diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c index 975eb321b1..06170ddfcb 100644 --- a/source/util/src/tcompression.c +++ b/source/util/src/tcompression.c @@ -2789,6 +2789,8 @@ int32_t tsCompressBool2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_ DEFINE_VAR(cmprAlg) if (l1 != L1_RLE) { SET_COMPRESS(L1_RLE, l2, lvl, tCmprAlg); + } else { + tCmprAlg = cmprAlg; } FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, tCmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_BOOL, 1); } @@ -2799,6 +2801,8 @@ int32_t tsDecompressBool2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int3 DEFINE_VAR(cmprAlg) if (l1 != L1_RLE) { SET_COMPRESS(L1_RLE, l2, lvl, tCmprAlg); + } else { + tCmprAlg = cmprAlg; } FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, tCmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_BOOL, 0); } @@ -2810,6 +2814,8 @@ int32_t tsCompressTinyint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int DEFINE_VAR(cmprAlg) if (l1 != L1_SIMPLE_8B) { SET_COMPRESS(L1_SIMPLE_8B, l2, lvl, tCmprAlg); + } else { + tCmprAlg = cmprAlg; } FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, tCmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_TINYINT, 1); } @@ -2820,6 +2826,8 @@ int32_t tsDecompressTinyint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, i DEFINE_VAR(cmprAlg) if (l1 != L1_SIMPLE_8B) { SET_COMPRESS(L1_SIMPLE_8B, l2, lvl, tCmprAlg); + } else { + tCmprAlg = cmprAlg; } FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, tCmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_TINYINT, 0); } @@ -2831,6 +2839,8 @@ int32_t tsCompressSmallint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, in DEFINE_VAR(cmprAlg) if (l1 != L1_SIMPLE_8B) { SET_COMPRESS(L1_SIMPLE_8B, l2, lvl, tCmprAlg); + } else { + tCmprAlg = cmprAlg; } FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, tCmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_SMALLINT, 1); } @@ -2841,6 +2851,8 @@ int32_t tsDecompressSmallint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, DEFINE_VAR(cmprAlg) if (l1 != L1_SIMPLE_8B) { SET_COMPRESS(L1_SIMPLE_8B, l2, lvl, tCmprAlg); + } else { + tCmprAlg = cmprAlg; } FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, tCmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_SMALLINT, 0); } @@ -2849,23 +2861,24 @@ int32_t tsDecompressSmallint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t tsCompressInt2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf, int32_t nBuf) { uint32_t tCmprAlg = 0; - { - DEFINE_VAR(cmprAlg) - if (l1 != L1_SIMPLE_8B) { - SET_COMPRESS(L1_SIMPLE_8B, l2, lvl, tCmprAlg); - } + DEFINE_VAR(cmprAlg) + if (l1 != L1_SIMPLE_8B) { + SET_COMPRESS(L1_SIMPLE_8B, l2, lvl, tCmprAlg); + } else { + tCmprAlg = cmprAlg; } + FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, tCmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_INT, 1); } int32_t tsDecompressInt2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf, int32_t nBuf) { uint32_t tCmprAlg = 0; - { - DEFINE_VAR(cmprAlg) - if (l1 != L1_SIMPLE_8B) { - SET_COMPRESS(L1_SIMPLE_8B, l2, lvl, tCmprAlg); - } + DEFINE_VAR(cmprAlg) + if (l1 != L1_SIMPLE_8B) { + SET_COMPRESS(L1_SIMPLE_8B, l2, lvl, tCmprAlg); + } else { + tCmprAlg = cmprAlg; } FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, tCmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_INT, 0); } diff --git a/tests/script/tsim/compress/compress_col.sim b/tests/script/tsim/compress/compress_col.sim new file mode 100644 index 0000000000..c55b74f246 --- /dev/null +++ b/tests/script/tsim/compress/compress_col.sim @@ -0,0 +1,113 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print ============================ dnode1 start +$i = 0 +$dbPrefix = db +$tbPrefix = tb +$db = $dbPrefix . $i +$tb = $tbPrefix . $i + +$N = 2000 + +print =============== step1 + +sql create database $db +sql use $db +sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bigint, str binary(256)) + +$count = 0 +while $count < $N + $ms = 1591200000000 + $count + sql insert into $tb values( $ms , 1, 0, $count , $count , $count ,'it is a string') + $count = $count + 1 +endw + +sql select * from $tb +if $rows != $N then + return -1 +endi + +print =============== step2 +$i = 1 +$db = $dbPrefix . $i +$tb = $tbPrefix . $i + +sql create database $db +sql use $db + +sql create table $tb (ts timestamp, f float, d double, str binary(256)) + +$count = 0 +while $count < $N + $ms = 1591286400000 + $count + sql insert into $tb values( $ms , $count , $count ,'it is a string') + $count = $count + 1 +endw + +sql select * from $tb +if $rows != $N then + return -1 +endi + +print =============== step3 +$i = 2 +$db = $dbPrefix . $i +$tb = $tbPrefix . $i + +sql create database $db +sql use $db + +sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bigint, f float, d double, str binary(256)) + +$count = 0 +while $count < $N + $ms = 1591372800000 + $count + sql insert into $tb values( $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') + $count = $count + 1 +endw + +sql select * from $tb +if $rows != $N then + return -1 +endi + +print =============== step4 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +print =============== step5 + +$i = 0 +$db = $dbPrefix . $i +$tb = $tbPrefix . $i +sql use $db +sql select * from $tb +print select * from $tb ==> $rows points +if $rows != $N then + return -1 +endi + +$i = 1 +$db = $dbPrefix . $i +$tb = $tbPrefix . $i +sql use $db +sql select * from $tb +print select * from $tb ==> $rows points +if $rows != $N then + return -1 +endi + +$i = 2 +$db = $dbPrefix . $i +$tb = $tbPrefix . $i +sql use $db +sql select * from $tb +print select * from $tb ==> $rows points +if $rows != $N then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT