diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index c0494aa2ae3cd9a49b7960327c7ec5b39e9658e5..36b58afb76b1aba2b85363ff51944ffe4ba8f2a1 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -1588,7 +1588,7 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* FOREACH(pProjection, pProjectNode->pProjections) { SNode* pChildTarget = NULL; FOREACH(pChildTarget, pChild->pTargets) { - if (strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName) == 0) { + if (0 == strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName)) { nodesListAppend(pNewChildTargets, nodesCloneNode(pChildTarget)); break; } @@ -2167,10 +2167,26 @@ static int32_t tagScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubp break; } } - NODES_DESTORY_LIST(pScanNode->pScanCols); SLogicNode* pAgg = pScanNode->node.pParent; + if (NULL == pAgg->pParent) { + SNodeList* pScanTargets = nodesMakeList(); + + SNode* pAggTarget = NULL; + FOREACH(pAggTarget, pAgg->pTargets) { + SNode* pScanTarget = NULL; + FOREACH(pScanTarget, pScanNode->node.pTargets) { + if (0 == strcmp( ((SColumnNode*)pAggTarget)->colName, ((SColumnNode*)pAggTarget)->colName )) { + nodesListAppend(pScanTargets, nodesCloneNode(pScanTarget)); + break; + } + } + } + nodesDestroyList(pScanNode->node.pTargets); + pScanNode->node.pTargets = pScanTargets; + } + int32_t code = replaceLogicNode(pLogicSubplan, pAgg, (SLogicNode*)pScanNode); if (TSDB_CODE_SUCCESS == code) { NODES_CLEAR_LIST(pAgg->pChildren);