From b9471b8115b61224d4f5c832a0216ac76cb84e25 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 28 Mar 2022 11:13:59 +0800 Subject: [PATCH 01/39] [TD-14222] add test for encode/decode ResultRow --- source/libs/executor/src/executorimpl.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 2417bd352a..b739ffb2b9 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -6363,6 +6363,16 @@ static int32_t doOpenAggregateOptr(SOperatorInfo *pOperator) { // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order); doAggregateImpl(pOperator, 0, pInfo->pCtx); + + char *result = NULL; + int32_t length = 0; + pOperator->encodeResultRow(pOperator, &result, &length); + SAggSupporter *pSup = &pAggInfo->aggSup; + taosHashClear(pSup->pResultRowHashTable); + pOperator->decodeResultRow(pOperator, result, length); + if(result){ + free(result); + } } finalizeQueryResult(pInfo->pCtx, pOperator->numOfOutput); @@ -6486,7 +6496,7 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char *result, int32_t l initResultRow(resultRow); - pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = (SResultRowPosition) {.pageId = resultRow->pageId, .offset = resultRow->offset}; + //pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = (SResultRowPosition) {.pageId = resultRow->pageId, .offset = resultRow->offset}; } if (offset != length){ From c941a2c7109ff651877f362b0ae833236565459f Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 29 Mar 2022 18:16:40 +0800 Subject: [PATCH 02/39] add test for encode/decode ResultRow in group by and interval --- include/libs/nodes/nodes.h | 3 +- source/libs/executor/src/executorimpl.c | 76 ++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 411d34063c..9698f0e13e 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -141,7 +141,8 @@ typedef enum ENodeType { QUERY_NODE_PHYSICAL_PLAN_DISPATCH, QUERY_NODE_PHYSICAL_PLAN_INSERT, QUERY_NODE_PHYSICAL_SUBPLAN, - QUERY_NODE_PHYSICAL_PLAN + QUERY_NODE_PHYSICAL_PLAN, + QUERY_NODE_PHYSICAL_PLAN_GROUPBY } ENodeType; /** diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 5d6495b52a..5ec5d8cd70 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -6346,7 +6346,7 @@ static int32_t doOpenAggregateOptr(SOperatorInfo *pOperator) { taosHashClear(pSup->pResultRowHashTable); pOperator->decodeResultRow(pOperator, result, length); if(result){ - free(result); + taosMemoryFree(result); } } @@ -6377,8 +6377,27 @@ static SSDataBlock* getAggregateResult(SOperatorInfo *pOperator, bool* newgroup) } static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t *length) { - SAggOperatorInfo *pAggInfo = pOperator->info; - SAggSupporter *pSup = &pAggInfo->aggSup; + SAggSupporter *pSup = NULL; + switch(pOperator->operatorType){ + case QUERY_NODE_PHYSICAL_PLAN_AGG:{ + SAggOperatorInfo *pAggInfo = pOperator->info; + pSup = &pAggInfo->aggSup; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_GROUPBY:{ + SGroupbyOperatorInfo *pAggInfo = pOperator->info; + pSup = &pAggInfo->aggSup; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{ + STableIntervalOperatorInfo *pAggInfo = pOperator->info; + pSup = &pAggInfo->aggSup; + break; + } + default:{ + qDebug("invalid operatorType: %d", pOperator->operatorType); + } + } int32_t size = taosHashGetSize(pSup->pResultRowHashTable); size_t keyLen = POINTER_BYTES; // estimate the key length @@ -6434,9 +6453,28 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char *result, int32_t l return false; } - SAggOperatorInfo *pAggInfo = pOperator->info; - SAggSupporter *pSup = &pAggInfo->aggSup; - SOptrBasicInfo *pInfo = &pAggInfo->binfo; + SAggSupporter *pSup = NULL; + switch(pOperator->operatorType){ + case QUERY_NODE_PHYSICAL_PLAN_AGG:{ + SAggOperatorInfo *pAggInfo = pOperator->info; + //SOptrBasicInfo *pInfo = &pAggInfo->binfo; + pSup = &pAggInfo->aggSup; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_GROUPBY:{ + SGroupbyOperatorInfo *pAggInfo = pOperator->info; + pSup = &pAggInfo->aggSup; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{ + STableIntervalOperatorInfo *pAggInfo = pOperator->info; + pSup = &pAggInfo->aggSup; + break; + } + default:{ + qDebug("invalid operatorType: %d", pOperator->operatorType); + } + } // int32_t size = taosHashGetSize(pSup->pResultRowHashTable); int32_t count = *(int32_t*)(result); @@ -6733,6 +6771,16 @@ static int32_t doOpenIntervalAgg(SOperatorInfo *pOperator) { // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0); + + char *result = NULL; + int32_t length = 0; + pOperator->encodeResultRow(pOperator, &result, &length); + SAggSupporter *pSup = &pInfo->aggSup; + taosHashClear(pSup->pResultRowHashTable); + pOperator->decodeResultRow(pOperator, result, length); + if(result){ + taosMemoryFree(result); + } } closeAllResultRows(&pInfo->binfo.resultRowInfo); @@ -7149,6 +7197,16 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo *pOperator, bool* newgrou setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); // setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput); doHashGroupbyAgg(pOperator, pBlock); + + char *result = NULL; + int32_t length = 0; + pOperator->encodeResultRow(pOperator, &result, &length); + SAggSupporter *pSup = &pInfo->aggSup; + taosHashClear(pSup->pResultRowHashTable); + pOperator->decodeResultRow(pOperator, result, length); + if(result){ + taosMemoryFree(result); + } } pOperator->status = OP_RES_TO_RETURN; @@ -7693,6 +7751,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pOperator->_openFn = doOpenIntervalAgg; pOperator->getNextFn = doBuildIntervalResult; pOperator->closeFn = destroyIntervalOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -7903,13 +7963,15 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pOperator->name = "GroupbyAggOperator"; pOperator->blockingOptr = true; pOperator->status = OP_NOT_OPENED; -// pOperator->operatorType = OP_Groupby; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_GROUPBY; pOperator->pExpr = pExprInfo; pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; pOperator->_openFn = operatorDummyOpenFn; pOperator->getNextFn = hashGroupbyAggregate; pOperator->closeFn = destroyGroupbyOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; code = appendDownstream(pOperator, &downstream, 1); return pOperator; From bceb557809114fd62a896fa7f318a50739b03745 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 30 Mar 2022 10:05:20 +0800 Subject: [PATCH 03/39] rm useless code --- source/libs/executor/src/dataDispatcher.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 34894c235b..e527e3a315 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -125,7 +125,6 @@ static void toDataCacheEntry(const SDataDispatchHandle* pHandle, const SInputDat pBuf->useSize = sizeof(SRetrieveTableRsp); copyData(pInput, pHandle->pSchema, pEntry->data, pEntry->compressed, &pEntry->dataLen); - pEntry->dataLen = pEntry->dataLen; pBuf->useSize += pEntry->dataLen; } From 70980e84b51f09ee8564956df05c5f5ba829d397 Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 7 Apr 2022 10:48:20 +0800 Subject: [PATCH 04/39] add complex sim case --- tests/script/tsim/query/complex_select.sim | 426 +++++++++++++++++++++ 1 file changed, 426 insertions(+) create mode 100644 tests/script/tsim/query/complex_select.sim diff --git a/tests/script/tsim/query/complex_select.sim b/tests/script/tsim/query/complex_select.sim new file mode 100644 index 0000000000..1cb58237c4 --- /dev/null +++ b/tests/script/tsim/query/complex_select.sim @@ -0,0 +1,426 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +sql select * from ct1 limit 2 offset 1 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +print ================ query 2 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 4 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql_error select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +## TODO : group by +print ================ query 3 group by filter + + + +## TODO : complex +print ================ query 4 scalar function + where + group by + limit/offset + + + + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 30def824b64e961cc08858e3ed65f3f0ebabc5a7 Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 7 Apr 2022 16:09:38 +0800 Subject: [PATCH 05/39] add group by --- tests/script/tsim/query/complex_select.sim | 123 ++++++++++++++++----- 1 file changed, 94 insertions(+), 29 deletions(-) diff --git a/tests/script/tsim/query/complex_select.sim b/tests/script/tsim/query/complex_select.sim index 1cb58237c4..4a710c4b58 100644 --- a/tests/script/tsim/query/complex_select.sim +++ b/tests/script/tsim/query/complex_select.sim @@ -50,42 +50,42 @@ if $rows != 4 then endi print =============== insert data into child table ct1 (s) -sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) -sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) -sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) -sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) -sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) -sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) -sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now ) -sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now ) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) print =============== insert data into child table ct2 (d) -sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) -sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) -sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) -sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) -sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) -sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now ) -sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now ) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) print =============== insert data into child table ct3 (n) sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) -sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) -sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) -sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) -sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) -sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) -sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) print =============== insert data into child table ct4 (y) -sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) -sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) -sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) -sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) -sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) -sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) @@ -372,12 +372,77 @@ if $rows != 32 then endi -## TODO : group by print ================ query 3 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi -## TODO : complex print ================ query 4 scalar function + where + group by + limit/offset From c7dd60ff85b566437ccc6fccd218d1543ce657b7 Mon Sep 17 00:00:00 2001 From: cpwu Date: Sat, 9 Apr 2022 14:07:27 +0800 Subject: [PATCH 06/39] fix the case --- tests/script/tsim/query/complex_select.sim | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/script/tsim/query/complex_select.sim b/tests/script/tsim/query/complex_select.sim index 4a710c4b58..1696d22da7 100644 --- a/tests/script/tsim/query/complex_select.sim +++ b/tests/script/tsim/query/complex_select.sim @@ -444,9 +444,103 @@ if $rows != 8 then endi print ================ query 4 scalar function + where + group by + limit/offset +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi print =================== count all rows sql select count(c1) from stb1 From c33f31b6d5e9c7ba0cc123e65fa106c82d67eb7f Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Sat, 9 Apr 2022 18:12:15 +0800 Subject: [PATCH 07/39] feature/qnode --- source/libs/command/src/explain.c | 14 ++++++-------- source/libs/qworker/inc/qworkerInt.h | 1 + source/libs/qworker/src/qworker.c | 10 +++++++--- source/libs/qworker/src/qworkerMsg.c | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 605d8f41da..155da8de49 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -52,16 +52,14 @@ void qExplainFreeCtx(SExplainCtx *pCtx) { void *pIter = taosHashIterate(pCtx->groupHash, NULL); while (pIter) { SExplainGroup *group = (SExplainGroup *)pIter; - if (NULL == group->nodeExecInfo) { - continue; + if (group->nodeExecInfo) { + int32_t num = taosArrayGetSize(group->nodeExecInfo); + for (int32_t i = 0; i < num; ++i) { + SExplainRsp *rsp = taosArrayGet(group->nodeExecInfo, i); + taosMemoryFreeClear(rsp->subplanInfo); + } } - int32_t num = taosArrayGetSize(group->nodeExecInfo); - for (int32_t i = 0; i < num; ++i) { - SExplainRsp *rsp = taosArrayGet(group->nodeExecInfo, i); - taosMemoryFreeClear(rsp->subplanInfo); - } - pIter = taosHashIterate(pCtx->groupHash, pIter); } } diff --git a/source/libs/qworker/inc/qworkerInt.h b/source/libs/qworker/inc/qworkerInt.h index cfd4a3ec7b..d62f9f04b8 100644 --- a/source/libs/qworker/inc/qworkerInt.h +++ b/source/libs/qworker/inc/qworkerInt.h @@ -79,6 +79,7 @@ typedef struct SQWConnInfo { typedef struct SQWMsg { void *node; + int32_t code; char *msg; int32_t msgLen; SQWConnInfo connInfo; diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index f0f04a8a9b..67871dfe62 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -536,6 +536,8 @@ int32_t qwDropTask(QW_FPARAMS_DEF) { QW_ERR_RET(qwDropTaskStatus(QW_FPARAMS())); QW_ERR_RET(qwDropTaskCtx(QW_FPARAMS())); + QW_TASK_DLOG_E("task is dropped"); + return TSDB_CODE_SUCCESS; } @@ -1239,8 +1241,10 @@ int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) { QW_ERR_JRET(qwKillTaskHandle(QW_FPARAMS(), ctx)); qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_DROPPING); } else if (ctx->phase > 0) { - qwBuildAndSendDropRsp(&qwMsg->connInfo, code); - QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); + if (0 == qwMsg->code) { + qwBuildAndSendDropRsp(&qwMsg->connInfo, code); + QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); + } QW_ERR_JRET(qwDropTask(QW_FPARAMS())); rsped = true; @@ -1273,7 +1277,7 @@ _return: qwReleaseTaskCtx(mgmt, ctx); } - if (TSDB_CODE_SUCCESS != code) { + if ((TSDB_CODE_SUCCESS != code) && (0 == qwMsg->code)) { qwBuildAndSendDropRsp(&qwMsg->connInfo, code); QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); } diff --git a/source/libs/qworker/src/qworkerMsg.c b/source/libs/qworker/src/qworkerMsg.c index bf8f97aa4c..15a42d3a31 100644 --- a/source/libs/qworker/src/qworkerMsg.c +++ b/source/libs/qworker/src/qworkerMsg.c @@ -549,7 +549,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { uint64_t tId = msg->taskId; int64_t rId = msg->refId; - SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0}; + SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .code = pMsg->code}; qwMsg.connInfo.handle = pMsg->handle; qwMsg.connInfo.ahandle = pMsg->ahandle; From f052e64103d49cf9c3344ddaa2e157ceaeda91c2 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Sat, 9 Apr 2022 18:12:53 +0800 Subject: [PATCH 08/39] feature/qnode --- tests/script/general/explain/explain.sim | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/script/general/explain/explain.sim diff --git a/tests/script/general/explain/explain.sim b/tests/script/general/explain/explain.sim new file mode 100644 index 0000000000..666e4040b7 --- /dev/null +++ b/tests/script/general/explain/explain.sim @@ -0,0 +1,102 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c wallevel -v 2 +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 + +print ========= start dnode1 as master +system sh/exec.sh -n dnode1 -s start +sleep 2000 +sql connect + +print ======== step1 +sql create database db1 vgroups 3; +sql use db1; +sql show databases; +sql create stable st1 (ts timestamp, f1 int, f2 binary(200)) tags(t1 int); +sql create stable st2 (ts timestamp, f1 int, f2 binary(200)) tags(t1 int); +sql create table tb1 using st1 tags(1); +sql insert into tb1 values (now, 1, "Hash Join (cost=230.47..713.98 rows=101 width=488) (actual time=0.711..7.427 rows=100 loops=1)"); + +sql create table tb2 using st1 tags(2); +sql insert into tb2 values (now, 2, "Seq Scan on tenk2 t2 (cost=0.00..445.00 rows=10000 width=244) (actual time=0.007..2.583 rows=10000 loops=1)"); +sql create table tb3 using st1 tags(3); +sql insert into tb3 values (now, 3, "Hash (cost=229.20..229.20 rows=101 width=244) (actual time=0.659..0.659 rows=100 loops=1)"); +sql create table tb4 using st1 tags(4); +sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..229.20 rows=101 width=244) (actual time=0.080..0.526 rows=100 loops=1)"); + +sql create table tb1 using st2 tags(1); +sql insert into tb1 values (now, 1, "Hash Join (cost=230.47..713.98 rows=101 width=488) (actual time=0.711..7.427 rows=100 loops=1)"); + +sql create table tb2 using st2 tags(2); +sql insert into tb2 values (now, 2, "Seq Scan on tenk2 t2 (cost=0.00..445.00 rows=10000 width=244) (actual time=0.007..2.583 rows=10000 loops=1)"); +sql create table tb3 using st2 tags(3); +sql insert into tb3 values (now, 3, "Hash (cost=229.20..229.20 rows=101 width=244) (actual time=0.659..0.659 rows=100 loops=1)"); +sql create table tb4 using st2 tags(4); +sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..229.20 rows=101 width=244) (actual time=0.080..0.526 rows=100 loops=1)"); + + +print ======== step2 +sql explain select * from st1 where -2; +sql explain select ts from tb1; +sql explain select * from st1; +sql explain select * from st1 order by ts; +sql explain select * from information_schema.user_stables; +sql explain select count(*),sum(f1) from tb1; +sql explain select count(*),sum(f1) from st1; +sql explain select count(*),sum(f1) from st1 group by f1; +sql explain select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain select min(f1) from st1 interval(1m, 2a) sliding(3n); + +print ======== step3 +sql explain verbose true select * from st1 where -2; +sql explain verbose true select ts from tb1 where f1 > 0; +sql explain verbose true select * from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; +sql explain verbose true select * from information_schema.user_stables where db_name='db2'; +sql explain verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; + +print ======== step4 +sql explain analyze select ts from st1 where -2; +sql explain analyze select ts from tb1; +sql explain analyze select ts from st1; +sql explain analyze select ts from st1; +sql explain analyze select ts from st1 order by ts; +sql explain analyze select * from information_schema.user_stables; +sql explain analyze select count(*),sum(f1) from tb1; +sql explain analyze select count(*),sum(f1) from st1; +sql explain analyze select count(*),sum(f1) from st1 group by f1; +sql explain analyze select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain analyze select min(f1) from st1 interval(3n, 2a) sliding(1n); + +print ======== step5 +sql explain analyze verbose true select ts from st1 where -2; +sql explain analyze verbose true select ts from tb1; +sql explain analyze verbose true select ts from st1; +sql explain analyze verbose true select ts from st1; +sql explain analyze verbose true select ts from st1 order by ts; +sql explain analyze verbose true select * from information_schema.user_stables; +sql explain analyze verbose true select count(*),sum(f1) from tb1; +sql explain analyze verbose true select count(*),sum(f1) from st1; +sql explain analyze verbose true select count(*),sum(f1) from st1 group by f1; +sql explain analyze verbose true select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain analyze verbose true select ts from tb1 where f1 > 0; +sql explain analyze verbose true select f1 from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; +sql explain analyze verbose true select * from information_schema.user_stables where db_name='db2'; +sql explain analyze verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; +sql explain analyze verbose true select min(f1) from st1 interval(3n, 2a) sliding(1n); +sql explain analyze verbose true select * from (select min(f1),count(*) a from st1 where f1 > 0) where a < 0; + +#not pass case +#sql explain verbose true select count(*),sum(f1) as aa from tb1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by aa; +#sql explain verbose true select * from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by ts; +#sql explain verbose true select count(*),sum(f1) from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by ts; +#sql explain verbose true select count(f1) from tb1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' interval(1s, 2d) sliding(3s) order by ts; +#sql explain verbose true select min(f1) from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' interval(1m, 2a) sliding(3n) fill(linear) order by ts; +#sql explain select max(f1) from tb1 SESSION(ts, 1s); +#sql explain select max(f1) from st1 SESSION(ts, 1s); +#sql explain select * from tb1, tb2 where tb1.ts=tb2.ts; +#sql explain select * from st1, st2 where tb1.ts=tb2.ts; +#sql explain analyze verbose true select sum(a+b) from (select _rowts, min(f1) b,count(*) a from st1 where f1 > 0 interval(1a)) where a < 0 interval(1s); + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 1df069814a28903da29596789f7363dd25f46b49 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 10 Apr 2022 15:35:09 +0800 Subject: [PATCH 09/39] feat[query]:add time slice operator. --- source/client/test/clientTests.cpp | 5 +- source/libs/executor/inc/executorimpl.h | 10 +++- source/libs/executor/src/executorimpl.c | 70 ++++++++++++------------- 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 772f9049e5..fd2abbb559 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -400,7 +400,7 @@ TEST(testCase, show_vgroup_Test) { taos_free_result(pRes); taos_close(pConn); } -#endif + TEST(testCase, create_multiple_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -653,6 +653,7 @@ TEST(testCase, projection_query_stables) { taos_free_result(pRes); taos_close(pConn); } +#endif TEST(testCase, agg_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -661,7 +662,7 @@ TEST(testCase, agg_query_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "select count(*) from tu"); + pRes = taos_query(pConn, "select length('abc') from tu"); if (taos_errno(pRes) != 0) { printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 32a5140da2..b1f15482a9 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -609,6 +609,12 @@ typedef struct SSessionAggOperatorInfo { SColumnInfoData timeWindowData; // query time window info for scalar function execution. } SSessionAggOperatorInfo; +typedef struct STimeSliceOperatorInfo { + SOptrBasicInfo binfo; + SInterval interval; + SGroupResInfo groupResInfo; // multiple results build supporter +} STimeSliceOperatorInfo; + typedef struct SStateWindowOperatorInfo { SOptrBasicInfo binfo; SAggSupporter aggSup; @@ -707,6 +713,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); +SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo); + #if 0 SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, @@ -716,7 +724,7 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); -SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput); +SOperatorInfo* createTagScanOperatorInfo(SReaderHandle* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema, int32_t numOfOutput); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index ee5c675989..1bc84f85d7 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -5429,58 +5429,48 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { return NULL; } - STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; - - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + STimeSliceOperatorInfo* pSliceInfo = pOperator->info; if (pOperator->status == OP_RES_TO_RETURN) { // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); - - if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + if (pSliceInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pSliceInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } - return pIntervalInfo->binfo.pRes; + return pSliceInfo->binfo.pRes; } - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; - STimeWindow win = pQueryAttr->window; - + int32_t order = TSDB_ORDER_ASC; +// STimeWindow win = pQueryAttr->window; SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); - if (pBlock == NULL) { break; } // setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); - // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); - hashAllIntervalAgg(pOperator, &pIntervalInfo->binfo.resultRowInfo, pBlock, 0); + setInputDataBlock(pOperator, pSliceInfo->binfo.pCtx, pBlock, order); + hashAllIntervalAgg(pOperator, &pSliceInfo->binfo.resultRowInfo, pBlock, 0); } // restore the value - pQueryAttr->order.order = order; - pQueryAttr->window = win; - pOperator->status = OP_RES_TO_RETURN; - closeAllResultRows(&pIntervalInfo->binfo.resultRowInfo); + closeAllResultRows(&pSliceInfo->binfo.resultRowInfo); setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); - finalizeQueryResult(pIntervalInfo->binfo.pCtx, pOperator->numOfOutput); + finalizeQueryResult(pSliceInfo->binfo.pCtx, pOperator->numOfOutput); - initGroupResInfo(&pRuntimeEnv->groupResInfo, &pIntervalInfo->binfo.resultRowInfo); - // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + initGroupResInfo(&pSliceInfo->groupResInfo, &pSliceInfo->binfo.resultRowInfo); + // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pSliceInfo->pRes); - if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + if (pSliceInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pSliceInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } - return pIntervalInfo->binfo.pRes->info.rows == 0 ? NULL : pIntervalInfo->binfo.pRes; + return pSliceInfo->binfo.pRes->info.rows == 0 ? NULL : pSliceInfo->binfo.pRes; } static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup) { @@ -6238,28 +6228,34 @@ _error: return NULL; } -SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, - SExprInfo* pExpr, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); +SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo) { + STimeSliceOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STimeSliceOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pOperator == NULL || pInfo == NULL) { + goto _error; + } - // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - - pOperator->name = "AllTimeIntervalAggOperator"; + pOperator->name = "TimeSliceOperator"; // pOperator->operatorType = OP_AllTimeWindow; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->getNextFn = doAllIntervalAgg; - pOperator->closeFn = destroyBasicOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->getNextFn = doAllIntervalAgg; + pOperator->closeFn = destroyBasicOperatorInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; + + _error: + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + return NULL; } SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { From 14ec5b672a2cd70264c42a4f8cec5511ca7ea76d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 10 Apr 2022 18:24:16 +0800 Subject: [PATCH 10/39] fix[cluster]: redirect msg when mnode not deployed --- source/dnode/mgmt/main/dndInt.c | 4 ++-- source/dnode/mgmt/main/dndTransport.c | 16 +++++++++++----- tests/script/tsim/mnode/basic1.sim | 1 - 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/dnode/mgmt/main/dndInt.c b/source/dnode/mgmt/main/dndInt.c index 7b207fd496..d406b0c02e 100644 --- a/source/dnode/mgmt/main/dndInt.c +++ b/source/dnode/mgmt/main/dndInt.c @@ -158,7 +158,7 @@ SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount); } else { - terrno = TSDB_CODE_NODE_REDIRECT; + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; pRetWrapper = NULL; } taosRUnLockLatch(&pWrapper->latch); @@ -174,7 +174,7 @@ int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); } else { - terrno = TSDB_CODE_NODE_REDIRECT; + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; code = -1; } taosRUnLockLatch(&pWrapper->latch); diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/main/dndTransport.c index 75722c8f9c..b639b79935 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/main/dndTransport.c @@ -53,8 +53,9 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS int32_t code = -1; SNodeMsg *pMsg = NULL; NodeMsgFp msgFp = NULL; + uint16_t msgType = pRpc->msgType; - if (pEpSet && pEpSet->numOfEps > 0 && pRpc->msgType == TDMT_MND_STATUS_RSP) { + if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) { dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet); } @@ -84,9 +85,15 @@ _OVER: } } else { dError("msg:%p, failed to process since 0x%04x:%s", pMsg, code & 0XFFFF, terrstr()); - if (pRpc->msgType & 1U) { + if (msgType & 1U) { if (terrno != 0) code = terrno; - SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; + if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) { + if (msgType > TDMT_MND_MSG && msgType < TDMT_VND_MSG) { + code = TSDB_CODE_NODE_REDIRECT; + } + } + + SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code}; tmsgSendRsp(&rsp); } dTrace("msg:%p, is freed", pMsg); @@ -348,8 +355,7 @@ static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *p } static void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { - if (pRsp->code == TSDB_CODE_APP_NOT_READY || pRsp->code == TSDB_CODE_NODE_REDIRECT || - pRsp->code == TSDB_CODE_NODE_OFFLINE) { + if (pRsp->code == TSDB_CODE_NODE_REDIRECT) { dmSendRedirectRsp(pWrapper->pMgmt, pRsp); } else { rpcSendResponse(pRsp); diff --git a/tests/script/tsim/mnode/basic1.sim b/tests/script/tsim/mnode/basic1.sim index 74ec44328d..e3d27d0c13 100644 --- a/tests/script/tsim/mnode/basic1.sim +++ b/tests/script/tsim/mnode/basic1.sim @@ -75,7 +75,6 @@ if $data02 != master then return -1 endi -return print =============== create drop mnode 1 sql_error create mnode on dnode 1 sql_error drop mnode on dnode 1 From c4ee7142b9dd9cdc8518e65f9a12a52311d172af Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 10 Apr 2022 22:34:18 +0800 Subject: [PATCH 11/39] fix[cluster]: manage mnode in multi-process mode --- source/dnode/mgmt/main/dndTransport.c | 3 ++- source/dnode/mgmt/mm/mmHandle.c | 2 +- source/dnode/mgmt/mm/mmInt.c | 3 +++ source/dnode/mgmt/test/mnode/dmnode.cpp | 2 +- tests/script/jenkins/basic.txt | 10 ++++++++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/main/dndTransport.c index b639b79935..bcebd521b6 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/main/dndTransport.c @@ -448,7 +448,8 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, ProcFuncType ftype) { pMsg->pCont = pCont; - dTrace("msg:%p, get from parent queue, ftype:%d handle:%p, app:%p", pMsg, ftype, pMsg->handle, pMsg->ahandle); + dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle, + pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle); switch (ftype) { case PROC_REGIST: diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c index eeae9da8b7..6ad0b8c0ed 100644 --- a/source/dnode/mgmt/mm/mmHandle.c +++ b/source/dnode/mgmt/mm/mmHandle.c @@ -96,7 +96,7 @@ int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { if (alterReq.dnodeId != pDnode->dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to alter mnode since %s", terrstr()); + dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->dnodeId, alterReq.dnodeId); return -1; } else { return mmAlter(pMgmt, &alterReq); diff --git a/source/dnode/mgmt/mm/mmInt.c b/source/dnode/mgmt/mm/mmInt.c index 64daf09bf9..49886621ec 100644 --- a/source/dnode/mgmt/mm/mmInt.c +++ b/source/dnode/mgmt/mm/mmInt.c @@ -112,6 +112,9 @@ static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) { if (!deployed) { dInfo("mnode start to deploy"); + if (pMgmt->pWrapper->procType == PROC_CHILD) { + pMgmt->pDnode->dnodeId = 1; + } mmBuildOptionForDeploy(pMgmt, &option); } else { dInfo("mnode start to open"); diff --git a/source/dnode/mgmt/test/mnode/dmnode.cpp b/source/dnode/mgmt/test/mnode/dmnode.cpp index 348eb50c8f..e92e51fa39 100644 --- a/source/dnode/mgmt/test/mnode/dmnode.cpp +++ b/source/dnode/mgmt/test/mnode/dmnode.cpp @@ -188,7 +188,7 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) { SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen); ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_REDIRECT); + ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED); } { diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2d18167337..761a8921d5 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -43,7 +43,7 @@ ./test.sh -f tsim/bnode/basic1.sim # ---- mnode -./test.sh -f tsim/bnode/basic1.sim +./test.sh -f tsim/mnode/basic1.sim # ---- show ./test.sh -f tsim/show/basic.sim @@ -69,7 +69,13 @@ # --- for multi process mode ./test.sh -f tsim/user/basic1.sim -m -./test.sh -f tsim/stable/vnode3.sim -m +./test.sh -f tsim/db/basic3.sim -m +./test.sh -f tsim/insert/backquote.sim +./test.sh -f tsim/parser/fourArithmetic-basic.sim -m +./test.sh -f tsim/query/interval-offset.sim -m ./test.sh -f tsim/tmq/basic.sim -m +./test.sh -f tsim/stable/vnode3.sim -m +./test.sh -f tsim/qnode/basic1.sim -m +./test.sh -f tsim/mnode/basic1.sim -m #======================b1-end=============== From ca5d5ca7bb6f4ee3ebce6d67beab74dfc81e9d0a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 10:44:37 +0800 Subject: [PATCH 12/39] test[query]:update the script. --- source/libs/executor/inc/executorimpl.h | 3 - tests/script/tsim/query/session.sim | 114 ++++++++++++------------ 2 files changed, 57 insertions(+), 60 deletions(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index b1f15482a9..9a75830ec4 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -717,9 +717,6 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* #if 0 SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); -SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, - SExprInfo* pExpr, int32_t numOfOutput); - SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim index c1d3437e4a..3a57581668 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -98,15 +98,15 @@ if $data01 != 2 then return -1 endi - -print ====> select count(*) from (select * from dev_001) session(ts,5a) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,5a) -if $rows != 15 then - return -1 -endi -if $data01 != 2 then - return -1 -endi +# +#print ====> select count(*) from (select * from dev_001) session(ts,5a) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,5a) +#if $rows != 15 then +# return -1 +#endi +#if $data01 != 2 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1s) sql select _wstartts, count(*) from dev_001 session(ts,1s) @@ -117,14 +117,14 @@ if $data01 != 5 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1s) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1s) -if $rows != 12 then - return -1 -endi -if $data01 != 5 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1s) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1s) +#if $rows != 12 then +# return -1 +#endi +#if $data01 != 5 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1000a) sql select _wstartts, count(*) from dev_001 session(ts,1000a) @@ -135,14 +135,14 @@ if $data01 != 5 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1000a) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1000a) -if $rows != 12 then - return -1 -endi -if $data01 != 5 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1000a) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1000a) +#if $rows != 12 then +# return -1 +#endi +#if $data01 != 5 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1m) sql select _wstartts, count(*) from dev_001 session(ts,1m) @@ -153,14 +153,14 @@ if $data01 != 8 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1m) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1m) -if $rows != 9 then - return -1 -endi -if $data01 != 8 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1m) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1m) +#if $rows != 9 then +# return -1 +#endi +#if $data01 != 8 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1h) sql select _wstartts, count(*) from dev_001 session(ts,1h) @@ -171,14 +171,14 @@ if $data01 != 11 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1h) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1h) -if $rows != 6 then - return -1 -endi -if $data01 != 11 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1h) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1h) +#if $rows != 6 then +# return -1 +#endi +#if $data01 != 11 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1d) sql select _wstartts, count(*) from dev_001 session(ts,1d) @@ -189,14 +189,14 @@ if $data01 != 13 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1d) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1d) -if $rows != 4 then - return -1 -endi -if $data01 != 13 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1d) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1d) +#if $rows != 4 then +# return -1 +#endi +#if $data01 != 13 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1w) sql select _wstartts, count(*) from dev_001 session(ts,1w) @@ -207,14 +207,14 @@ if $data01 != 15 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1w) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1w) -if $rows != 2 then - return -1 -endi -if $data01 != 15 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1w) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1w) +#if $rows != 2 then +# return -1 +#endi +#if $data01 != 15 then +# return -1 +#endi print ====> leastsquares not supported yet. From 984a508774a155dbfbdfe7703dbd03de34abf280 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 11 Apr 2022 11:51:03 +0800 Subject: [PATCH 13/39] add group by case --- tests/script/tsim/query/complex_group.sim | 278 ++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 tests/script/tsim/query/complex_group.sim diff --git a/tests/script/tsim/query/complex_group.sim b/tests/script/tsim/query/complex_group.sim new file mode 100644 index 0000000000..5372f9bd9b --- /dev/null +++ b/tests/script/tsim/query/complex_group.sim @@ -0,0 +1,278 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== + + +print ================ query 1 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From f17bead78e1e83624a22ab9e73f81ff153573f1a Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 11 Apr 2022 12:48:09 +0800 Subject: [PATCH 14/39] add complex case --- tests/script/tsim/query/complex_group.sim | 198 +++++++ tests/script/tsim/query/complex_limit.sim | 535 +++++++++++++++++ tests/script/tsim/query/complex_where.sim | 691 ++++++++++++++++++++++ 3 files changed, 1424 insertions(+) create mode 100644 tests/script/tsim/query/complex_limit.sim create mode 100644 tests/script/tsim/query/complex_where.sim diff --git a/tests/script/tsim/query/complex_group.sim b/tests/script/tsim/query/complex_group.sim index 5372f9bd9b..3a1ec523fe 100644 --- a/tests/script/tsim/query/complex_group.sim +++ b/tests/script/tsim/query/complex_group.sim @@ -164,6 +164,105 @@ if $rows != 8 then return -1 endi +print ================ query 2 complex with group by +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + print =================== count all rows sql select count(c1) from stb1 @@ -275,4 +374,103 @@ if $rows != 8 then return -1 endi +print ================ query 2 complex with group by +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + #system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_limit.sim b/tests/script/tsim/query/complex_limit.sim new file mode 100644 index 0000000000..ac25135685 --- /dev/null +++ b/tests/script/tsim/query/complex_limit.sim @@ -0,0 +1,535 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +sql select * from ct1 limit 2 offset 1 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + + +print ================ query 2 complex with limit +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +sql select * from ct1 limit 2 offset 1 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + + +print ================ query 2 complex with limit +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_where.sim b/tests/script/tsim/query/complex_where.sim new file mode 100644 index 0000000000..7a5de85a3c --- /dev/null +++ b/tests/script/tsim/query/complex_where.sim @@ -0,0 +1,691 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 4 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql_error select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +print ================ query 2 complex with where +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 4 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql_error select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +print ================ query 2 complex with where +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 9a543fb331eb5babe931c458ca2ef45fe7f47c1b Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 11 Apr 2022 14:09:47 +0800 Subject: [PATCH 15/39] feat:fix error in result row --- source/libs/executor/src/executorimpl.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index c57079cf4b..947e705c39 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -302,10 +302,6 @@ SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { } taosArrayPush(pBlock->pDataBlock, &idata); - - if (IS_VAR_DATA_TYPE(idata.info.type)) { - pBlock->info.hasVarCol = true; - } } return pBlock; @@ -365,7 +361,7 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env) pResultRowInfo->pPosition = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition)); int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity; - memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition)); + memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition) * inc); pResultRowInfo->capacity = (int32_t)newCapacity; } @@ -500,7 +496,7 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, pData = getBufPage(pResultBuf, getPageId(pi)); pageId = getPageId(pi); - if (pData->num + interBufSize + sizeof(SResultRow) > getBufPageSize(pResultBuf)) { + if (pData->num + interBufSize > getBufPageSize(pResultBuf)) { // release current page first, and prepare the next one releaseBufPageInfo(pResultBuf, pi); @@ -520,7 +516,7 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, pResultRow->pageId = pageId; pResultRow->offset = (int32_t)pData->num; - pData->num += interBufSize + sizeof(SResultRow); + pData->num += interBufSize; return pResultRow; } @@ -588,7 +584,7 @@ static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultR // add a new result set for a new group SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset}; - taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, POINTER_BYTES); + taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, sizeof(SResultRowPosition)); SResultRowCell cell = {.groupId = tableGroupId, .pos = pos}; taosArrayPush(pSup->pResultRowArrayList, &cell); } else { From 6f12bc1093f24e49ca0662451845c23fc81fab1f Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 14:15:09 +0800 Subject: [PATCH 16/39] feature/qnode --- include/libs/command/command.h | 2 +- source/client/inc/clientInt.h | 8 +++---- source/client/src/clientEnv.c | 6 ++--- source/client/src/clientHb.c | 16 ++++--------- source/client/src/clientImpl.c | 6 ++--- source/libs/command/inc/commandInt.h | 14 +++++++---- source/libs/command/src/explain.c | 30 +++++++++++++++++++++--- source/libs/parser/src/parAstCreater.c | 9 ++++--- tests/script/general/explain/explain.sim | 2 +- 9 files changed, 60 insertions(+), 33 deletions(-) diff --git a/include/libs/command/command.h b/include/libs/command/command.h index fa229d7265..0cd566ee46 100644 --- a/include/libs/command/command.h +++ b/include/libs/command/command.h @@ -22,7 +22,7 @@ typedef struct SExplainCtx SExplainCtx; int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp); int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp); -int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int32_t startTs); +int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs); int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp); int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp); void qExplainFreeCtx(SExplainCtx *pCtx); diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index ae1b34a3bd..96d7cead68 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -84,10 +84,10 @@ typedef struct { } SClientHbMgr; typedef struct SQueryExecMetric { - int64_t start; // start timestamp - int64_t parsed; // start to parse - int64_t send; // start to send to server - int64_t rsp; // receive response from server + int64_t start; // start timestamp, us + int64_t parsed; // start to parse, us + int64_t send; // start to send to server, us + int64_t rsp; // receive response from server, us } SQueryExecMetric; typedef struct SInstanceSummary { diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 769870ada8..359649884f 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -65,10 +65,10 @@ static void deregisterRequest(SRequestObj *pRequest) { int32_t currentInst = atomic_sub_fetch_64(&pActivity->currentRequests, 1); int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1); - int64_t duration = taosGetTimestampMs() - pRequest->metric.start; + int64_t duration = taosGetTimestampUs() - pRequest->metric.start; tscDebug("0x%" PRIx64 " free Request from connObj: 0x%" PRIx64 ", reqId:0x%" PRIx64 " elapsed:%" PRIu64 " ms, current:%d, app current:%d", - pRequest->self, pTscObj->id, pRequest->requestId, duration, num, currentInst); + pRequest->self, pTscObj->id, pRequest->requestId, duration/1000, num, currentInst); taosReleaseRef(clientConnRefPool, pTscObj->id); } @@ -151,7 +151,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty pRequest->pDb = getDbOfConnection(pObj); pRequest->requestId = generateRequestId(); - pRequest->metric.start = taosGetTimestampMs(); + pRequest->metric.start = taosGetTimestampUs(); pRequest->type = type; pRequest->pTscObj = pObj; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index abb6e7fbd1..d389fc34c6 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -435,11 +435,11 @@ static int32_t hbCreateThread() { taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); -// if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) { -// terrno = TAOS_SYSTEM_ERROR(errno); -// return -1; -// } -// taosThreadAttrDestroy(&thAttr); + if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + taosThreadAttrDestroy(&thAttr); return 0; } @@ -500,8 +500,6 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) { } void appHbMgrCleanup(void) { - taosThreadMutexLock(&clientHbMgr.lock); - int sz = taosArrayGetSize(clientHbMgr.appHbMgrs); for (int i = 0; i < sz; i++) { SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i); @@ -510,8 +508,6 @@ void appHbMgrCleanup(void) { taosHashCleanup(pTarget->connInfo); pTarget->connInfo = NULL; } - - taosThreadMutexUnlock(&clientHbMgr.lock); } int hbMgrInit() { @@ -532,7 +528,6 @@ int hbMgrInit() { } void hbMgrCleanUp() { -#if 0 hbStopThread(); // destroy all appHbMgr @@ -545,7 +540,6 @@ void hbMgrCleanUp() { taosThreadMutexUnlock(&clientHbMgr.lock); clientHbMgr.appHbMgrs = NULL; -#endif } int hbRegisterConnImpl(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, SHbConnInfo *info) { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 9938a2e1b9..b311060ea9 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -520,7 +520,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { SRequestObj* pRequest = (SRequestObj*)taosAcquireRef(clientReqRefPool, pSendInfo->requestObjRefId); assert(pRequest->self == pSendInfo->requestObjRefId); - pRequest->metric.rsp = taosGetTimestampMs(); + pRequest->metric.rsp = taosGetTimestampUs(); STscObj* pTscObj = pRequest->pTscObj; if (pEpSet) { @@ -536,10 +536,10 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start; if (pMsg->code == TSDB_CODE_SUCCESS) { tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%" PRIx64, pRequest->self, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed/1000, pRequest->requestId); } else { tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%" PRIx64, pRequest->self, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed/1000, pRequest->requestId); } taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index 23e4f2b24f..452804ac91 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -44,6 +44,9 @@ extern "C" { #define EXPLAIN_OUTPUT_FORMAT "Output: " #define EXPLAIN_TIME_WINDOWS_FORMAT "Time Window: interval=%" PRId64 "%c offset=%" PRId64 "%c sliding=%" PRId64 "%c" #define EXPLAIN_WINDOW_FORMAT "Window: gap=%" PRId64 +#define EXPLAIN_RATIO_TIME_FORMAT "Ratio: %f" +#define EXPLAIN_PLANNING_TIME_FORMAT "Planning Time: %.3f ms" +#define EXPLAIN_EXEC_TIME_FORMAT "Execution Time: %.3f ms" //append area #define EXPLAIN_LEFT_PARENTHESIS_FORMAT " (" @@ -108,16 +111,19 @@ typedef struct SExplainCtx { #define EXPLAIN_ROW_NEW(level, ...) \ do { \ if (isVerboseLine) { \ - tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, "%*s", (level) * 2 + 3, ""); \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s", (level) * 2 + 3, ""); \ } else { \ - tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, "%*s%s", (level) * 2, "", "-> "); \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s%s", (level) * 2, "", "-> "); \ } \ - tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - tlen, __VA_ARGS__); \ + tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__); \ } while (0) -#define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - tlen, __VA_ARGS__) +#define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__) #define EXPLAIN_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; isVerboseLine = true; } while (0) +#define EXPLAIN_SUM_ROW_NEW(...) tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, __VA_ARGS__) +#define EXPLAIN_SUM_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; } while (0) + #ifdef __cplusplus } #endif diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 155da8de49..7a6264709f 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -894,9 +894,33 @@ _return: QRY_RET(code); } +int32_t qExplainAppendPlanRows(SExplainCtx *pCtx) { + if (EXPLAIN_MODE_ANALYZE != pCtx->mode) { + return TSDB_CODE_SUCCESS; + } + + int32_t tlen = 0; + char *tbuf = pCtx->tbuf; + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_RATIO_TIME_FORMAT, pCtx->ratio); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_PLANNING_TIME_FORMAT, (double)(pCtx->jobStartTs - pCtx->reqStartTs) / 1000.0); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_EXEC_TIME_FORMAT, (double)(pCtx->jobDoneTs - pCtx->jobStartTs) / 1000.0); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + return TSDB_CODE_SUCCESS; +} int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { QRY_ERR_RET(qExplainAppendGroupResRows(pCtx, pCtx->rootGroupId, 0)); + + QRY_ERR_RET(qExplainAppendPlanRows(pCtx)); QRY_ERR_RET(qExplainGetRspFromCtx(pCtx, pRsp)); @@ -977,18 +1001,18 @@ _return: QRY_RET(code); } -int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int32_t startTs) { +int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs) { QRY_ERR_RET(qExplainPrepareCtx(pDag, pCtx)); (*pCtx)->reqStartTs = startTs; - (*pCtx)->jobStartTs = taosGetTimestampMs(); + (*pCtx)->jobStartTs = taosGetTimestampUs(); return TSDB_CODE_SUCCESS; } int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { int32_t code = 0; - pCtx->jobDoneTs = taosGetTimestampMs(); + pCtx->jobDoneTs = taosGetTimestampUs(); atomic_store_8((int8_t *)&pCtx->execDone, true); diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4908748f0d..cf05d87d4d 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -207,7 +207,9 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { CHECK_RAW_EXPR_NODE(pNode); SRawExprNode* pRawExpr = (SRawExprNode*)pNode; SNode* pExpr = pRawExpr->pNode; - strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, pRawExpr->n); + if (nodesIsExprNode(pExpr)) { + strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, pRawExpr->n); + } taosMemoryFreeClear(pNode); return pExpr; } @@ -498,8 +500,9 @@ SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* p if (NULL == pNode || !pCxt->valid) { return pNode; } - uint32_t maxLen = sizeof(((SExprNode*)pNode)->aliasName); - strncpy(((SExprNode*)pNode)->aliasName, pAlias->z, pAlias->n > maxLen ? maxLen : pAlias->n); + int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n); + strncpy(((SExprNode*)pNode)->aliasName, pAlias->z, len); + ((SExprNode*)pNode)->aliasName[len] = '\0'; return pNode; } diff --git a/tests/script/general/explain/explain.sim b/tests/script/general/explain/explain.sim index 666e4040b7..3358b24e83 100644 --- a/tests/script/general/explain/explain.sim +++ b/tests/script/general/explain/explain.sim @@ -99,4 +99,4 @@ sql explain analyze verbose true select * from (select min(f1),count(*) a from s #sql explain analyze verbose true select sum(a+b) from (select _rowts, min(f1) b,count(*) a from st1 where f1 > 0 interval(1a)) where a < 0 interval(1s); -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT From cd75d1121a44edd21de121267ec41c3073294f68 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Mon, 11 Apr 2022 14:48:07 +0800 Subject: [PATCH 17/39] constant calc bugfix --- source/libs/function/src/builtins.c | 94 +++++++++++++-------------- source/libs/parser/src/parCalcConst.c | 3 +- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index aa7343f610..7acb0e5463 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -19,14 +19,14 @@ #include "taoserror.h" #include "tdatablock.h" -int32_t stubCheckAndGetResultType(SFunctionNode* pFunc); +int32_t checkAndGetResultType(SFunctionNode* pFunc); const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "count", .type = FUNCTION_TYPE_COUNT, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getCountFuncEnv, .initFunc = functionSetup, .processFunc = countFunction, @@ -36,7 +36,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sum", .type = FUNCTION_TYPE_SUM, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getSumFuncEnv, .initFunc = functionSetup, .processFunc = sumFunction, @@ -46,7 +46,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "min", .type = FUNCTION_TYPE_MIN, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getMinmaxFuncEnv, .initFunc = minFunctionSetup, .processFunc = minFunction, @@ -56,7 +56,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "max", .type = FUNCTION_TYPE_MAX, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -66,7 +66,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "stddev", .type = FUNCTION_TYPE_STDDEV, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getStddevFuncEnv, .initFunc = stddevFunctionSetup, .processFunc = stddevFunction, @@ -76,7 +76,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "percentile", .type = FUNCTION_TYPE_PERCENTILE, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getPercentileFuncEnv, .initFunc = percentileFunctionSetup, .processFunc = percentileFunction, @@ -86,7 +86,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "apercentile", .type = FUNCTION_TYPE_APERCENTILE, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -96,7 +96,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "top", .type = FUNCTION_TYPE_TOP, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -106,7 +106,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "bottom", .type = FUNCTION_TYPE_BOTTOM, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -116,7 +116,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "spread", .type = FUNCTION_TYPE_SPREAD, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -126,7 +126,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "last_row", .type = FUNCTION_TYPE_LAST_ROW, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -136,7 +136,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "first", .type = FUNCTION_TYPE_FIRST, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getFirstLastFuncEnv, .initFunc = functionSetup, .processFunc = firstFunction, @@ -146,7 +146,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "last", .type = FUNCTION_TYPE_LAST, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getFirstLastFuncEnv, .initFunc = functionSetup, .processFunc = lastFunction, @@ -156,7 +156,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "diff", .type = FUNCTION_TYPE_DIFF, .classification = FUNC_MGT_NONSTANDARD_SQL_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getDiffFuncEnv, .initFunc = diffFunctionSetup, .processFunc = diffFunction, @@ -166,7 +166,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "abs", .type = FUNCTION_TYPE_ABS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = absFunction, @@ -176,7 +176,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "log", .type = FUNCTION_TYPE_LOG, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = logFunction, @@ -186,7 +186,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "pow", .type = FUNCTION_TYPE_POW, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = powFunction, @@ -196,7 +196,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sqrt", .type = FUNCTION_TYPE_SQRT, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = sqrtFunction, @@ -206,7 +206,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "ceil", .type = FUNCTION_TYPE_CEIL, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = ceilFunction, @@ -216,7 +216,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "floor", .type = FUNCTION_TYPE_FLOOR, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = floorFunction, @@ -226,7 +226,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "round", .type = FUNCTION_TYPE_ROUND, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = roundFunction, @@ -236,7 +236,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sin", .type = FUNCTION_TYPE_SIN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = sinFunction, @@ -246,7 +246,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "cos", .type = FUNCTION_TYPE_COS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = cosFunction, @@ -256,7 +256,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "tan", .type = FUNCTION_TYPE_TAN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = tanFunction, @@ -266,7 +266,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "asin", .type = FUNCTION_TYPE_ASIN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = asinFunction, @@ -276,7 +276,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "acos", .type = FUNCTION_TYPE_ACOS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = acosFunction, @@ -286,7 +286,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "atan", .type = FUNCTION_TYPE_ATAN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = atanFunction, @@ -296,7 +296,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "length", .type = FUNCTION_TYPE_LENGTH, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = lengthFunction, @@ -306,7 +306,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "char_length", .type = FUNCTION_TYPE_CHAR_LENGTH, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = charLengthFunction, @@ -316,7 +316,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "concat", .type = FUNCTION_TYPE_CONCAT, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = concatFunction, @@ -326,7 +326,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "concat_ws", .type = FUNCTION_TYPE_CONCAT_WS, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = concatWsFunction, @@ -336,7 +336,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "lower", .type = FUNCTION_TYPE_LOWER, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = lowerFunction, @@ -346,7 +346,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "upper", .type = FUNCTION_TYPE_UPPER, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = upperFunction, @@ -356,7 +356,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "ltrim", .type = FUNCTION_TYPE_LTRIM, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = ltrimFunction, @@ -366,7 +366,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "rtrim", .type = FUNCTION_TYPE_RTRIM, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = rtrimFunction, @@ -376,7 +376,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "substr", .type = FUNCTION_TYPE_SUBSTR, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = substrFunction, @@ -386,7 +386,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "cast", .type = FUNCTION_TYPE_CAST, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = NULL, @@ -396,7 +396,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_rowts", .type = FUNCTION_TYPE_ROWTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = NULL, @@ -406,7 +406,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "tbname", .type = FUNCTION_TYPE_TBNAME, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = NULL, @@ -416,7 +416,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_qstartts", .type = FUNCTION_TYPE_QSTARTTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = qStartTsFunction, @@ -426,7 +426,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_qendts", .type = FUNCTION_TYPE_QENDTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = qEndTsFunction, @@ -436,7 +436,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wstartts", .type = FUNCTION_TYPE_WSTARTTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winStartTsFunction, @@ -446,7 +446,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wendts", .type = FUNCTION_TYPE_QENDTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winEndTsFunction, @@ -456,7 +456,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wduration", .type = FUNCTION_TYPE_WDURATION, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winDurFunction, @@ -466,7 +466,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "now", .type = FUNCTION_TYPE_NOW, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, - .checkFunc = stubCheckAndGetResultType, + .checkFunc = checkAndGetResultType, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winDurFunction, @@ -476,7 +476,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition)); -int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { +int32_t checkAndGetResultType(SFunctionNode* pFunc) { switch(pFunc->funcType) { case FUNCTION_TYPE_WDURATION: case FUNCTION_TYPE_COUNT: { diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 048830b80b..c31ec92bde 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -45,7 +45,7 @@ static EDealRes calcConstOperator(SOperatorNode** pNode, void* pContext) { static EDealRes calcConstFunction(SFunctionNode** pNode, void* pContext) { SFunctionNode* pFunc = *pNode; - if (fmIsPseudoColumnFunc(pFunc->funcId)) { + if (!fmIsScalarFunc(pFunc->funcId)) { return DEAL_RES_CONTINUE; } SNode* pParam = NULL; @@ -61,6 +61,7 @@ static EDealRes calcConstLogicCond(SLogicConditionNode** pNode, void* pContext) SLogicConditionNode* pCond = *pNode; SNode* pParam = NULL; FOREACH(pParam, pCond->pParameterList) { + // todo calc "true and c1 > 10" if (QUERY_NODE_VALUE != nodeType(pParam)) { return DEAL_RES_CONTINUE; } From b223010bdd69e917c0dd5db9f0c14305a2fb1dc4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 14:54:16 +0800 Subject: [PATCH 18/39] fix[query]:fix memory invalid write in group by nchar data. --- source/libs/executor/inc/executorimpl.h | 2 +- source/libs/executor/src/executorimpl.c | 45 ++++++++++++++---------- source/libs/executor/src/groupoperator.c | 17 ++++++--- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 9a75830ec4..f6f863c82d 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -671,7 +671,7 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator); void operatorDummyCloseFn(void* param, int32_t numOfCols); int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num); int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, - int32_t numOfRows, SSDataBlock* pResultBlock, const char* pkey); + int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey); void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset); void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 1bc84f85d7..1c9ca87563 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -1687,12 +1687,13 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { if (IS_VAR_DATA_TYPE(type)) { - if (pResultRow->key == NULL) { - pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); - varDataCopy(pResultRow->key, pData); - } else { - assert(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); - } + // todo disable this +// if (pResultRow->key == NULL) { +// pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); +// varDataCopy(pResultRow->key, pData); +// } else { +// ASSERT(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); +// } } else { int64_t v = -1; GET_TYPED_DATA(v, int64_t, type, pData); @@ -4467,7 +4468,7 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { return pResBlock; } -static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey); +static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey); static void cleanupAggSup(SAggSupporter* pAggSup); static void destroySortedMergeOperatorInfo(void* param, int32_t numOfOutput) { @@ -4826,7 +4827,8 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t goto _error; } - int32_t code = doInitAggInfoSup(&pInfo->aggSup, pInfo->binfo.pCtx, num, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = doInitAggInfoSup(&pInfo->aggSup, pInfo->binfo.pCtx, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -5890,11 +5892,11 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { taosMemoryFreeClear(pOperator); } -int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey) { +int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey) { _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput); - pAggSup->keyBuf = taosMemoryCalloc(1, sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES); + pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize); pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK); pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK); pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell)); @@ -5921,12 +5923,12 @@ static void cleanupAggSup(SAggSupporter* pAggSup) { } int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, - int32_t numOfRows, SSDataBlock* pResultBlock, const char* pkey) { + int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey) { pBasicInfo->pCtx = createSqlFunctionCtx_rv(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset); pBasicInfo->pRes = pResultBlock; pBasicInfo->capacity = numOfRows; - doInitAggInfoSup(pAggSup, pBasicInfo->pCtx, numOfCols, pkey); + doInitAggInfoSup(pAggSup, pBasicInfo->pCtx, numOfCols, keyBufSize, pkey); return TSDB_CODE_SUCCESS; } @@ -5965,7 +5967,8 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* //(int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); int32_t numOfRows = 1; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, keyBufSize, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; @@ -6081,8 +6084,9 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprI SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); int32_t numOfRows = 1; + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; int32_t code = - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; @@ -6142,7 +6146,8 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p int32_t numOfCols = num; int32_t numOfRows = 4096; - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); setFunctionResultOutput(&pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, pTaskInfo); pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pInfo->binfo.pCtx, numOfCols); @@ -6190,7 +6195,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pInfo->primaryTsIndex = primaryTsSlot; int32_t numOfRows = 4096; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); initExecTimeWindowInfo(&pInfo->timeWindowData, &pInfo->win); // pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); @@ -6266,8 +6272,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf } pInfo->colIndex = -1; - - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExpr, numOfCols, 4096, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExpr, numOfCols, 4096, pResBlock, keyBufSize, pTaskInfo->id.str); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); pOperator->name = "StateWindowOperator"; @@ -6299,7 +6305,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo } int32_t numOfRows = 4096; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 3eb8ff1b72..9410d1384d 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -46,7 +46,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); for (int32_t i = 0; i < numOfGroupCols; ++i) { SColumn* pCol = taosArrayGet(pGroupColList, i); - (*keyLen) += pCol->bytes; + (*keyLen) += pCol->bytes; // actual data + null_flag SGroupKeys key = {0}; key.bytes = pCol->bytes; @@ -61,8 +61,9 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** } int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols; + (*keyLen) += nullFlagSize; - (*keyBuf) = taosMemoryCalloc(1, (*keyLen) + nullFlagSize); + (*keyBuf) = taosMemoryCalloc(1, (*keyLen)); if ((*keyBuf) == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -169,11 +170,16 @@ static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[i]); SColumnInfoData* pColInfoData = pCtx[i].input.pData[0]; + // todo OPT all/all not NULL if (!colDataIsNull(pColInfoData, totalRows, rowIndex, NULL)) { char* dest = GET_ROWCELL_INTERBUF(pEntryInfo); char* data = colDataGetData(pColInfoData, rowIndex); - memcpy(dest, data, pColInfoData->info.bytes); + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + varDataCopy(dest, data); + } else { + memcpy(dest, data, pColInfoData->info.bytes); + } } else { // it is a NULL value pEntryInfo->isNullRes = 1; } @@ -326,14 +332,15 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pInfo->pGroupCols = pGroupColList; pInfo->pCondition = pCondition; - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, 4096, pResultBlock, pTaskInfo->id.str); - initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); int32_t code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList); if (code != TSDB_CODE_SUCCESS) { goto _error; } + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, 4096, pResultBlock, pInfo->groupKeyLen, pTaskInfo->id.str); + initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); + pOperator->name = "GroupbyAggOperator"; pOperator->blockingOptr = true; pOperator->status = OP_NOT_OPENED; From 86a39034d3209ee4dbb7638f4135d9547572e0d6 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:13:53 +0800 Subject: [PATCH 19/39] add explain case --- tests/script/{general/explain => tsim/query}/explain.sim | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/script/{general/explain => tsim/query}/explain.sim (100%) diff --git a/tests/script/general/explain/explain.sim b/tests/script/tsim/query/explain.sim similarity index 100% rename from tests/script/general/explain/explain.sim rename to tests/script/tsim/query/explain.sim From e158dbeed99f6c0685d71092b943488c17f095c8 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:21:55 +0800 Subject: [PATCH 20/39] add case to CI --- tests/script/jenkins/basic.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2d18167337..d3ae58a524 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -32,6 +32,7 @@ ./test.sh -f tsim/query/interval-offset.sim ./test.sh -f tsim/query/scalarFunction.sim ./test.sh -f tsim/query/charScalarFunction.sim +./test.sh -f tsim/query/explain.sim # ---- qnode ./test.sh -f tsim/qnode/basic1.sim From 6b681d79d4de328f3b4d110e39433a2aec5f5df4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 15:25:19 +0800 Subject: [PATCH 21/39] fix[query]:enable sum function to be applied to bool data type. --- source/libs/function/src/builtins.c | 2 +- source/libs/function/src/builtinsimpl.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index c1cdcbcb0c..0d0afd4011 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -479,7 +479,7 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { int32_t paraType = pParam->node.resType.type; int32_t resType = 0; - if (IS_SIGNED_NUMERIC_TYPE(paraType)) { + if (IS_SIGNED_NUMERIC_TYPE(paraType) || paraType == TSDB_DATA_TYPE_BOOL) { resType = TSDB_DATA_TYPE_BIGINT; } else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) { resType = TSDB_DATA_TYPE_UBIGINT; diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index bad40422c8..53b15a82af 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -138,8 +138,8 @@ int32_t sumFunction(SqlFunctionCtx *pCtx) { int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; - if (IS_SIGNED_NUMERIC_TYPE(type)) { - if (type == TSDB_DATA_TYPE_TINYINT) { + if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { + if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) { LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int8_t, numOfElem); } else if (type == TSDB_DATA_TYPE_SMALLINT) { LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int16_t, numOfElem); From e4d53ef3c77245311a65b54d5de0a70b9830c28c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:57:34 +0800 Subject: [PATCH 22/39] fix hb bug --- source/common/src/tmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 5973a70b59..0edfcb3314 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1960,7 +1960,7 @@ int32_t tDeserializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pR int32_t numOfBatch = taosArrayGetSize(pRsp->pArray); if (tDecodeI32(&decoder, &numOfBatch) < 0) return -1; - pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbBatchRsp)); + pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbRsp)); if (pRsp->pArray == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; From 3ff5d91d31c7fee71280ea19eca93cac48387171 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 11 Apr 2022 16:12:34 +0800 Subject: [PATCH 23/39] test:add session windows cases --- tests/script/tsim/query/session.sim | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim index 3a57581668..2f85cc7723 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -77,6 +77,8 @@ sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.51', 7) $loop_test = 0 loop_test_pos: +sql use $dbNamme + # session(ts,5a) print ====> select count(*) from dev_001 session(ts,5a) sql select _wstartts, count(*) from dev_001 session(ts,5a) @@ -301,12 +303,17 @@ sql create table dev_001 (ts timestamp ,i timestamp ,j int) sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4) print ====> select count(*) from dev_001 session(ts,1u) sql select _wstartts, count(*) from dev_001 session(ts,1u) -if $rows != 2 then +print rows: $rows +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +print $data20 $data21 $data22 $data23 +print $data30 $data31 $data32 $data33 +if $rows != 4 then print expect 2, actual: $rows return -1 endi -if $data01 != 3 then +if $data01 != 1 then return -1 endi From e30d114c7b9bdcfa3289ac171ee198050d85815b Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Mon, 11 Apr 2022 16:27:42 +0800 Subject: [PATCH 24/39] set datablock desc timestamp precision --- include/libs/nodes/plannodes.h | 7 +-- source/libs/command/src/explain.c | 2 +- source/libs/executor/src/executorimpl.c | 2 +- source/libs/nodes/src/nodesCodeFuncs.c | 18 +++---- source/libs/nodes/src/nodesUtilFuncs.c | 2 +- source/libs/planner/src/planPhysiCreater.c | 55 +++++++++++++--------- source/libs/planner/src/planSpliter.c | 1 + 7 files changed, 49 insertions(+), 38 deletions(-) diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 7cb96104bd..3931be7da5 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -84,6 +84,7 @@ typedef struct SVnodeModifLogicNode { typedef struct SExchangeLogicNode { SLogicNode node; int32_t srcGroupId; + uint8_t precision; } SExchangeLogicNode; typedef enum EWindowType { @@ -163,7 +164,7 @@ typedef struct SDataBlockDescNode { SNodeList* pSlots; int32_t totalRowSize; int32_t outputRowSize; - int16_t precision; + uint8_t precision; } SDataBlockDescNode; typedef struct SPhysiNode { @@ -253,11 +254,11 @@ typedef struct SWinodwPhysiNode { SPhysiNode node; SNodeList* pExprs; // these are expression list of parameter expression of function SNodeList* pFuncs; + SNode* pTspk; // timestamp primary key } SWinodwPhysiNode; typedef struct SIntervalPhysiNode { SWinodwPhysiNode window; - SNode* pTspk; // timestamp primary key int64_t interval; int64_t offset; int64_t sliding; @@ -274,7 +275,7 @@ typedef struct SMultiTableIntervalPhysiNode { typedef struct SSessionWinodwPhysiNode { SWinodwPhysiNode window; - int64_t gap; + int64_t gap; } SSessionWinodwPhysiNode; typedef struct SStateWinodwPhysiNode { diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 605d8f41da..064dde3ee9 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -641,7 +641,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{ SIntervalPhysiNode *pIntNode = (SIntervalPhysiNode *)pNode; - EXPLAIN_ROW_NEW(level, EXPLAIN_INTERVAL_FORMAT, nodesGetNameFromColumnNode(pIntNode->pTspk)); + EXPLAIN_ROW_NEW(level, EXPLAIN_INTERVAL_FORMAT, nodesGetNameFromColumnNode(pIntNode->window.pTspk)); EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT); if (pResNode->pExecInfo) { QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 1bc84f85d7..74544cc202 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -6916,7 +6916,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo .precision = pIntervalPhyNode->precision }; - int32_t primaryTsSlotId = ((SColumnNode*) pIntervalPhyNode->pTspk)->slotId; + int32_t primaryTsSlotId = ((SColumnNode*) pIntervalPhyNode->window.pTspk)->slotId; return createIntervalOperatorInfo(op, pExprInfo, num, pResBlock, &interval, primaryTsSlotId, pTableGroupInfo, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) { SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode; diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 7f91aeb16f..13093d63ac 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -65,7 +65,7 @@ const char* nodesNodeName(ENodeType type) { case QUERY_NODE_TARGET: return "Target"; case QUERY_NODE_DATABLOCK_DESC: - return "TupleDesc"; + return "DataBlockDesc"; case QUERY_NODE_SLOT_DESC: return "SlotDesc"; case QUERY_NODE_COLUMN_DEF: @@ -1060,6 +1060,7 @@ static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) { static const char* jkWindowPhysiPlanExprs = "Exprs"; static const char* jkWindowPhysiPlanFuncs = "Funcs"; +static const char* jkWindowPhysiPlanTsPk = "TsPk"; static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) { const SWinodwPhysiNode* pNode = (const SWinodwPhysiNode*)pObj; @@ -1071,6 +1072,9 @@ static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkWindowPhysiPlanFuncs, pNode->pFuncs); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk); + } return code; } @@ -1085,6 +1089,9 @@ static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkWindowPhysiPlanFuncs, &pNode->pFuncs); } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk); + } return code; } @@ -1095,7 +1102,6 @@ static const char* jkIntervalPhysiPlanSliding = "Sliding"; static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit"; static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit"; static const char* jkIntervalPhysiPlanFill = "Fill"; -static const char* jkIntervalPhysiPlanTsPk = "TsPk"; static const char* jkIntervalPhysiPlanPrecision = "Precision"; static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { @@ -1120,9 +1126,6 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkIntervalPhysiPlanFill, nodeToJson, pNode->pFill); } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddObject(pJson, jkIntervalPhysiPlanTsPk, nodeToJson, pNode->pTspk); - } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanPrecision, pNode->precision); } @@ -1152,9 +1155,6 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkIntervalPhysiPlanFill, (SNode**)&pNode->pFill); } - if (TSDB_CODE_SUCCESS == code) { - code = jsonToNodeObject(pJson, jkIntervalPhysiPlanTsPk, (SNode**)&pNode->pTspk); - } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetUTinyIntValue(pJson, jkIntervalPhysiPlanPrecision, &pNode->precision); } @@ -2291,7 +2291,7 @@ static int32_t jsonToDataBlockDescNode(const SJson* pJson, void* pObj) { code = jsonToNodeList(pJson, jkDataBlockDescSlots, &pNode->pSlots); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetSmallIntValue(pJson, jkDataBlockPrecision, &pNode->precision); + code = tjsonGetUTinyIntValue(pJson, jkDataBlockPrecision, &pNode->precision); } return code; diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index d21eec0a41..9f81b34274 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -252,6 +252,7 @@ static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) { destroyPhysiNode((SPhysiNode*)pNode); nodesDestroyList(pNode->pExprs); nodesDestroyList(pNode->pFuncs); + nodesDestroyNode(pNode->pTspk); } static void destroyScanPhysiNode(SScanPhysiNode* pNode) { @@ -593,7 +594,6 @@ void nodesDestroyNode(SNodeptr pNode) { SIntervalPhysiNode* pPhyNode = (SIntervalPhysiNode*)pNode; destroyWinodwPhysiNode((SWinodwPhysiNode*)pPhyNode); nodesDestroyNode(pPhyNode->pFill); - nodesDestroyNode(pPhyNode->pTspk); break; } case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 0c2cffa399..3b255bf276 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -316,7 +316,18 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i return TSDB_CODE_SUCCESS; } -static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, ENodeType type) { +static uint8_t getPrecision(SNodeList* pChildren) { + if (1 == LIST_LENGTH(pChildren)) { + return (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc)->precision; + } else if (2 == LIST_LENGTH(pChildren)) { + uint8_t lp = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc)->precision; + uint8_t rp = (((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc)->precision; + return (lp > rp ? rp : lp); + } + return 0; +} + +static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, uint8_t precision, SLogicNode* pLogicNode, ENodeType type) { SPhysiNode* pPhysiNode = (SPhysiNode*)nodesMakeNode(type); if (NULL == pPhysiNode) { return NULL; @@ -327,6 +338,7 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode nodesDestroyNode(pPhysiNode); return NULL; } + pPhysiNode->pOutputDataBlockDesc->precision = precision; return pPhysiNode; } @@ -405,7 +417,7 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd } static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); + STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); if (NULL == pTagScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -413,7 +425,7 @@ static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* p } static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); + STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); if (NULL == pTableScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -430,7 +442,7 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp } static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN); + SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -451,7 +463,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* } static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); + SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -515,7 +527,7 @@ static int32_t createJoinOutputCols(SPhysiPlanContext* pCxt, SDataBlockDescNode* } static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) { - SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN); + SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN); if (NULL == pJoin) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -656,7 +668,7 @@ static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeLi } static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) { - SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG); + SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG); if (NULL == pAgg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -710,7 +722,7 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, } static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) { - SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT); + SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT); if (NULL == pProject) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -738,18 +750,18 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild } static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { - SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE); + SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE); if (NULL == pExchange) { return TSDB_CODE_OUT_OF_MEMORY; } - + pExchange->srcGroupId = pExchangeLogicNode->srcGroupId; *pPhyNode = (SPhysiNode*)pExchange; return TSDB_CODE_SUCCESS; } static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { - SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); + SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -803,6 +815,10 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* } } + if (TSDB_CODE_SUCCESS == code) { + code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pWindow->pTspk); + } + if (TSDB_CODE_SUCCESS == code && NULL != pFuncs) { code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pWindow->pFuncs); if (TSDB_CODE_SUCCESS == code) { @@ -820,7 +836,7 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* } static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL); + SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL); if (NULL == pInterval) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -838,18 +854,11 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil return TSDB_CODE_OUT_OF_MEMORY; } - SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); - int32_t code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pInterval->pTspk); - if (TSDB_CODE_SUCCESS != code) { - nodesDestroyNode(pInterval); - return code; - } - return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode); } static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW); + SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW); if (NULL == pSession) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -860,7 +869,7 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* } static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW); + SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW); if (NULL == pState) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -908,7 +917,7 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr } static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) { - SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT); + SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT); if (NULL == pSort) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -947,7 +956,7 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren } static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) { - SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION); + SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION); if (NULL == pPart) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 3ce225abab..aadbaf6fd8 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -103,6 +103,7 @@ static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla return TSDB_CODE_OUT_OF_MEMORY; } pExchange->srcGroupId = pCxt->groupId; + pExchange->precision = pScan->pMeta->tableInfo.precision; pExchange->node.pTargets = nodesCloneList(pScan->node.pTargets); if (NULL == pExchange->node.pTargets) { return TSDB_CODE_OUT_OF_MEMORY; From 0f83fd7c5903b7358c48511847c2e7bec1f296f8 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 11 Apr 2022 16:32:44 +0800 Subject: [PATCH 25/39] test: add session cases into CI --- tests/script/jenkins/basic.txt | 1 + tests/script/tsim/query/session.sim | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 761a8921d5..c6a69f7e06 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -32,6 +32,7 @@ ./test.sh -f tsim/query/interval-offset.sim ./test.sh -f tsim/query/scalarFunction.sim ./test.sh -f tsim/query/charScalarFunction.sim +./test.sh -f tsim/query/session.sim # ---- qnode ./test.sh -f tsim/qnode/basic1.sim diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim index 2f85cc7723..282d83bc27 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -219,8 +219,8 @@ endi #endi -print ====> leastsquares not supported yet. -print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) +#print ====> leastsquares not supported yet. +#print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) #sql select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) #if $rows != 2 then # return -1 @@ -287,14 +287,14 @@ print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtyp #endi print ================> syntax error check not active ================> reactive -#sql_error select * from dev_001 session(ts,1w) -#sql_error select count(*) from st session(ts,1w) -#sql_error select count(*) from dev_001 group by tagtype session(ts,1w) -#sql_error select count(*) from dev_001 session(ts,1n) -#sql_error select count(*) from dev_001 session(ts,1y) -#sql_error select count(*) from dev_001 session(ts,0s) -#sql_error select count(*) from dev_001 session(i,1y) -#sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0' +sql_error select * from dev_001 session(ts,1w) +sql select count(*) from st session(ts,1w) +sql_error select count(*) from dev_001 group by tagtype session(ts,1w) +sql select count(*) from dev_001 session(ts,1n) +sql select count(*) from dev_001 session(ts,1y) +sql select count(*) from dev_001 session(ts,0s) +sql_error select count(*) from dev_001 session(i,1y) +sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0' print ====> create database d1 precision 'us' sql create database d1 precision 'us' @@ -318,7 +318,7 @@ if $data01 != 1 then endi #sql_error select count(*) from dev_001 session(i,1s) -#sql create table secondts(ts timestamp,t2 timestamp,i int) +sql create table secondts(ts timestamp,t2 timestamp,i int) #sql_error select count(*) from secondts session(t2,2s) if $loop_test == 0 then From 8240efda4c98304918ad42993f3122fa09dd25e5 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 17:03:41 +0800 Subject: [PATCH 26/39] fix[query]: enable filter on nchar type. --- source/libs/scalar/src/filter.c | 29 +++++++++--------- source/libs/scalar/src/scalar.c | 1 - source/libs/scalar/src/sclvector.c | 48 ++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 2e47e19023..191143de12 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1748,7 +1748,6 @@ int32_t fltInitValFieldData(SFilterInfo *info) { SFilterField* fi = right; SValueNode* var = (SValueNode *)fi->desc; - if (var == NULL) { assert(fi->data != NULL); continue; @@ -1767,13 +1766,18 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } SDataType *dType = &var->node.resType; + size_t bytes = 0; if (type == TSDB_DATA_TYPE_BINARY) { size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; - fi->data = taosMemoryCalloc(1, len + 1 + VARSTR_HEADER_SIZE); + bytes = len + 1 + VARSTR_HEADER_SIZE; + + fi->data = taosMemoryCalloc(1, bytes); } else if (type == TSDB_DATA_TYPE_NCHAR) { - size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; - fi->data = taosMemoryCalloc(1, (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; + bytes = (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; + + fi->data = taosMemoryCalloc(1, bytes); } else if (type != TSDB_DATA_TYPE_JSON){ if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE /* @@ -1797,8 +1801,11 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } else { SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; out.columnData->info.type = type; - out.columnData->info.bytes = tDataTypes[type].bytes; - ASSERT(!IS_VAR_DATA_TYPE(type)); + if (IS_VAR_DATA_TYPE(type)) { + out.columnData->info.bytes = bytes; + } else { + out.columnData->info.bytes = tDataTypes[type].bytes; + } // todo refactor the convert int32_t code = doConvertDataType(var, &out); @@ -2985,13 +2992,13 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); - if (colData == NULL || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)) { + if (colData == NULL || colDataIsNull_s((SColumnInfoData *)info->cunits[uidx].colData, i)) { (*p)[i] = 0; all = false; continue; } - // match/nmatch for nchar type need convert from ucs4 to mbs + // match/nmatch for nchar type need convert from ucs4 to mbs if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)){ char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); @@ -3222,19 +3229,13 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) { info->unitFlags = taosMemoryMalloc(info->unitNum * sizeof(*info->unitFlags)); filterDumpInfoToString(info, "Final", 0); - return code; _return: - qInfo("init from node failed, code:%d", code); - return code; } - - - bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows) { if (FILTER_EMPTY_RES(info)) { return false; diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index f97e5a2d2a..116dfdd5d5 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -46,7 +46,6 @@ int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out) { colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); colInfoDataEnsureCapacity(out->columnData, 1); - int32_t code = vectorConvertImpl(&in, out); sclFreeParam(&in); diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 4bce8f33f2..ff677d2f7b 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -177,10 +177,25 @@ static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowInd colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v); } +static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIndex) { + int32_t len = 0; + int32_t inputLen = varDataLen(buf); + + char* t = taosMemoryCalloc(1,(inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + /*int32_t resLen = */taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4*) varDataVal(t), pOut->columnData->info.bytes, &len); + varDataSetLen(t, len); + + colDataAppend(pOut->columnData, rowIndex, t, false); + taosMemoryFree(t); +} + +//TODO opt performance int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { int32_t bufSize = pIn->columnData->info.bytes; char *tmp = taosMemoryMalloc(bufSize); + bool vton = false; + _bufConverteFunc func = NULL; if (TSDB_DATA_TYPE_BOOL == outType) { func = varToBool; @@ -190,6 +205,9 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in func = varToUnsigned; } else if (IS_FLOAT_TYPE(outType)) { func = varToFloat; + } else if (outType == TSDB_DATA_TYPE_NCHAR) { + func = varToNchar; + vton = true; } else { sclError("invalid convert outType:%d", outType); return TSDB_CODE_QRY_APP_ERROR; @@ -197,26 +215,30 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in pOut->numOfRows = pIn->numOfRows; for (int32_t i = 0; i < pIn->numOfRows; ++i) { - if (colDataIsNull(pIn->columnData, pIn->numOfRows, i, NULL)) { + if (colDataIsNull_s(pIn->columnData, i)) { colDataAppendNULL(pOut->columnData, i); continue; } char* data = colDataGetData(pIn->columnData, i); - if (TSDB_DATA_TYPE_BINARY == inType) { - memcpy(tmp, varDataVal(data), varDataLen(data)); - tmp[varDataLen(data)] = 0; + if (vton) { + memcpy(tmp, data, varDataTLen(data)); } else { - ASSERT (varDataLen(data) <= bufSize); - - int len = taosUcs4ToMbs((TdUcs4*)varDataVal(data), varDataLen(data), tmp); - if (len < 0){ - sclError("castConvert taosUcs4ToMbs error 1"); - taosMemoryFreeClear(tmp); - return TSDB_CODE_QRY_APP_ERROR; + if (TSDB_DATA_TYPE_VARCHAR == inType) { + memcpy(tmp, varDataVal(data), varDataLen(data)); + tmp[varDataLen(data)] = 0; + } else { + ASSERT(varDataLen(data) <= bufSize); + + int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(data), varDataLen(data), tmp); + if (len < 0) { + sclError("castConvert taosUcs4ToMbs error 1"); + taosMemoryFreeClear(tmp); + return TSDB_CODE_QRY_APP_ERROR; + } + + tmp[len] = 0; } - - tmp[len] = 0; } (*func)(tmp, pOut, i); From 72e39b2bf521424065ebd740d5cb7e6089b83e34 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 11 Apr 2022 17:05:24 +0800 Subject: [PATCH 27/39] adaption for update function --- include/common/taosdef.h | 2 ++ include/common/tdataformat.h | 2 +- include/common/trow.h | 2 +- include/common/ttypes.h | 1 + source/common/src/tdataformat.c | 1 + source/common/src/trow.c | 26 +++++++------- source/dnode/vnode/src/tsdb/tsdbCommit.c | 40 +++++++++++++++++++++- source/dnode/vnode/src/tsdb/tsdbMemTable.c | 2 +- source/dnode/vnode/src/tsdb/tsdbRead.c | 8 +++++ source/dnode/vnode/src/tsdb/tsdbReadImpl.c | 7 ++-- 10 files changed, 72 insertions(+), 19 deletions(-) diff --git a/include/common/taosdef.h b/include/common/taosdef.h index 5001a99c2a..6e344dfdb4 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -57,6 +57,8 @@ typedef enum { TD_ROW_PARTIAL_UPDATE = 2, } TDUpdateConfig; +#define TD_SUPPORT_UPDATE(u) ((u) > 0) + typedef enum { TSDB_STATIS_OK = 0, // statis part exist and load successfully TSDB_STATIS_NONE = 1, // statis part not exist diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 8e07d4e669..8a87a1bd2e 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -482,7 +482,7 @@ void tdResetDataCols(SDataCols *pCols); int32_t tdInitDataCols(SDataCols *pCols, STSchema *pSchema); SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData); SDataCols *tdFreeDataCols(SDataCols *pCols); -int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool forceSetNull); +int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool forceSetNull, TDRowVerT maxVer); // ----------------- K-V data row structure /* |<-------------------------------------- len -------------------------------------------->| diff --git a/include/common/trow.h b/include/common/trow.h index b7ffcd14c6..539bda078d 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -230,7 +230,7 @@ static FORCE_INLINE int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowVa static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData, int8_t colType, int16_t colIdx, int32_t offset, col_id_t colId); -int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool forceSetNull); +int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols); /** * @brief diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 37d688a0ef..5f1cfc030a 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -27,6 +27,7 @@ extern "C" { typedef int32_t VarDataOffsetT; typedef uint32_t TDRowLenT; typedef uint8_t TDRowValT; +typedef uint64_t TDRowVerT; typedef int16_t col_id_t; typedef int8_t col_type_t; typedef int32_t col_bytes_t; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index f6614633fb..f2a5a98d96 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -411,6 +411,7 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { #endif pCols->numOfRows = 0; + pCols->bitmapMode = 0; pCols->numOfCols = schemaNCols(pSchema); for (i = 0; i < schemaNCols(pSchema); ++i) { diff --git a/source/common/src/trow.c b/source/common/src/trow.c index d9c48bfe76..7392b0bf8b 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -385,7 +385,6 @@ int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int pCol->len += pCol->bytes; } #ifdef TD_SUPPORT_BITMAP - tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode); #endif return 0; @@ -486,7 +485,7 @@ static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols * @param pCols * @param forceSetNull */ -int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool forceSetNull) { +int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols) { if (TD_IS_TP_ROW(pRow)) { return tdAppendTpRowToDataCol(pRow, pSchema, pCols); } else if (TD_IS_KV_ROW(pRow)) { @@ -497,7 +496,7 @@ int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCol return TSDB_CODE_SUCCESS; } -int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull) { +int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull, TDRowVerT maxVer) { ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows); ASSERT(target->numOfCols == source->numOfCols); int offset = 0; @@ -510,6 +509,7 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int * if ((target->numOfRows == 0) || (dataColsKeyLast(target) < dataColsKeyAtRow(source, *pOffset))) { // No overlap ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints); + // TODO: filter the maxVer for (int i = 0; i < rowsToMerge; i++) { for (int j = 0; j < source->numOfCols; j++) { if (source->cols[j].len > 0 || target->cols[j].len > 0) { @@ -555,9 +555,9 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i // TKEY tkey2 = (*iter2 >= limit2) ? TKEY_NULL : dataColsTKeyAt(src2, *iter2); ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1))); - + // TODO: filter the maxVer if (key1 < key2) { - for (int i = 0; i < src1->numOfCols; i++) { + for (int i = 0; i < src1->numOfCols; ++i) { ASSERT(target->cols[i].type == src1->cols[i].type); if (src1->cols[i].len > 0 || target->cols[i].len > 0) { SCellVal sVal = {0}; @@ -568,12 +568,12 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i } } - target->numOfRows++; - (*iter1)++; + ++target->numOfRows; + ++(*iter1); } else if (key1 >= key2) { - // if ((key1 > key2) || (key1 == key2 && !TKEY_IS_DELETED(tkey2))) { - if ((key1 > key2) || (key1 == key2)) { - for (int i = 0; i < src2->numOfCols; i++) { + // TODO: filter the maxVer + if ((key1 > key2) || ((key1 == key2) && !TKEY_IS_DELETED(key2))) { + for (int i = 0; i < src2->numOfCols; ++i) { SCellVal sVal = {0}; ASSERT(target->cols[i].type == src2->cols[i].type); if (tdGetColDataOfRow(&sVal, src2->cols + i, *iter2, src2->bitmapMode) < 0) { @@ -590,11 +590,11 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i dataColSetNullAt(&target->cols[i], target->numOfRows, true, target->bitmapMode); } } - target->numOfRows++; + ++target->numOfRows; } - (*iter2)++; - if (key1 == key2) (*iter1)++; + ++(*iter2); + if (key1 == key2) ++(*iter1); } ASSERT(target->numOfRows <= target->maxPoints); diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 21ad1ec076..67c7973206 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -1678,10 +1678,11 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt ASSERT(pSchema != NULL); } - tdAppendSTSRowToDataCol(row, pSchema, pTarget, true); + tdAppendSTSRowToDataCol(row, pSchema, pTarget); tSkipListIterNext(pCommitIter->pIter); } else { +#if 0 if (update != TD_ROW_OVERWRITE_UPDATE) { // copy disk data for (int i = 0; i < pDataCols->numOfCols; ++i) { @@ -1706,6 +1707,43 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt } ++(*iter); tSkipListIterNext(pCommitIter->pIter); +#endif + // copy disk data + for (int i = 0; i < pDataCols->numOfCols; ++i) { + SCellVal sVal = {0}; + if (tdGetColDataOfRow(&sVal, pDataCols->cols + i, *iter, pDataCols->bitmapMode) < 0) { + TASSERT(0); + } + // TODO: tdAppendValToDataCol may fail + tdAppendValToDataCol(pTarget->cols + i, sVal.valType, sVal.val, pTarget->numOfRows, pTarget->maxPoints, + pTarget->bitmapMode); + } + + if (TD_SUPPORT_UPDATE(update)) { + // copy mem data(Multi-Version) + if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) { + pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, TD_ROW_SVER(row)); + ASSERT(pSchema != NULL); + } + + // TODO: merge with Multi-Version + STSRow *curRow = row; + + ++(*iter); + tSkipListIterNext(pCommitIter->pIter); + STSRow *nextRow = tsdbNextIterRow(pCommitIter->pIter); + + if (key2 < TD_ROW_KEY(nextRow)) { + tdAppendSTSRowToDataCol(row, pSchema, pTarget); + } else { + tdAppendSTSRowToDataCol(row, pSchema, pTarget); + } + // TODO: merge with Multi-Version + } else { + ++pTarget->numOfRows; + ++(*iter); + tSkipListIterNext(pCommitIter->pIter); + } } if (pTarget->numOfRows >= maxRows) break; diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index c657b2e947..54115003cf 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -475,7 +475,7 @@ static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema * } } - tdAppendSTSRowToDataCol(row, *ppSchema, pCols, true); + tdAppendSTSRowToDataCol(row, *ppSchema, pCols); } return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 5677bb0615..e308c9c2b9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -761,6 +761,7 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, TSKEY r2 = TD_ROW_KEY(rimem); if (r1 == r2) { +#if 0 if(update == TD_ROW_DISCARD_UPDATE){ pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; tSkipListIterNext(pCheckInfo->iter); @@ -771,6 +772,13 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, } else { pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; } +#endif + if (TD_SUPPORT_UPDATE(update)) { + pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; + } else { + pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; + tSkipListIterNext(pCheckInfo->iter); + } return r1; } else if (r1 < r2 && ASCENDING_TRAVERSE(order)) { pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index 87459593b5..e31ede09cc 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -263,8 +263,9 @@ int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) { for (int i = 1; i < pBlock->numOfSubBlocks; i++) { iBlock++; if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[1]) < 0) return -1; + // TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL, - update != TD_ROW_PARTIAL_UPDATE) < 0) + update != TD_ROW_PARTIAL_UPDATE, UINT64_MAX) < 0) return -1; } @@ -293,8 +294,9 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, for (int i = 1; i < pBlock->numOfSubBlocks; i++) { iBlock++; if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[1], colIds, numOfColsIds) < 0) return -1; + // TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL, - update != TD_ROW_PARTIAL_UPDATE) < 0) + update != TD_ROW_PARTIAL_UPDATE, UINT64_MAX) < 0) return -1; } @@ -304,6 +306,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, if (pDataCol->bitmap) { ASSERT(pDataCol->colId != PRIMARYKEY_TIMESTAMP_COL_ID); tdMergeBitmap(pDataCol->pBitmap, TD_BITMAP_BYTES(pReadh->pDCols[0]->numOfRows), pDataCol->pBitmap); + tdDataColsSetBitmapI(pReadh->pDCols[0]); } } } From 4961b6ab8ee7cb58d51e204f73422c1ccc630b39 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 11 Apr 2022 17:08:13 +0800 Subject: [PATCH 28/39] feat: optimize encode/decode resultRow --- source/libs/executor/inc/executorimpl.h | 9 +- source/libs/executor/src/executorimpl.c | 134 ++++++++++------------- source/libs/executor/src/groupoperator.c | 6 +- 3 files changed, 68 insertions(+), 81 deletions(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 9a75830ec4..526f43cb64 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -232,9 +232,11 @@ typedef struct STaskAttr { } STaskAttr; struct SOperatorInfo; +struct SAggSupporter; +struct SOptrBasicInfo; -typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char **result, int32_t *length); -typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char *result, int32_t length); +typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter *pSup, struct SOptrBasicInfo *pInfo, char **result, int32_t *length); +typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter *pSup, struct SOptrBasicInfo *pInfo, char *result, int32_t length); typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr); typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr, bool* newgroup); @@ -753,6 +755,9 @@ void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status); int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model); int32_t getOperatorExplainExecInfo(SOperatorInfo *operatorInfo, SExplainExecInfo **pRes, int32_t *capacity, int32_t *resNum); +bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char* result, int32_t length); +void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char **result, int32_t *length); + #ifdef __cplusplus } #endif diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index d344b93485..8addd53479 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -4974,15 +4974,19 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order); doAggregateImpl(pOperator, 0, pInfo->pCtx); - char *result = NULL; - int32_t length = 0; - pOperator->encodeResultRow(pOperator, &result, &length); - SAggSupporter *pSup = &pAggInfo->aggSup; - taosHashClear(pSup->pResultRowHashTable); - pOperator->decodeResultRow(pOperator, result, length); - if(result){ - taosMemoryFree(result); + if(pOperator->encodeResultRow){ + char *result = NULL; + int32_t length = 0; + SAggSupporter *pSup = &pAggInfo->aggSup; + pOperator->encodeResultRow(pOperator, pSup, pInfo, &result, &length); + taosHashClear(pSup->pResultRowHashTable); + pInfo->resultRowInfo.size = 0; + pOperator->decodeResultRow(pOperator, pSup, pInfo, result, length); + if(result){ + taosMemoryFree(result); + } } + } finalizeQueryResult(pInfo->pCtx, pOperator->numOfOutput); @@ -5011,43 +5015,33 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator, bool* newgroup) return (blockDataGetNumOfRows(pInfo->pRes) != 0) ? pInfo->pRes : NULL; } -static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t *length) { - SAggSupporter *pSup = NULL; - switch(pOperator->operatorType){ - case QUERY_NODE_PHYSICAL_PLAN_AGG:{ - SAggOperatorInfo *pAggInfo = pOperator->info; - pSup = &pAggInfo->aggSup; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_GROUPBY:{ - SGroupbyOperatorInfo *pAggInfo = pOperator->info; - pSup = &pAggInfo->aggSup; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{ - STableIntervalOperatorInfo *pAggInfo = pOperator->info; - pSup = &pAggInfo->aggSup; - break; - } - default:{ - qDebug("invalid operatorType: %d", pOperator->operatorType); - } - } - +void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char **result, int32_t *length) { int32_t size = taosHashGetSize(pSup->pResultRowHashTable); - size_t keyLen = POINTER_BYTES; // estimate the key length + size_t keyLen = sizeof(uint64_t) * 2; // estimate the key length int32_t totalSize = sizeof(int32_t) + size * (sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize); *result = taosMemoryCalloc(1, totalSize); if (*result == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_OUT_OF_MEMORY); } *(int32_t*)(*result) = size; int32_t offset = sizeof(int32_t); + + // prepare memory + SResultRowPosition* pos = &pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.curPos]; + void* pPage = getBufPage(pSup->pResultBuf, pos->pageId); + SResultRow* pRow = (SResultRow*)((char*)pPage + pos->offset); + setBufPageDirty(pPage, true); + releaseBufPage(pSup->pResultBuf, pPage); + void* pIter = taosHashIterate(pSup->pResultRowHashTable, NULL); while (pIter) { void* key = taosHashGetKey(pIter, &keyLen); - SResultRow** p1 = (SResultRow**)pIter; + SResultRowPosition** p1 = (SResultRowPosition**)pIter; + + pPage = (SFilePage*) getBufPage(pSup->pResultBuf, (*p1)->pageId); + pRow = (SResultRow*)((char*)pPage + (*p1)->offset); + setBufPageDirty(pPage, true); + releaseBufPage(pSup->pResultBuf, pPage); // recalculate the result size int32_t realTotalSize = offset + sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize; @@ -5057,7 +5051,7 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(*result); *result = NULL; - return; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_OUT_OF_MEMORY); } else { *result = tmp; } @@ -5071,7 +5065,7 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t // save value *(int32_t*)(*result + offset) = pSup->resultRowSize; offset += sizeof(int32_t); - memcpy(*result + offset, *p1, pSup->resultRowSize); + memcpy(*result + offset, pRow, pSup->resultRowSize); offset += pSup->resultRowSize; pIter = taosHashIterate(pSup->pResultRowHashTable, pIter); @@ -5083,34 +5077,11 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t return; } -static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t length) { +bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char* result, int32_t length) { if (!result || length <= 0) { return false; } - SAggSupporter *pSup = NULL; - switch(pOperator->operatorType){ - case QUERY_NODE_PHYSICAL_PLAN_AGG:{ - SAggOperatorInfo *pAggInfo = pOperator->info; - //SOptrBasicInfo *pInfo = &pAggInfo->binfo; - pSup = &pAggInfo->aggSup; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_GROUPBY:{ - SGroupbyOperatorInfo *pAggInfo = pOperator->info; - pSup = &pAggInfo->aggSup; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{ - STableIntervalOperatorInfo *pAggInfo = pOperator->info; - pSup = &pAggInfo->aggSup; - break; - } - default:{ - qDebug("invalid operatorType: %d", pOperator->operatorType); - } - } - // int32_t size = taosHashGetSize(pSup->pResultRowHashTable); int32_t count = *(int32_t*)(result); @@ -5122,17 +5093,16 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t l uint64_t tableGroupId = *(uint64_t*)(result + offset); SResultRow* resultRow = getNewResultRow_rv(pSup->pResultBuf, tableGroupId, pSup->resultRowSize); if (!resultRow) { - terrno = TSDB_CODE_TSC_INVALID_INPUT; - return false; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT); } // add a new result set for a new group - taosHashPut(pSup->pResultRowHashTable, result + offset, keyLen, &resultRow, POINTER_BYTES); + SResultRowPosition pos = {.pageId = resultRow->pageId, .offset = resultRow->offset}; + taosHashPut(pSup->pResultRowHashTable, result + offset, keyLen, &pos, sizeof(SResultRowPosition)); offset += keyLen; int32_t valueLen = *(int32_t*)(result + offset); if (valueLen != pSup->resultRowSize) { - terrno = TSDB_CODE_TSC_INVALID_INPUT; - return false; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT); } offset += sizeof(int32_t); int32_t pageId = resultRow->pageId; @@ -5143,12 +5113,13 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t l offset += valueLen; initResultRow(resultRow); - //pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = (SResultRowPosition) {.pageId = resultRow->pageId, .offset = resultRow->offset}; + prepareResultListBuffer(&pInfo->resultRowInfo, pOperator->pTaskInfo->env); + pInfo->resultRowInfo.curPos = pInfo->resultRowInfo.size; + pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = (SResultRowPosition) {.pageId = resultRow->pageId, .offset = resultRow->offset}; } if (offset != length) { - terrno = TSDB_CODE_TSC_INVALID_INPUT; - return false; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT); } return true; } @@ -5375,16 +5346,21 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0); - char *result = NULL; - int32_t length = 0; - pOperator->encodeResultRow(pOperator, &result, &length); - SAggSupporter *pSup = &pInfo->aggSup; - taosHashClear(pSup->pResultRowHashTable); - pOperator->decodeResultRow(pOperator, result, length); - if(result){ - taosMemoryFree(result); +#if 0 + if(pOperator->encodeResultRow){ + char *result = NULL; + int32_t length = 0; + SAggSupporter *pSup = &pInfo->aggSup; + pOperator->encodeResultRow(pOperator, pSup, &pInfo->binfo, &result, &length); + taosHashClear(pSup->pResultRowHashTable); + pInfo->binfo.resultRowInfo.size = 0; + pOperator->decodeResultRow(pOperator, pSup, &pInfo->binfo, result, length); + if(result){ + taosMemoryFree(result); + } } } +#endif closeAllResultRows(&pInfo->binfo.resultRowInfo); finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, @@ -6335,6 +6311,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf pOperator->info = pInfo; pOperator->getNextFn = doStateWindowAgg; pOperator->closeFn = destroyStateWindowOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -6374,6 +6352,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo pOperator->info = pInfo; pOperator->getNextFn = doSessionWindowAgg; pOperator->closeFn = destroySWindowOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; pOperator->pTaskInfo = pTaskInfo; code = appendDownstream(pOperator, &downstream, 1); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 3eb8ff1b72..1de33466e3 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -165,7 +165,7 @@ static int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) { // assign the group keys or user input constant values if required static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t totalRows, int32_t rowIndex) { for (int32_t i = 0; i < numOfOutput; ++i) { - if (pCtx[i].functionId == -1) { + if (pCtx[i].functionId == -1) { // select count(*),key from t group by key. SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[i]); SColumnInfoData* pColInfoData = pCtx[i].input.pData[0]; @@ -337,7 +337,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pOperator->name = "GroupbyAggOperator"; pOperator->blockingOptr = true; pOperator->status = OP_NOT_OPENED; - // pOperator->operatorType = OP_Groupby; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_GROUPBY; pOperator->pExpr = pExprInfo; pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; @@ -345,6 +345,8 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pOperator->_openFn = operatorDummyOpenFn; pOperator->getNextFn = hashGroupbyAggregate; pOperator->closeFn = destroyGroupOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; code = appendDownstream(pOperator, &downstream, 1); return pOperator; From 91f966155035d476370f7a27eee4285a5c3163d0 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 11 Apr 2022 17:29:14 +0800 Subject: [PATCH 29/39] bug fix for bitmap compress --- source/dnode/vnode/src/tsdb/tsdbCommit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 67c7973206..eb32663387 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -1298,7 +1298,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF int32_t tBitmaps = 0; int32_t tBitmapsLen = 0; if ((ncol != 0) && !TD_COL_ROWS_NORM(pBlockCol)) { - tBitmaps = sBitmaps; + tBitmaps = isSuper ? sBitmaps : nBitmaps; } #endif From 78fd2d3a3eabeb6d608c217bb96d04bb18776021 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 11 Apr 2022 17:30:27 +0800 Subject: [PATCH 30/39] feat: optimize encode/decode resultRow --- source/libs/executor/src/executorimpl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 8addd53479..eff5555dd2 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -4974,6 +4974,7 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order); doAggregateImpl(pOperator, 0, pInfo->pCtx); +#if 0 // test for encode/decode result info if(pOperator->encodeResultRow){ char *result = NULL; int32_t length = 0; @@ -4986,7 +4987,7 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { taosMemoryFree(result); } } - +#endif } finalizeQueryResult(pInfo->pCtx, pOperator->numOfOutput); @@ -5036,10 +5037,10 @@ void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasi void* pIter = taosHashIterate(pSup->pResultRowHashTable, NULL); while (pIter) { void* key = taosHashGetKey(pIter, &keyLen); - SResultRowPosition** p1 = (SResultRowPosition**)pIter; + SResultRowPosition* p1 = (SResultRowPosition*)pIter; - pPage = (SFilePage*) getBufPage(pSup->pResultBuf, (*p1)->pageId); - pRow = (SResultRow*)((char*)pPage + (*p1)->offset); + pPage = (SFilePage*) getBufPage(pSup->pResultBuf, p1->pageId); + pRow = (SResultRow*)((char*)pPage + p1->offset); setBufPageDirty(pPage, true); releaseBufPage(pSup->pResultBuf, pPage); @@ -5346,7 +5347,7 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0); -#if 0 +#if 0 // test for encode/decode result info if(pOperator->encodeResultRow){ char *result = NULL; int32_t length = 0; From 45b766cd358f0eaeb7df335e6adbcebf507bbee8 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 11 Apr 2022 17:35:17 +0800 Subject: [PATCH 31/39] feat: optimize encode/decode resultRow --- include/libs/nodes/nodes.h | 3 +-- source/libs/executor/src/groupoperator.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 68056eff47..c91779ba8b 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -184,8 +184,7 @@ typedef enum ENodeType { QUERY_NODE_PHYSICAL_PLAN_DISPATCH, QUERY_NODE_PHYSICAL_PLAN_INSERT, QUERY_NODE_PHYSICAL_SUBPLAN, - QUERY_NODE_PHYSICAL_PLAN, - QUERY_NODE_PHYSICAL_PLAN_GROUPBY + QUERY_NODE_PHYSICAL_PLAN } ENodeType; /** diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 1de33466e3..8d780fc70c 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -337,7 +337,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pOperator->name = "GroupbyAggOperator"; pOperator->blockingOptr = true; pOperator->status = OP_NOT_OPENED; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_GROUPBY; + // pOperator->operatorType = OP_Groupby; pOperator->pExpr = pExprInfo; pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; From 2624fa2711ea5a73c20c07975516497576dbdc3b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 17:36:10 +0800 Subject: [PATCH 32/39] fix[query]: invalid write. --- source/libs/scalar/src/sclvector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index ff677d2f7b..05456790a5 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -189,10 +189,10 @@ static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIn taosMemoryFree(t); } -//TODO opt performance +//TODO opt performance, tmp is not needed. int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { int32_t bufSize = pIn->columnData->info.bytes; - char *tmp = taosMemoryMalloc(bufSize); + char *tmp = taosMemoryMalloc(bufSize + VARSTR_HEADER_SIZE); bool vton = false; From 983e4aa010b1bc481d75b52771c28890f3eca56e Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Mon, 11 Apr 2022 17:42:05 +0800 Subject: [PATCH 33/39] set datablock desc timestamp precision --- include/libs/nodes/querynodes.h | 1 + source/libs/function/inc/builtins.h | 20 +++++++------ source/libs/nodes/src/nodesTraverseFuncs.c | 27 +++++++++++++---- source/libs/parser/src/parAstCreater.c | 35 +++++----------------- source/libs/planner/src/planLogicCreater.c | 12 ++++++++ source/libs/planner/src/planPhysiCreater.c | 1 + 6 files changed, 53 insertions(+), 43 deletions(-) diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index f052c9daa7..3e78da63de 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -190,6 +190,7 @@ typedef struct SLimitNode { typedef struct SStateWindowNode { ENodeType type; // QUERY_NODE_STATE_WINDOW + SNode* pCol; // timestamp primary key SNode* pExpr; } SStateWindowNode; diff --git a/source/libs/function/inc/builtins.h b/source/libs/function/inc/builtins.h index 2c0148e04f..f0349c55b9 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -26,15 +26,17 @@ extern "C" { #define FUNC_MGT_FUNC_CLASSIFICATION_MASK(n) (1 << n) -#define FUNC_MGT_AGG_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(0) -#define FUNC_MGT_SCALAR_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(1) -#define FUNC_MGT_NONSTANDARD_SQL_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(2) -#define FUNC_MGT_STRING_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(3) -#define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4) -#define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5) -#define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6) -#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7) -#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8) +#define FUNC_MGT_AGG_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(0) +#define FUNC_MGT_SCALAR_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(1) +#define FUNC_MGT_NONSTANDARD_SQL_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(2) +#define FUNC_MGT_STRING_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(3) +#define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4) +#define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5) +#define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6) +#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7) +#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8) +#define FUNC_MGT_SPECIAL_DATA_REQUIRED FUNC_MGT_FUNC_CLASSIFICATION_MASK(9) +#define FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED FUNC_MGT_FUNC_CLASSIFICATION_MASK(10) #define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index 3c10287992..4a782cce08 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -77,9 +77,14 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker case QUERY_NODE_ORDER_BY_EXPR: res = walkNode(((SOrderByExprNode*)pNode)->pExpr, order, walker, pContext); break; - case QUERY_NODE_STATE_WINDOW: - res = walkNode(((SStateWindowNode*)pNode)->pExpr, order, walker, pContext); + case QUERY_NODE_STATE_WINDOW: { + SStateWindowNode* pState = (SStateWindowNode*)pNode; + res = walkNode(pState->pExpr, order, walker, pContext); + if (DEAL_RES_ERROR != res) { + res = walkNode(pState->pCol, order, walker, pContext); + } break; + } case QUERY_NODE_SESSION_WINDOW: { SSessionWindowNode* pSession = (SSessionWindowNode*)pNode; res = walkNode(pSession->pCol, order, walker, pContext); @@ -211,12 +216,22 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit case QUERY_NODE_ORDER_BY_EXPR: res = rewriteNode(&(((SOrderByExprNode*)pNode)->pExpr), order, rewriter, pContext); break; - case QUERY_NODE_STATE_WINDOW: - res = rewriteNode(&(((SStateWindowNode*)pNode)->pExpr), order, rewriter, pContext); + case QUERY_NODE_STATE_WINDOW: { + SStateWindowNode* pState = (SStateWindowNode*)pNode; + res = rewriteNode(&pState->pExpr, order, rewriter, pContext); + if (DEAL_RES_ERROR != res) { + res = rewriteNode(&pState->pCol, order, rewriter, pContext); + } break; - case QUERY_NODE_SESSION_WINDOW: - res = rewriteNode(&(((SSessionWindowNode*)pNode)->pCol), order, rewriter, pContext); + } + case QUERY_NODE_SESSION_WINDOW: { + SSessionWindowNode* pSession = (SSessionWindowNode*)pNode; + res = rewriteNode(&pSession->pCol, order, rewriter, pContext); + if (DEAL_RES_ERROR != res) { + res = rewriteNode(&pSession->pGap, order, rewriter, pContext); + } break; + } case QUERY_NODE_INTERVAL_WINDOW: { SIntervalWindowNode* pInterval = (SIntervalWindowNode*)pNode; res = rewriteNode(&(pInterval->pInterval), order, rewriter, pContext); diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4908748f0d..01531f89ab 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -456,6 +456,13 @@ SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) { SStateWindowNode* state = (SStateWindowNode*)nodesMakeNode(QUERY_NODE_STATE_WINDOW); CHECK_OUT_OF_MEM(state); + state->pCol = nodesMakeNode(QUERY_NODE_COLUMN); + if (NULL == state->pCol) { + nodesDestroyNode(state); + CHECK_OUT_OF_MEM(state->pCol); + } + ((SColumnNode*)state->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID; + strcpy(((SColumnNode*)state->pCol)->colName, PK_TS_COL_INTERNAL_NAME); state->pExpr = pExpr; return (SNode*)state; } @@ -584,34 +591,6 @@ SNode* createDatabaseOptions(SAstCreateContext* pCxt) { return (SNode*)pOptions; } -static bool checkAndSetKeepOption(SAstCreateContext* pCxt, SNodeList* pKeep, int32_t* pKeep0, int32_t* pKeep1, int32_t* pKeep2) { - int32_t numOfKeep = LIST_LENGTH(pKeep); - if (numOfKeep > 3 || numOfKeep < 1) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid number of keep options"); - return false; - } - - int32_t daysToKeep0 = strtol(((SValueNode*)nodesListGetNode(pKeep, 0))->literal, NULL, 10); - int32_t daysToKeep1 = numOfKeep > 1 ? strtol(((SValueNode*)nodesListGetNode(pKeep, 1))->literal, NULL, 10) : daysToKeep0; - int32_t daysToKeep2 = numOfKeep > 2 ? strtol(((SValueNode*)nodesListGetNode(pKeep, 2))->literal, NULL, 10) : daysToKeep1; - if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP || - daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, - "invalid option keep: %d, %d, %d valid range: [%d, %d]", daysToKeep0, daysToKeep1, daysToKeep2, TSDB_MIN_KEEP, TSDB_MAX_KEEP); - return false; - } - - if (!((daysToKeep0 <= daysToKeep1) && (daysToKeep1 <= daysToKeep2))) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid keep value, should be keep0 <= keep1 <= keep2"); - return false; - } - - *pKeep0 = daysToKeep0; - *pKeep1 = daysToKeep1; - *pKeep2 = daysToKeep2; - return true; -} - SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { switch (pAlterOption->type) { case DB_OPTION_BLOCKS: diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 596bb64bac..bd5ce0f494 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -488,6 +488,12 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo pWindow->winType = WINDOW_TYPE_STATE; pWindow->pStateExpr = nodesCloneNode(pState->pExpr); + pWindow->pTspk = nodesCloneNode(pState->pCol); + if (NULL == pWindow->pTspk) { + nodesDestroyNode(pWindow); + return TSDB_CODE_OUT_OF_MEMORY; + } + return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } @@ -500,6 +506,12 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW pWindow->winType = WINDOW_TYPE_SESSION; pWindow->sessionGap = ((SValueNode*)pSession->pGap)->datum.i; + pWindow->pTspk = nodesCloneNode(pSession->pCol); + if (NULL == pWindow->pTspk) { + nodesDestroyNode(pWindow); + return TSDB_CODE_OUT_OF_MEMORY; + } + return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 3b255bf276..f34452f84a 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -1238,6 +1238,7 @@ static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) { SExplainStmt* pStmt = (SExplainStmt*)pCxt->pAstRoot; pPlan->explainInfo.mode = pStmt->analyze ? EXPLAIN_MODE_ANALYZE : EXPLAIN_MODE_STATIC; pPlan->explainInfo.verbose = pStmt->pOptions->verbose; + pPlan->explainInfo.ratio = pStmt->pOptions->ratio; } else { pPlan->explainInfo.mode = EXPLAIN_MODE_DISABLE; } From bc4e73a3ddc3b1f6eff98b3dbe225bdd8a063a0a Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 11 Apr 2022 17:55:53 +0800 Subject: [PATCH 34/39] feat: optimize encode/decode resultRow --- source/libs/executor/src/executorimpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index eff5555dd2..63cd6b77b4 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -5360,8 +5360,8 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { taosMemoryFree(result); } } - } #endif + } closeAllResultRows(&pInfo->binfo.resultRowInfo); finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, From 8c27b944bac52f3356a80f991c43e5e8e40b9527 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 18:54:31 +0800 Subject: [PATCH 35/39] fix[query]: disable the auto convert of ucs4 for taos_fetch_raw_block api. --- source/client/inc/clientInt.h | 4 +- source/client/src/clientImpl.c | 81 +++++++++++++++------------- source/client/src/clientMain.c | 6 +-- source/client/src/clientMsgHandler.c | 4 +- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index ae1b34a3bd..562a1ce696 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -238,9 +238,9 @@ void initMsgHandleFp(); TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, uint16_t port); -void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr); +void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); -int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows); +int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, bool convertUcs4); int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 9938a2e1b9..2949d6eda6 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -13,7 +13,7 @@ static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet); static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest); static void destroySendMsgInfo(SMsgSendInfo* pMsgBody); -static int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp); +static int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4); static bool stringLengthCheck(const char* str, size_t maxsize) { if (str == NULL) { @@ -176,7 +176,7 @@ int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { SRetrieveTableRsp* pRsp = NULL; int32_t code = qExecCommand(pQuery->pRoot, &pRsp); if (TSDB_CODE_SUCCESS == code && NULL != pRsp) { - code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp); + code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false); } return code; } @@ -616,7 +616,7 @@ static void doSetOneRowPtr(SReqResultInfo* pResultInfo) { } } -void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) { +void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) { assert(pRequest != NULL); SReqResultInfo* pResultInfo = &pRequest->body.resInfo; @@ -637,7 +637,7 @@ void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) { return NULL; } - pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData); + pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData, convertUcs4); if (pRequest->code != TSDB_CODE_SUCCESS) { pResultInfo->numOfRows = 0; return NULL; @@ -735,7 +735,42 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { return TSDB_CODE_SUCCESS; } -int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) { +static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int32_t numOfCols, int32_t* colLength) { + for (int32_t i = 0; i < numOfCols; ++i) { + int32_t type = pResultInfo->fields[i].type; + int32_t bytes = pResultInfo->fields[i].bytes; + + if (type == TSDB_DATA_TYPE_NCHAR) { + char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pResultInfo->convertBuf[i] = p; + + SResultColumn* pCol = &pResultInfo->pCol[i]; + for (int32_t j = 0; j < numOfRows; ++j) { + if (pCol->offset[j] != -1) { + char* pStart = pCol->offset[j] + pCol->pData; + + int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p)); + ASSERT(len <= bytes); + + varDataSetLen(p, len); + pCol->offset[j] = (p - pResultInfo->convertBuf[i]); + p += (len + VARSTR_HEADER_SIZE); + } + } + + pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; + pResultInfo->row[i] = pResultInfo->pCol[i].pData; + } + } + + return TSDB_CODE_SUCCESS; +} + +int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, bool convertUcs4) { assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL); if (numOfRows == 0) { return TSDB_CODE_SUCCESS; @@ -767,37 +802,11 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 } // convert UCS4-LE encoded character to native multi-bytes character in current data block. - for (int32_t i = 0; i < numOfCols; ++i) { - int32_t type = pResultInfo->fields[i].type; - int32_t bytes = pResultInfo->fields[i].bytes; - - if (type == TSDB_DATA_TYPE_NCHAR) { - char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); - if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pResultInfo->convertBuf[i] = p; - - SResultColumn* pCol = &pResultInfo->pCol[i]; - for (int32_t j = 0; j < numOfRows; ++j) { - if (pCol->offset[j] != -1) { - pStart = pCol->offset[j] + pCol->pData; - - int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p)); - ASSERT(len <= bytes); - - varDataSetLen(p, len); - pCol->offset[j] = (p - pResultInfo->convertBuf[i]); - p += (len + VARSTR_HEADER_SIZE); - } - } - - pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; - pResultInfo->row[i] = pResultInfo->pCol[i].pData; - } + if (convertUcs4) { + code = doConvertUCS4(pResultInfo, numOfRows, numOfCols, colLength); } - return TSDB_CODE_SUCCESS; + return code; } char* getDbOfConnection(STscObj* pObj) { @@ -829,7 +838,7 @@ void resetConnectDB(STscObj* pTscObj) { taosThreadMutexUnlock(&pTscObj->mutex); } -int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) { +int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4) { assert(pResultInfo != NULL && pRsp != NULL); pResultInfo->pRspMsg = (const char*)pRsp; @@ -842,5 +851,5 @@ int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableR // TODO handle the compressed case pResultInfo->totalRows += pResultInfo->numOfRows; - return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows); + return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows, convertUcs4); } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index e10cf5179e..51629510d0 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -168,7 +168,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return NULL; } - return doFetchRow(pRequest, true); + return doFetchRow(pRequest, true, true); } int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) { @@ -404,7 +404,7 @@ int taos_fetch_block_s(TAOS_RES *res, int* numOfRows, TAOS_ROW *rows) { return 0; } - doFetchRow(pRequest, false); + doFetchRow(pRequest, false, true); // TODO refactor SReqResultInfo *pResultInfo = &pRequest->body.resInfo; @@ -426,7 +426,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int* numOfRows, void** pData) { return 0; } - doFetchRow(pRequest, false); + doFetchRow(pRequest, false, false); SReqResultInfo *pResultInfo = &pRequest->body.resInfo; diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 4314391743..99c6e81551 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -191,7 +191,7 @@ int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) pResInfo->completed = pRetrieve->completed; pResInfo->current = 0; - setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); +// setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows, pRetrieve->completed, pRequest->body.showInfo.execId); @@ -225,7 +225,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { pResInfo->pData = pFetchRsp->data; pResInfo->current = 0; - setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); +// setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pFetchRsp->numOfRows, pFetchRsp->completed, pRequest->body.showInfo.execId); From c11946fd7509cf9759afed186a02194084279bb6 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Mon, 11 Apr 2022 18:55:43 +0800 Subject: [PATCH 36/39] [TD-13756]: Fix macro name error. --- include/os/osFile.h | 2 +- source/common/src/ttszip.c | 2 +- source/dnode/mgmt/dm/dmFile.c | 2 +- source/dnode/mgmt/main/dndFile.c | 6 +++--- source/dnode/mgmt/mm/mmFile.c | 2 +- source/dnode/mgmt/vm/vmFile.c | 2 +- source/dnode/mnode/impl/test/trans/trans.cpp | 2 +- source/dnode/mnode/sdb/src/sdbFile.c | 2 +- source/dnode/vnode/src/tq/tqMetaStore.c | 4 ++-- source/dnode/vnode/src/tsdb/tsdbFS.c | 2 +- source/dnode/vnode/src/tsdb/tsdbFile.c | 4 ++-- source/libs/index/src/indexFstCountingWriter.c | 2 +- source/libs/sync/src/syncRaftStore.c | 2 +- source/libs/tdb/src/inc/tdbOs.h | 2 +- source/libs/tfs/test/tfsTest.cpp | 4 ++-- source/libs/transport/test/pushServer.c | 2 +- source/libs/transport/test/rserver.c | 2 +- source/libs/wal/src/walMeta.c | 2 +- source/libs/wal/src/walSeek.c | 8 ++++---- source/libs/wal/src/walWrite.c | 4 ++-- source/os/src/osFile.c | 4 ++-- source/util/src/tlog.c | 6 +++--- source/util/src/tpagedbuf.c | 2 +- tests/test/c/tmqDemo.c | 2 +- tests/tsim/src/simExe.c | 4 ++-- tools/shell/src/backup/shellCheck.c | 2 +- tools/shell/src/shellEngine.c | 4 ++-- 27 files changed, 41 insertions(+), 41 deletions(-) diff --git a/include/os/osFile.h b/include/os/osFile.h index 143b4bf2f8..89b58cdd65 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -44,7 +44,7 @@ extern "C" { typedef struct TdFile *TdFilePtr; -#define TD_FILE_CTEATE 0x0001 +#define TD_FILE_CREATE 0x0001 #define TD_FILE_WRITE 0x0002 #define TD_FILE_READ 0x0004 #define TD_FILE_TRUNC 0x0008 diff --git a/source/common/src/ttszip.c b/source/common/src/ttszip.c index 15e741d307..3160d64c12 100644 --- a/source/common/src/ttszip.c +++ b/source/common/src/ttszip.c @@ -39,7 +39,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { taosGetTmpfilePath(tsTempDir, "join", pTSBuf->path); // pTSBuf->pFile = fopen(pTSBuf->path, "wb+"); - pTSBuf->pFile = taosOpenFile(pTSBuf->path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC); + pTSBuf->pFile = taosOpenFile(pTSBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC); if (pTSBuf->pFile == NULL) { taosMemoryFree(pTSBuf); return NULL; diff --git a/source/dnode/mgmt/dm/dmFile.c b/source/dnode/mgmt/dm/dmFile.c index 1ac86870e3..c1964ac8c4 100644 --- a/source/dnode/mgmt/dm/dmFile.c +++ b/source/dnode/mgmt/dm/dmFile.c @@ -162,7 +162,7 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { char file[PATH_MAX]; snprintf(file, sizeof(file), "%s%sdnode.json.bak", pMgmt->path, TD_DIRSEP); - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { dError("failed to write %s since %s", file, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); diff --git a/source/dnode/mgmt/main/dndFile.c b/source/dnode/mgmt/main/dndFile.c index d4d2a3e6ea..905624f072 100644 --- a/source/dnode/mgmt/main/dndFile.c +++ b/source/dnode/mgmt/main/dndFile.c @@ -75,7 +75,7 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); - pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to write %s since %s", file, terrstr()); @@ -121,7 +121,7 @@ TdFilePtr dndCheckRunning(const char *dataDir) { char filepath[PATH_MAX] = {0}; snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP); - TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to lock file:%s since %s", filepath, terrstr()); @@ -218,7 +218,7 @@ int32_t dndWriteShmFile(SDnode *pDnode) { snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP); snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); - pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to open file:%s since %s", file, terrstr()); diff --git a/source/dnode/mgmt/mm/mmFile.c b/source/dnode/mgmt/mm/mmFile.c index 57e1c0cb92..44027780de 100644 --- a/source/dnode/mgmt/mm/mmFile.c +++ b/source/dnode/mgmt/mm/mmFile.c @@ -109,7 +109,7 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { char file[PATH_MAX]; snprintf(file, sizeof(file), "%s%smnode.json.bak", pMgmt->path, TD_DIRSEP); - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to write %s since %s", file, terrstr()); diff --git a/source/dnode/mgmt/vm/vmFile.c b/source/dnode/mgmt/vm/vmFile.c index ba59482c1a..7e00a022b2 100644 --- a/source/dnode/mgmt/vm/vmFile.c +++ b/source/dnode/mgmt/vm/vmFile.c @@ -154,7 +154,7 @@ int32_t vmWriteVnodesToFile(SVnodesMgmt *pMgmt) { snprintf(file, sizeof(file), "%s%svnodes.json.bak", pMgmt->path, TD_DIRSEP); snprintf(realfile, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP); - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to write %s since %s", file, terrstr()); diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 40b052400b..560b30d13c 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -38,7 +38,7 @@ class MndTestTrans : public ::testing::Test { test.ServerStop(); - pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); int32_t writeLen = taosWriteFile(pFile, buffer, readLen); if (writeLen < 0 || writeLen == readLen) { ASSERT(1); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index c11025beed..f61899766e 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -232,7 +232,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) { mDebug("start to write file:%s, current ver:%" PRId64 ", commit ver:%" PRId64, curfile, pSdb->curVer, pSdb->lastCommitVer); - TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to open file:%s for write since %s", tmpfile, terrstr()); diff --git a/source/dnode/vnode/src/tq/tqMetaStore.c b/source/dnode/vnode/src/tq/tqMetaStore.c index beb19f48f1..84f12f93c6 100644 --- a/source/dnode/vnode/src/tq/tqMetaStore.c +++ b/source/dnode/vnode/src/tq/tqMetaStore.c @@ -95,7 +95,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F tqError("failed to create dir:%s since %s ", name, terrstr()); } strcat(name, "/" TQ_IDX_NAME); - TdFilePtr pIdxFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ); + TdFilePtr pIdxFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ); if (pIdxFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); tqError("failed to open file:%s since %s ", name, terrstr()); @@ -113,7 +113,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F strcpy(name, path); strcat(name, "/" TQ_META_NAME); - TdFilePtr pFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ); + TdFilePtr pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); tqError("failed to open file:%s since %s", name, terrstr()); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 1f42e90616..eff350ddda 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -416,7 +416,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) { tsdbGetTxnFname(pRepo, TSDB_TXN_TEMP_FILE, tfname); tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, cfname); - TdFilePtr pFile = taosOpenFile(tfname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(tfname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 6f96aff848..8e5a6afc4d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -360,7 +360,7 @@ static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) { int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType) { ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC); - pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pDFile->pFile == NULL) { if (errno == ENOENT) { // Try to create directory recursively @@ -371,7 +371,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T } taosMemoryFreeClear(s); - pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pDFile->pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; diff --git a/source/libs/index/src/indexFstCountingWriter.c b/source/libs/index/src/indexFstCountingWriter.c index 76ff4309b5..1d4395aff6 100644 --- a/source/libs/index/src/indexFstCountingWriter.c +++ b/source/libs/index/src/indexFstCountingWriter.c @@ -92,7 +92,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int ctx->file.readOnly = readOnly; if (readOnly == false) { // ctx->file.pFile = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO); - ctx->file.pFile = taosOpenFile(path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + ctx->file.pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); taosFtruncateFile(ctx->file.pFile, 0); int64_t file_size; taosStatFile(path, &file_size, NULL); diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index c9054d088e..d6f2e91de7 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -57,7 +57,7 @@ SRaftStore *raftStoreOpen(const char *path) { static int32_t raftStoreInit(SRaftStore *pRaftStore) { assert(pRaftStore != NULL); - pRaftStore->pFile = taosOpenFile(pRaftStore->path, TD_FILE_CTEATE | TD_FILE_WRITE); + pRaftStore->pFile = taosOpenFile(pRaftStore->path, TD_FILE_CREATE | TD_FILE_WRITE); assert(pRaftStore->pFile != NULL); pRaftStore->currentTerm = 0; diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index 1d87285091..503e109adb 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -37,7 +37,7 @@ extern "C" { /* file */ typedef TdFilePtr tdb_fd_t; -#define TDB_O_CREAT TD_FILE_CTEATE +#define TDB_O_CREAT TD_FILE_CREATE #define TDB_O_WRITE TD_FILE_WRITE #define TDB_O_READ TD_FILE_READ #define TDB_O_TRUNC TD_FILE_TRUNC diff --git a/source/libs/tfs/test/tfsTest.cpp b/source/libs/tfs/test/tfsTest.cpp index 1a093c3877..58c3a83aff 100644 --- a/source/libs/tfs/test/tfsTest.cpp +++ b/source/libs/tfs/test/tfsTest.cpp @@ -231,7 +231,7 @@ TEST_F(TfsTest, 04_File) { EXPECT_EQ(tfsMkdir(pTfs, "t3"), 0); // FILE *fp = fopen(f1.aname, "w"); - TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); ASSERT_NE(pFile, nullptr); taosWriteFile(pFile, "12345678", 5); taosCloseFile(&pFile); @@ -640,7 +640,7 @@ TEST_F(TfsTest, 05_MultiDisk) { EXPECT_EQ(tfsMkdir(pTfs, "t3"), 0); // FILE *fp = fopen(f1.aname, "w"); - TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); ASSERT_NE(pFile, nullptr); taosWriteFile(pFile, "12345678", 5); taosCloseFile(&pFile); diff --git a/source/libs/transport/test/pushServer.c b/source/libs/transport/test/pushServer.c index f4ad73f743..3099998f57 100644 --- a/source/libs/transport/test/pushServer.c +++ b/source/libs/transport/test/pushServer.c @@ -181,7 +181,7 @@ int main(int argc, char *argv[]) { tInfo("RPC server is running, ctrl-c to exit"); if (commit) { - pDataFile = taosOpenFile(dataName, TD_FILE_APPEND | TD_FILE_CTEATE | TD_FILE_WRITE); + pDataFile = taosOpenFile(dataName, TD_FILE_APPEND | TD_FILE_CREATE | TD_FILE_WRITE); if (pDataFile == NULL) tInfo("failed to open data file, reason:%s", strerror(errno)); } qhandle = taosOpenQueue(); diff --git a/source/libs/transport/test/rserver.c b/source/libs/transport/test/rserver.c index 8ed3bbc960..14d109dc5a 100644 --- a/source/libs/transport/test/rserver.c +++ b/source/libs/transport/test/rserver.c @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) { tInfo("RPC server is running, ctrl-c to exit"); if (commit) { - pDataFile = taosOpenFile(dataName, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pDataFile = taosOpenFile(dataName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pDataFile == NULL) tInfo("failed to open data file, reason:%s", strerror(errno)); } qhandle = taosOpenQueue(); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 36323cdffa..9f8fe8d84d 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -360,7 +360,7 @@ int walSaveMeta(SWal* pWal) { int metaVer = walFindCurMetaVer(pWal); char fnameStr[WAL_FILE_LEN]; walBuildMetaName(pWal, metaVer + 1, fnameStr); - TdFilePtr pMataFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE); + TdFilePtr pMataFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE); if (pMataFile == NULL) { return -1; } diff --git a/source/libs/wal/src/walSeek.c b/source/libs/wal/src/walSeek.c index 413dcb47f0..a6f238af6b 100644 --- a/source/libs/wal/src/walSeek.c +++ b/source/libs/wal/src/walSeek.c @@ -56,13 +56,13 @@ int walSetWrite(SWal* pWal) { char fnameStr[WAL_FILE_LEN]; walBuildIdxName(pWal, fileFirstVer, fnameStr); - pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } walBuildLogName(pWal, fileFirstVer, fnameStr); - pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -102,14 +102,14 @@ int walChangeWrite(SWal* pWal, int64_t ver) { int64_t fileFirstVer = pFileInfo->firstVer; walBuildIdxName(pWal, fileFirstVer, fnameStr); - pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); pWal->pWriteIdxTFile = NULL; return -1; } walBuildLogName(pWal, fileFirstVer, fnameStr); - pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { taosCloseFile(&pIdxTFile); terrno = TAOS_SYSTEM_ERROR(errno); diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index a578c6f368..81f2d82ea5 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -216,13 +216,13 @@ int walRoll(SWal *pWal) { int64_t newFileFirstVersion = pWal->vers.lastVer + 1; char fnameStr[WAL_FILE_LEN]; walBuildIdxName(pWal, newFileFirstVersion, fnameStr); - pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } walBuildLogName(pWal, newFileFirstVersion, fnameStr); - pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index a7855539a4..4bd6b9e5cd 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -129,7 +129,7 @@ int64_t taosCopyFile(const char *from, const char *to) { if (pFileFrom == NULL) goto _err; // fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755); - TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_EXCL); + TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL); if (pFileTo == NULL) goto _err; while (true) { @@ -246,7 +246,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { } } else { int access = O_BINARY; - access |= (tdFileOptions & TD_FILE_CTEATE) ? O_CREAT : 0; + access |= (tdFileOptions & TD_FILE_CREATE) ? O_CREAT : 0; if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) { access |= O_RDWR; } else if (tdFileOptions & TD_FILE_WRITE) { diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 46e2d567ce..b37b1b2f69 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -199,7 +199,7 @@ static void *taosThreadToOpenNewFile(void *param) { taosUmaskFile(0); - TdFilePtr pFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { tsLogObj.openInProgress = 0; tsLogObj.lines = tsLogObj.maxLines - 1000; @@ -348,7 +348,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { taosThreadMutexInit(&tsLogObj.logMutex, NULL); taosUmaskFile(0); - tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CTEATE | TD_FILE_WRITE); + tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE); if (tsLogObj.logHandle->pFile == NULL) { printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno)); @@ -699,7 +699,7 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { goto cmp_end; } - TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { ret = -2; goto cmp_end; diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 48cf97a11f..1ad12ef43a 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -48,7 +48,7 @@ struct SDiskbasedBuf { }; static int32_t createDiskFile(SDiskbasedBuf* pBuf) { - pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL); + pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL); if (pBuf->pFile == NULL) { return TAOS_SYSTEM_ERROR(errno); } diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index d339166d74..45a9d31f4c 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -588,7 +588,7 @@ int32_t syncWriteDataByRatio() { void printParaIntoFile() { // FILE *fp = fopen(g_stConfInfo.resultFileName, "a"); - TdFilePtr pFile = taosOpenFile(g_stConfInfo.resultFileName, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_STREAM); + TdFilePtr pFile = taosOpenFile(g_stConfInfo.resultFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_STREAM); if (NULL == pFile) { fprintf(stderr, "Failed to open %s for save result\n", g_stConfInfo.resultFileName); exit -1; diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 9a0b48197a..8ef5c816c8 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -22,7 +22,7 @@ void simLogSql(char *sql, bool useSharp) { sprintf(filename, "%s/sim.sql", simScriptDir); if (pFile == NULL) { // fp = fopen(filename, "w"); - pFile = taosOpenFile(filename, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { fprintf(stderr, "ERROR: failed to open file: %s\n", filename); return; @@ -773,7 +773,7 @@ bool simExecuteRestfulCmd(SScript *script, char *rest) { char filename[256]; sprintf(filename, "%s/tmp.sql", simScriptDir); // fp = fopen(filename, "w"); - pFile = taosOpenFile(filename, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { fprintf(stderr, "ERROR: failed to open file: %s\n", filename); return false; diff --git a/tools/shell/src/backup/shellCheck.c b/tools/shell/src/backup/shellCheck.c index dc18ecd3f8..d1f0683fea 100644 --- a/tools/shell/src/backup/shellCheck.c +++ b/tools/shell/src/backup/shellCheck.c @@ -116,7 +116,7 @@ static void *shellCheckThreadFp(void *arg) { char file[32] = {0}; snprintf(file, 32, "tb%d.txt", pThread->threadIndex); - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (!fp) { fprintf(stdout, "failed to open %s, reason:%s", file, strerror(errno)); return NULL; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 47d47f023d..0e611f3794 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -518,7 +518,7 @@ static int dumpResultToFile(const char *fname, TAOS_RES *tres) { } // FILE *fp = fopen(full_path.we_wordv[0], "w"); - TdFilePtr pFile = taosOpenFile(full_path.we_wordv[0], TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + TdFilePtr pFile = taosOpenFile(full_path.we_wordv[0], TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { fprintf(stderr, "ERROR: failed to open file: %s\n", full_path.we_wordv[0]); wordfree(&full_path); @@ -935,7 +935,7 @@ void write_history() { get_history_path(f_history); // FILE *f = fopen(f_history, "w"); - TdFilePtr pFile = taosOpenFile(f_history, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + TdFilePtr pFile = taosOpenFile(f_history, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { #ifndef WINDOWS fprintf(stderr, "Failed to open file %s for write, reason:%s\n", f_history, strerror(errno)); From 74e5ebc322340ce94cc39555ed6239e13fa39ca3 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 19:50:34 +0800 Subject: [PATCH 37/39] fix[query]: enable min/max function to be applied to bool data type. --- source/libs/function/src/builtinsimpl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 53b15a82af..133e8f9c93 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -212,6 +212,9 @@ bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { case TSDB_DATA_TYPE_UTINYINT: *((uint8_t *)buf) = 0; break; + case TSDB_DATA_TYPE_BOOL: + *((int8_t*)buf) = 0; + break; default: assert(0); } @@ -255,6 +258,9 @@ bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { case TSDB_DATA_TYPE_DOUBLE: SET_DOUBLE_VAL(((double *)buf), DBL_MAX); break; + case TSDB_DATA_TYPE_BOOL: + *((int8_t*)buf) = 1; + break; default: assert(0); } @@ -385,8 +391,8 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; - if (IS_SIGNED_NUMERIC_TYPE(type)) { - if (type == TSDB_DATA_TYPE_TINYINT) { + if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { + if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) { LOOPCHECK_N(*(int8_t*)buf, pCol, pCtx, int8_t, numOfRows, start, isMinFunc, numOfElems); } else if (type == TSDB_DATA_TYPE_SMALLINT) { LOOPCHECK_N(*(int16_t*) buf, pCol, pCtx, int16_t, numOfRows, start, isMinFunc, numOfElems); From 4990fd51ab84fc7e9082d94910973b2df20c79aa Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 11 Apr 2022 20:54:27 +0800 Subject: [PATCH 38/39] fix rpc problem --- source/libs/transport/src/transCli.c | 34 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d456cb23a4..c655c0bfc9 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -129,6 +129,12 @@ static void transDestroyConnCtx(STransConnCtx* ctx); static SCliThrdObj* createThrdObj(); static void destroyThrdObj(SCliThrdObj* pThrd); +// snprintf may cause performance problem +#define CONN_CONSTRUCT_HASH_KEY(key, ip, port) \ + do { \ + snprintf(key, sizeof(key), "%s:%d", ip, (int)port); \ + } while (0) + #define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1) #define CONN_PERSIST_TIME(para) (para * 1000 * 10) #define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL) @@ -206,8 +212,10 @@ static void destroyThrdObj(SCliThrdObj* pThrd); } \ } while (0) -#define CONN_NO_PERSIST_BY_APP(conn) (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) -#define CONN_RELEASE_BY_SERVER(conn) (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) +#define CONN_NO_PERSIST_BY_APP(conn) \ + (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) +#define CONN_RELEASE_BY_SERVER(conn) \ + (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) #define REQUEST_NO_RESP(msg) ((msg)->noResp == 1) #define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1) @@ -282,8 +290,9 @@ void cliHandleResp(SCliConn* conn) { tDebug("%s cli conn %p ref by app", CONN_GET_INST_LABEL(conn), conn); } - tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn, TMSG_INFO(pHead->msgType), - taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), taosInetNtoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), transMsg.contLen); + tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn, + TMSG_INFO(pHead->msgType), taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), + taosInetNtoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), transMsg.contLen); conn->secured = pHead->secured; @@ -349,10 +358,12 @@ void cliHandleExcept(SCliConn* pConn) { if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { transMsg.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType); - tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle, TMSG_INFO(transMsg.msgType)); + tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle, + TMSG_INFO(transMsg.msgType)); if (transMsg.ahandle == NULL) { transMsg.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, (int32_t*)&(transMsg.msgType)); - tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle); + tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, + transMsg.ahandle); } } else { transMsg.ahandle = pCtx ? pCtx->ahandle : NULL; @@ -423,8 +434,7 @@ void* destroyConnPool(void* pool) { static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) { char key[128] = {0}; - tstrncpy(key, ip, strlen(ip)); - tstrncpy(key + strlen(key), (char*)(&port), sizeof(port)); + CONN_CONSTRUCT_HASH_KEY(key, ip, port); SHashObj* pPool = pool; SConnList* plist = taosHashGet(pPool, key, strlen(key)); @@ -456,8 +466,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->status = ConnInPool; char key[128] = {0}; - tstrncpy(key, conn->ip, strlen(conn->ip)); - tstrncpy(key + strlen(key), (char*)(&conn->port), sizeof(conn->port)); + CONN_CONSTRUCT_HASH_KEY(key, conn->ip, conn->port); tTrace("cli conn %p added to conn pool, read buf cap: %d", conn, conn->readBuf.cap); SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key)); @@ -626,8 +635,9 @@ void cliSend(SCliConn* pConn) { pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); - tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pHead->msgType), - taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port)); + tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn, + TMSG_INFO(pHead->msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), + taosInetNtoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port)); if (pHead->persist == 1) { CONN_SET_PERSIST_BY_APP(pConn); From cf890f6e10de3ee7ad6c6950d63ff5d2c3f9426a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 23:05:39 +0800 Subject: [PATCH 39/39] fix[query]: fix null write error bug for varchar/nchar data type. --- source/libs/parser/src/parInsert.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 9d945039b8..435ab317e6 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -605,6 +605,12 @@ typedef struct SMemParam { static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) { SMemParam* pa = (SMemParam*)param; SRowBuilder* rb = pa->rb; + + if (value == NULL) { // it is a null data + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx); + return TSDB_CODE_SUCCESS; + } + if (TSDB_DATA_TYPE_BINARY == pa->schema->type) { const char* rowEnd = tdRowEnd(rb->pBuf); STR_WITH_SIZE_TO_VARSTR(rowEnd, value, len); @@ -621,14 +627,9 @@ static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, in varDataSetLen(rowEnd, output); tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx); } else { - if (value == NULL) { // it is a null data - tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, - pa->colIdx); - } else { - tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, - pa->colIdx); - } + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, pa->colIdx); } + return TSDB_CODE_SUCCESS; }