From 37b65c16c8e32cabb991ff1a8637399a62aa3f23 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 29 Nov 2022 14:59:48 +0800 Subject: [PATCH] enh: ins_tables count optimize --- source/libs/function/src/builtins.c | 2 +- source/libs/planner/src/planOptimizer.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 3e2bc2a4ac..a2a827e7e5 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -2081,7 +2081,7 @@ static int32_t translateTagsPseudoColumn(SFunctionNode* pFunc, char* pErrBuf, in } static int32_t translateTableCountPseudoColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { - pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes, .type = TSDB_DATA_TYPE_INT}; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 515d594e45..4f288f97d3 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -2630,9 +2630,11 @@ static int32_t tbCntScanOptRewriteScan(STbCntScanOptInfo* pInfo) { pInfo->pScan->scanType = SCAN_TYPE_TABLE_COUNT; strcpy(pInfo->pScan->tableName.dbname, pInfo->table.dbname); strcpy(pInfo->pScan->tableName.tname, pInfo->table.tname); - NODES_DESTORY_LIST(pInfo->pScan->node.pTargets); + if (NULL == pInfo->pAgg->pGroupKeys) { + NODES_DESTORY_LIST(pInfo->pScan->node.pTargets); + NODES_DESTORY_LIST(pInfo->pScan->pScanCols); + } NODES_DESTORY_NODE(pInfo->pScan->node.pConditions); - NODES_DESTORY_LIST(pInfo->pScan->pScanCols); NODES_DESTORY_LIST(pInfo->pScan->pScanPseudoCols); int32_t code = nodesListMakeStrictAppend(&pInfo->pScan->pScanPseudoCols, tbCntScanOptCreateTableCountFunc()); if (TSDB_CODE_SUCCESS == code) { @@ -2672,7 +2674,7 @@ static int32_t tbCntScanOptRewriteAgg(SAggLogicNode* pAgg) { SNode* pSum = NULL; int32_t code = tbCntScanOptCreateSumFunc( (SFunctionNode*)nodesListGetNode(pAgg->pAggFuncs, 0), - nodesListGetNode(((SLogicNode*)nodesListGetNode(pAgg->node.pChildren, 0))->pTargets, 0), &pSum); + nodesListGetNode(((SScanLogicNode*)nodesListGetNode(pAgg->node.pChildren, 0))->pScanPseudoCols, 0), &pSum); if (TSDB_CODE_SUCCESS == code) { NODES_DESTORY_LIST(pAgg->pAggFuncs); code = nodesListMakeStrictAppend(&pAgg->pAggFuncs, pSum);