diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 77aac35f622bd0fd56126bcba8182ffd18b7e5d9..76edcf44c4e318efd3a53129d32fd961bc6e2e6d 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -179,6 +179,7 @@ static void destroyBasicOperatorInfo(void* param, int32_t numOfOutput); static void destroySFillOperatorInfo(void* param, int32_t numOfOutput); static void destroyGroupbyOperatorInfo(void* param, int32_t numOfOutput); static void destroyArithOperatorInfo(void* param, int32_t numOfOutput); +static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput); static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo* pGroupResInfo, int32_t orderType, SSDataBlock* pBlock); @@ -1665,20 +1666,25 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf *(int64_t*) pRuntimeEnv->prevRow[0] = INT64_MIN; } - qDebug("QInfo:%p init runtime completed", pRuntimeEnv->qinfo); + qDebug("QInfo:%p init runtime environment completed", pRuntimeEnv->qinfo); // group by normal column, sliding window query, interval query are handled by interval query processor // interval (down sampling operation) - if (QUERY_IS_INTERVAL_QUERY(pQuery)) { + if (onlyQueryTags(pQuery)) { // do nothing for tags query + + } else if (QUERY_IS_INTERVAL_QUERY(pQuery)) { if (pQuery->stableQuery) { - pRuntimeEnv->proot = createMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); + pRuntimeEnv->proot = createMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, + pQuery->pExpr1, pQuery->numOfOutput); setTableScanFilterOperatorInfo(pRuntimeEnv->pTableScanner->info, pRuntimeEnv->proot); } else { - pRuntimeEnv->proot = createTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); + pRuntimeEnv->proot = + createTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); setTableScanFilterOperatorInfo(pRuntimeEnv->pTableScanner->info, pRuntimeEnv->proot); if (pQuery->pExpr2 != NULL) { - pRuntimeEnv->proot = createArithOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQuery->pExpr2, pQuery->numOfExpr2); + pRuntimeEnv->proot = + createArithOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQuery->pExpr2, pQuery->numOfExpr2); } if (pQuery->fillType != TSDB_FILL_NONE && !isPointInterpoQuery(pQuery)) { @@ -1687,42 +1693,46 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf } } - } else if (pQuery->groupbyColumn) { - pRuntimeEnv->proot = createGroupbyOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); - setTableScanFilterOperatorInfo(pRuntimeEnv->pTableScanner->info, pRuntimeEnv->proot); + } else if (pQuery->groupbyColumn) { + pRuntimeEnv->proot = + createGroupbyOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); + setTableScanFilterOperatorInfo(pRuntimeEnv->pTableScanner->info, pRuntimeEnv->proot); - if (pQuery->pExpr2 != NULL) { - pRuntimeEnv->proot = createArithOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQuery->pExpr2, pQuery->numOfExpr2); - } - } else if (isFixedOutputQuery(pQuery)) { - if (pQuery->stableQuery && !isTsCompQuery(pQuery)) { - pRuntimeEnv->proot = createMultiTableAggOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); - } else { - pRuntimeEnv->proot = createAggregateOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); - } + if (pQuery->pExpr2 != NULL) { + pRuntimeEnv->proot = createArithOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQuery->pExpr2, pQuery->numOfExpr2); + } + } else if (isFixedOutputQuery(pQuery)) { + if (pQuery->stableQuery && !isTsCompQuery(pQuery)) { + pRuntimeEnv->proot = + createMultiTableAggOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); + } else { + pRuntimeEnv->proot = + createAggregateOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); + } - setTableScanFilterOperatorInfo(pRuntimeEnv->pTableScanner->info, pRuntimeEnv->proot); + setTableScanFilterOperatorInfo(pRuntimeEnv->pTableScanner->info, pRuntimeEnv->proot); - if (pQuery->pExpr2 != NULL) { - pRuntimeEnv->proot = createArithOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQuery->pExpr2, pQuery->numOfExpr2); - } - } else { // diff/add/multiply/subtract/division - assert(pQuery->checkResultBuf == 1); - if (!onlyQueryTags(pQuery)) { - pRuntimeEnv->proot = createArithOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); - setTableScanFilterOperatorInfo(pRuntimeEnv->pTableScanner->info, pRuntimeEnv->proot); - } + if (pQuery->pExpr2 != NULL) { + pRuntimeEnv->proot = createArithOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQuery->pExpr2, pQuery->numOfExpr2); } - - if (pQuery->limit.offset > 0) { - pRuntimeEnv->proot = createOffsetOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot); + } else { // diff/add/multiply/subtract/division + assert(pQuery->checkResultBuf == 1); + if (!onlyQueryTags(pQuery)) { + pRuntimeEnv->proot = + createArithOperatorInfo(pRuntimeEnv, pRuntimeEnv->pTableScanner, pQuery->pExpr1, pQuery->numOfOutput); + setTableScanFilterOperatorInfo(pRuntimeEnv->pTableScanner->info, pRuntimeEnv->proot); } + } - if (pQuery->limit.limit > 0) { - pRuntimeEnv->proot = createLimitOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot); - } + if (pQuery->limit.offset > 0) { + pRuntimeEnv->proot = createOffsetOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot); + } - return TSDB_CODE_SUCCESS; + if (pQuery->limit.limit > 0) { + pRuntimeEnv->proot = createLimitOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot); + } + + return TSDB_CODE_SUCCESS; _clean: tfree(pRuntimeEnv->sasArray); @@ -3881,9 +3891,6 @@ static int32_t setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) // TODO set the tags scan handle if (onlyQueryTags(pQuery)) { return TSDB_CODE_SUCCESS; -// } else if (isTsCompQuery(pQuery)) { -// setTableQueryHandle(pRuntimeEnv, 0); -// return terrno; } STsdbQueryCond cond = createTsdbQueryCond(pQuery, &pQuery->window); @@ -4011,21 +4018,12 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, SArray* prevResult, void *ts } int32_t ps = DEFAULT_PAGE_SIZE; - int32_t rowsize = 0; getIntermediateBufInfo(pRuntimeEnv, &ps, &pQuery->intermediateResultRowSize); - int32_t TENMB = 1024*1024*10; - if (isSTableQuery && !onlyQueryTags(pQuery)) { - code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, ps, TENMB, pQInfo); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - } else if (pQuery->groupbyColumn || QUERY_IS_INTERVAL_QUERY(pQuery) || (!isSTableQuery)) { - getIntermediateBufInfo(pRuntimeEnv, &ps, &rowsize); - code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, ps, TENMB, pQInfo); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + int32_t TENMB = 1024*1024*10; + code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, ps, TENMB, pQInfo); + if (code != TSDB_CODE_SUCCESS) { + return code; } // create runtime environment @@ -4916,6 +4914,11 @@ static void destroyArithOperatorInfo(void* param, int32_t numOfOutput) { doDestroyBasicInfo(&pInfo->binfo, numOfOutput); } +static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) { + STagScanInfo* pInfo = (STagScanInfo*) param; + pInfo->pRes = destroyOutputBuf(pInfo->pRes); +} + SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SAggOperatorInfo* pInfo = calloc(1, sizeof(SAggOperatorInfo)); @@ -5191,13 +5194,14 @@ static SSDataBlock* doTagScan(void* param) { } qDebug("QInfo:%p create (tableId, tag) info completed, rows:%d", pRuntimeEnv->qinfo, count); - } /*else if (functionId == TSDB_FUNC_COUNT) {// handle the "count(tbname)" query - *(int64_t*) pQuery->sdata[0]->data = num; - + } else if (functionId == TSDB_FUNC_COUNT) {// handle the "count(tbname)" query + SColumnInfoData* pColInfo = taosArrayGet(pRes->pDataBlock, 0); + *(int64_t*)pColInfo->pData = pInfo->totalTables; count = 1; - SET_STABLE_QUERY_OVER(pRuntimeEnv); + + pOperator->status = OP_EXEC_DONE; qDebug("QInfo:%p create count(tbname) query, res:%d rows:1", pRuntimeEnv->qinfo, count); - }*/ else { // return only the tags|table name etc. + } else { // return only the tags|table name etc. SExprInfo* pExprInfo = pOperator->pExpr; // todo use the column list instead of exprinfo count = 0; @@ -5231,6 +5235,10 @@ static SSDataBlock* doTagScan(void* param) { count += 1; } + if (pInfo->currentIndex >= pInfo->totalTables) { + pOperator->status = OP_EXEC_DONE; + } + qDebug("QInfo:%p create tag values results completed, rows:%d", pRuntimeEnv->qinfo, count); } @@ -5258,6 +5266,7 @@ SOperatorInfo* createTagScanOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SExprInf pOperator->pExpr = pExpr; pOperator->numOfOutput = numOfOutput; pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->cleanup = destroyTagScanOperatorInfo; return pOperator; } diff --git a/tests/script/general/cache/new_metrics.sim b/tests/script/general/cache/new_metrics.sim index a13dd23bb64c490f52fed7abe946ec7dfec90adb..78428c1c5a1795781b2245e821f11a8abaa1f284 100644 --- a/tests/script/general/cache/new_metrics.sim +++ b/tests/script/general/cache/new_metrics.sim @@ -94,8 +94,9 @@ while $i < 10 $i = $i + 1 endw -print ==> sleep 8 seconds to renew cache -sleep 8000 +print ==> sleep 1 seconds to renew cache +sql reset query cache +sleep 1000 print =============== step5 diff --git a/tests/script/general/cache/restart_metrics.sim b/tests/script/general/cache/restart_metrics.sim index f5035e1251c11c7c4010160cfac967d9b2617c21..c3e0c8b9be9cbeaf2b19d079ea0d3563d657517e 100644 --- a/tests/script/general/cache/restart_metrics.sim +++ b/tests/script/general/cache/restart_metrics.sim @@ -55,7 +55,7 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 0 system sh/exec.sh -n dnode1 -s start print =============== step3 -print ==> sleep 8 seconds to renew cache +print ==> sleep 1 seconds to renew cache sql reset query cache sleep 1000 diff --git a/tests/script/general/cache/restart_table.sim b/tests/script/general/cache/restart_table.sim index fcdb2fb593bac7d3eb13b82c7abfe268eafe36dc..0a85100e8414c42006c6838473590acd11556849 100644 --- a/tests/script/general/cache/restart_table.sim +++ b/tests/script/general/cache/restart_table.sim @@ -39,10 +39,9 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 0 system sh/exec.sh -n dnode1 -s start print =============== step3 -print ==> sleep 8 seconds to renew cache -sleep 2000 +print ==> sleep 1 seconds to renew cache sql reset query cache -sleep 18000 +sleep 1000 print =============== step4 sql create database $db diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 8eb6aa55f2d06f4d90e14cd4035d2c460b6b1b00..f15daf2597b6b6cf2402cb39cc8f9eb03ab1af6e 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -775,8 +775,16 @@ if $rows != 1 then return -1 endi - if $data00 != 0.000000000 then return -1 endi +sql select count(tbname) from st1 +if $rows != 1 then + return -1 +endi + +sql select count(id) from st1 +if $rows != 1 then + return -1 +endi \ No newline at end of file diff --git a/tests/script/general/stream/restart_stream.sim b/tests/script/general/stream/restart_stream.sim index ce06f24df72d81c5b4da45cde75ff7d8bbd507d0..0addf0292c45b8791aae80c131a7feb9818ea7f3 100644 --- a/tests/script/general/stream/restart_stream.sim +++ b/tests/script/general/stream/restart_stream.sim @@ -100,8 +100,9 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 0 system sh/exec.sh -n dnode1 -s start print =============== step5 -print ==> sleep 8 seconds to renew cache -sleep 8000 +print ==> renew cache +sql reset query cache +sleep 1000 print =============== step6 diff --git a/tests/script/jenkins/basic_1.txt b/tests/script/jenkins/basic_1.txt index 17245767344e50389d10bc997be33abb78c289ef..ae72e76b2f6c444e84fdaee3818200983796ace3 100644 --- a/tests/script/jenkins/basic_1.txt +++ b/tests/script/jenkins/basic_1.txt @@ -22,8 +22,6 @@ ./test.sh -f general/http/grafana_bug.sim ./test.sh -f general/http/grafana.sim - - ./test.sh -f general/insert/basic.sim ./test.sh -f general/insert/insert_drop.sim ./test.sh -f general/insert/query_block1_memory.sim