From c8471a5a226ad602eb340746d93263fb5a0b71e1 Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Fri, 30 Aug 2024 14:02:44 +0800 Subject: [PATCH] fix duplicate col name --- include/libs/nodes/querynodes.h | 3 + include/util/tutil.h | 4 +- source/libs/nodes/src/nodesUtilFuncs.c | 39 +++++++++ source/libs/parser/src/parTranslater.c | 2 + source/libs/planner/inc/planInt.h | 1 + source/libs/planner/src/planLogicCreater.c | 6 +- source/libs/planner/src/planPhysiCreater.c | 94 ++++++++++++++-------- source/libs/planner/src/planUtil.c | 8 ++ 8 files changed, 122 insertions(+), 35 deletions(-) diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 8ed88ef47d..ab9f9598c0 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -625,6 +625,9 @@ int32_t nodesCollectColumnsExt(SSelectStmt* pSelect, ESqlClause clause, SSHashOb SNodeList** pCols); int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, ECollectColType type, SNodeList** pCols); +int32_t nodesCollectColumnsForTargets(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type, + SNodeList** pCols); + typedef bool (*FFuncClassifier)(int32_t funcId); int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList** pFuncs); int32_t nodesCollectSelectFuncs(SSelectStmt* pSelect, ESqlClause clause, char* tableAlias, FFuncClassifier classifier, SNodeList* pFuncs); diff --git a/include/util/tutil.h b/include/util/tutil.h index 6c7517f630..fb9bd9f637 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -82,7 +82,9 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar static FORCE_INLINE int32_t taosHashBinary(char* pBuf, int32_t len) { uint64_t hashVal = MurmurHash3_64(pBuf, len); - return sprintf(pBuf, "%" PRIu64, hashVal); + uInfo("wjm hash binary for: %s", pBuf); + int32_t ret = sprintf(pBuf, "%" PRIu64, hashVal); + return ret; } static FORCE_INLINE int32_t taosCreateMD5Hash(char *pBuf, int32_t len) { diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index df9fe5570a..f9f3c6e5c4 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -2250,6 +2250,7 @@ typedef struct SCollectColumnsCxt { ECollectColType collectType; SNodeList* pCols; SHashObj* pColHash; + bool collectForTarget; } SCollectColumnsCxt; static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pNode) { @@ -2267,6 +2268,7 @@ static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pN pCxt->errCode = nodesCloneNode(pNode, &pNew); if (TSDB_CODE_SUCCESS == pCxt->errCode) { //((SColumnNode*)pNew)->projRefIdx = pCol->node.projIdx; + if (pCxt->collectForTarget) ((SColumnNode*)pNew)->resIdx = pCol->projRefIdx; pCxt->errCode = nodesListStrictAppend(pCxt->pCols, pNew); } } @@ -2305,6 +2307,43 @@ static EDealRes collectColumnsExt(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } +int32_t nodesCollectColumnsForTargets(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type, + SNodeList** pCols) { + if (NULL == pSelect || NULL == pCols) { + return TSDB_CODE_FAILED; + } + SNodeList * pList = NULL; + if (!*pCols) { + int32_t code = nodesMakeList(&pList); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + } + SCollectColumnsCxt cxt = { + .errCode = TSDB_CODE_SUCCESS, + .pTableAlias = pTableAlias, + .collectForTarget = true, + .collectType = type, + .pCols = (NULL == *pCols ? pList : *pCols), + .pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)}; + if (NULL == cxt.pCols || NULL == cxt.pColHash) { + return TSDB_CODE_OUT_OF_MEMORY; + } + *pCols = NULL; + nodesWalkSelectStmt(pSelect, clause, collectColumns, &cxt); + taosHashCleanup(cxt.pColHash); + if (TSDB_CODE_SUCCESS != cxt.errCode) { + nodesDestroyList(cxt.pCols); + return cxt.errCode; + } + if (LIST_LENGTH(cxt.pCols) > 0) { + *pCols = cxt.pCols; + } else { + nodesDestroyList(cxt.pCols); + } + + return TSDB_CODE_SUCCESS; +} int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type, SNodeList** pCols) { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 1046d52a8d..1e9891b115 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1379,12 +1379,14 @@ static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef, return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, pCol->colName); } code = setColumnInfoByExpr(pTempTable, pExpr, pColRef); + //(*pColRef)->projRefIdx = pExpr->projIdx; if (TSDB_CODE_SUCCESS != code) { break; } *pFound = true; } else if (isPrimaryKeyImpl(pNode) && isInternalPrimaryKey(pCol)) { code = setColumnInfoByExpr(pTempTable, pExpr, pColRef); + //(*pColRef)->projRefIdx = pExpr->projIdx; if (TSDB_CODE_SUCCESS != code) break; pCol->isPrimTs = true; *pFound = true; diff --git a/source/libs/planner/inc/planInt.h b/source/libs/planner/inc/planInt.h index 9435955a3e..beb277493c 100644 --- a/source/libs/planner/inc/planInt.h +++ b/source/libs/planner/inc/planInt.h @@ -69,6 +69,7 @@ int32_t cloneLimit(SLogicNode* pParent, SLogicNode* pChild, uint8_t cloneWhat, b int32_t sortPriKeyOptGetSequencingNodesImpl(SLogicNode* pNode, bool groupSort, SSortLogicNode* pSort, bool* pNotOptimize, SNodeList** pSequencingNodes, bool* keepSort); bool isColRefExpr(const SColumnNode* pCol, const SExprNode* pExpr); +void rewriteTargetsWithResId(SNodeList* pTargets); #ifdef __cplusplus diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 2fecbe212f..08e22ba1cc 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -638,6 +638,10 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect } nodesDestroyList(pColList); } + + if (TSDB_CODE_SUCCESS == code) { + rewriteTargetsWithResId(pJoin->node.pTargets); + } if (NULL == pJoin->node.pTargets && NULL != pLeft) { code = nodesCloneList(pLeft->pTargets, &pJoin->node.pTargets); @@ -1342,7 +1346,7 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect pSort->node.resultDataOrder = isPrimaryKeySort(pSelect->pOrderByList) ? (pSort->groupSort ? DATA_ORDER_LEVEL_IN_GROUP : DATA_ORDER_LEVEL_GLOBAL) : DATA_ORDER_LEVEL_NONE; - code = nodesCollectColumns(pSelect, SQL_CLAUSE_ORDER_BY, NULL, COLLECT_COL_TYPE_ALL, &pSort->node.pTargets); + code = nodesCollectColumnsForTargets(pSelect, SQL_CLAUSE_ORDER_BY, NULL, COLLECT_COL_TYPE_ALL, &pSort->node.pTargets); if (TSDB_CODE_SUCCESS == code && NULL == pSort->node.pTargets) { SNode* pNew = NULL; code = nodesCloneNode(nodesListGetNode(pCxt->pCurrRoot->pTargets, 0), &pNew); diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 89a3376ab6..d018f89dc9 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -35,17 +35,18 @@ typedef struct SPhysiPlanContext { int32_t errCode; int16_t nextDataBlockId; SArray* pLocationHelper; + SArray* pProjIdxLocHelper; bool hasScan; bool hasSysScan; } SPhysiPlanContext; -static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int32_t *pLen) { +static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int32_t *pLen, uint16_t extraBufLen) { int32_t code = 0; if (QUERY_NODE_COLUMN == nodeType(pNode)) { SColumnNode* pCol = (SColumnNode*)pNode; if (NULL != pStmtName) { if ('\0' != pStmtName[0]) { - *ppKey = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1 + TSDB_COL_NAME_LEN + 1); + *ppKey = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1 + TSDB_COL_NAME_LEN + 1 + extraBufLen); if (!*ppKey) { return terrno; } @@ -55,7 +56,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int *pLen = taosHashBinary(*ppKey, strlen(*ppKey)); return code; } else { - *ppKey = taosMemoryCalloc(1, TSDB_COL_NAME_LEN + 1); + *ppKey = taosMemoryCalloc(1, TSDB_COL_NAME_LEN + 1 + extraBufLen); if (!*ppKey) { return terrno; } @@ -65,7 +66,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int } } if ('\0' == pCol->tableAlias[0]) { - *ppKey = taosMemoryCalloc(1, TSDB_COL_NAME_LEN + 1); + *ppKey = taosMemoryCalloc(1, TSDB_COL_NAME_LEN + 1 + extraBufLen); if (!*ppKey) { return terrno; } @@ -74,7 +75,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int return code; } - *ppKey = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1 + TSDB_COL_NAME_LEN + 1); + *ppKey = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1 + TSDB_COL_NAME_LEN + 1 + extraBufLen); if (!*ppKey) { return terrno; } @@ -89,7 +90,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0); if (pVal) { if (NULL != pStmtName && '\0' != pStmtName[0]) { - *ppKey = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1 + TSDB_COL_NAME_LEN + 1); + *ppKey = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1 + TSDB_COL_NAME_LEN + 1 + extraBufLen); if (!*ppKey) { return terrno; } @@ -99,7 +100,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int *pLen = taosHashBinary(*ppKey, strlen(*ppKey)); return code; } - *ppKey = taosMemoryCalloc(1, strlen(pVal->literal) + 1 + TSDB_COL_NAME_LEN + 1); + *ppKey = taosMemoryCalloc(1, strlen(pVal->literal) + 1 + TSDB_COL_NAME_LEN + 1 + extraBufLen); if (!*ppKey) { return terrno; } @@ -113,7 +114,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int } if (NULL != pStmtName && '\0' != pStmtName[0]) { - *ppKey = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1 + TSDB_COL_NAME_LEN + 1); + *ppKey = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1 + TSDB_COL_NAME_LEN + 1 + extraBufLen); if (!*ppKey) { return terrno; } @@ -124,7 +125,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int return code; } - *ppKey = taosMemoryCalloc(1, TSDB_COL_NAME_LEN + 1); + *ppKey = taosMemoryCalloc(1, TSDB_COL_NAME_LEN + 1 + extraBufLen); if (!*ppKey) { return terrno; } @@ -191,22 +192,34 @@ static int32_t putSlotToHash(const char* pName, int32_t len, int16_t dataBlockId } static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, - SHashObj** pDescHash) { + SHashObj** pDescHash, SHashObj** ppProjIdxDescHash) { SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (NULL == pHash) { return TSDB_CODE_OUT_OF_MEMORY; } + SHashObj* pProjIdxHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (!pProjIdxHash) { + taosHashCleanup(pHash); + return TSDB_CODE_OUT_OF_MEMORY; + } if (NULL == taosArrayInsert(pCxt->pLocationHelper, dataBlockId, &pHash)) { taosHashCleanup(pHash); + taosHashCleanup(pProjIdxHash); + return TSDB_CODE_OUT_OF_MEMORY; + } + if (NULL == taosArrayInsert(pCxt->pProjIdxLocHelper, dataBlockId, &pProjIdxHash)) { + taosHashCleanup(pHash); + taosHashCleanup(pProjIdxHash); return TSDB_CODE_OUT_OF_MEMORY; } *pDescHash = pHash; + *ppProjIdxDescHash = pProjIdxHash; return TSDB_CODE_SUCCESS; } static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, - SHashObj* pHash) { + SHashObj* pHash, SHashObj* pProjIdxDescHash) { pDataBlockDesc->pSlots = NULL; int32_t code = nodesMakeList(&pDataBlockDesc->pSlots); if (NULL == pDataBlockDesc->pSlots) { @@ -218,19 +231,17 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD FOREACH(pNode, pList) { char* name = NULL; int32_t len = 0; - code = getSlotKey(pNode, NULL, &name, &len); + code = getSlotKey(pNode, NULL, &name, &len, 16); if (TSDB_CODE_SUCCESS == code) { code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, name, pNode, slotId, true, false)); } - if (TSDB_CODE_SUCCESS == code) { - qInfo("wjm append slot name: %s, slotId: %d, aliasName: %s", name, slotId, ((SExprNode*)pNode)->aliasName); - code = putSlotToHash(name, len, pDataBlockDesc->dataBlockId, slotId, pNode, pHash); - } + qInfo("wjm append slot to hash name: %s, slotId: %d, aliasName: %s", name, slotId, ((SExprNode*)pNode)->aliasName); + code = putSlotToHash(name, len, pDataBlockDesc->dataBlockId, slotId, pNode, pHash); if (TSDB_CODE_SUCCESS == code) { if (nodeType(pNode) == QUERY_NODE_COLUMN && ((SColumnNode*)pNode)->resIdx > 0) { sprintf(name + strlen(name), "%d", ((SColumnNode*)pNode)->resIdx); - qInfo("wjm append slot name: %s, slotId: %d, aliasName: %s", name, slotId, ((SExprNode*)pNode)->aliasName); - code = putSlotToHash(name, strlen(name), pDataBlockDesc->dataBlockId, slotId, pNode, pHash); + qInfo("wjm append slot name to projidx hash: %s, slotId: %d, aliasName: %s", name, slotId, ((SExprNode*)pNode)->aliasName); + code = putSlotToHash(name, strlen(name), pDataBlockDesc->dataBlockId, slotId, pNode, pProjIdxDescHash); } } taosMemoryFree(name); @@ -254,9 +265,10 @@ static int32_t createDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SD pDesc->dataBlockId = pCxt->nextDataBlockId++; SHashObj* pHash = NULL; - code = createDataBlockDescHash(pCxt, LIST_LENGTH(pList), pDesc->dataBlockId, &pHash); + SHashObj* pProjIdxHash = NULL; + code = createDataBlockDescHash(pCxt, LIST_LENGTH(pList), pDesc->dataBlockId, &pHash, &pProjIdxHash); if (TSDB_CODE_SUCCESS == code) { - code = buildDataBlockSlots(pCxt, pList, pDesc, pHash); + code = buildDataBlockSlots(pCxt, pList, pDesc, pHash, pProjIdxHash); } if (TSDB_CODE_SUCCESS == code) { @@ -294,7 +306,7 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SNode* pExpr = QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode) ? ((SOrderByExprNode*)pNode)->pExpr : pNode; char *name = NULL; int32_t len = 0; - code = getSlotKey(pExpr, pStmtName, &name, &len); + code = getSlotKey(pExpr, pStmtName, &name, &len, 0); if (TSDB_CODE_SUCCESS == code) { SSlotIndex* pIndex = taosHashGet(pHash, name, len); if (NULL == pIndex) { @@ -364,7 +376,9 @@ static int32_t pushdownDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, typedef struct SSetSlotIdCxt { int32_t errCode; SHashObj* pLeftHash; + SHashObj* pLeftProjIdxHash; SHashObj* pRightHash; + SHashObj* pRightProdIdxHash; } SSetSlotIdCxt; static void dumpSlots(const char* pName, SHashObj* pHash) { @@ -388,20 +402,26 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext; char *name = NULL; int32_t len = 0; - pCxt->errCode = getSlotKey(pNode, NULL, &name, &len); + pCxt->errCode = getSlotKey(pNode, NULL, &name, &len, 0); if (TSDB_CODE_SUCCESS != pCxt->errCode) { return DEAL_RES_ERROR; } + SSlotIndex *pIndex = NULL; if (((SColumnNode*)pNode)->projRefIdx > 0) { sprintf(name + strlen(name), "%d", ((SColumnNode*)pNode)->projRefIdx); - } - SSlotIndex* pIndex = taosHashGet(pCxt->pLeftHash, name, strlen(name)); - if (NULL == pIndex) { - pIndex = taosHashGet(pCxt->pRightHash, name, strlen(name)); + pIndex = taosHashGet(pCxt->pLeftProjIdxHash, name, strlen(name)); + if (!pIndex) { + pIndex = taosHashGet(pCxt->pRightProdIdxHash, name, strlen(name)); + } + } else { + pIndex = taosHashGet(pCxt->pLeftHash, name, len); + if (NULL == pIndex) { + pIndex = taosHashGet(pCxt->pRightHash, name, len); + } } // pIndex is definitely not NULL, otherwise it is a bug if (NULL == pIndex) { - planError("doSetSlotId failed, invalid slot name %s", name); + planError("wjm doSetSlotId failed, invalid slot name %s", name); dumpSlots("left datablock desc", pCxt->pLeftHash); dumpSlots("right datablock desc", pCxt->pRightHash); pCxt->errCode = TSDB_CODE_PLAN_INTERNAL_ERROR; @@ -432,7 +452,9 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i SSetSlotIdCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), - .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))}; + .pLeftProjIdxHash = taosArrayGetP(pCxt->pProjIdxLocHelper, leftDataBlockId), + .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId)), + .pRightProdIdxHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pProjIdxLocHelper, rightDataBlockId))}; nodesWalkExpr(pRes, doSetSlotId, &cxt); if (TSDB_CODE_SUCCESS != cxt.errCode) { nodesDestroyNode(pRes); @@ -458,7 +480,9 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i SSetSlotIdCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), - .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))}; + .pLeftProjIdxHash = taosArrayGetP(pCxt->pProjIdxLocHelper, leftDataBlockId), + .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId)), + .pRightProdIdxHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pProjIdxLocHelper, rightDataBlockId))}; nodesWalkExprs(pRes, doSetSlotId, &cxt); if (TSDB_CODE_SUCCESS != cxt.errCode) { nodesDestroyList(pRes); @@ -1268,7 +1292,7 @@ static int32_t sortHashJoinTargets(int16_t lBlkId, int16_t rBlkId, SHashJoinPhys SColumnNode* pCol = (SColumnNode*)pNode; char *pName = NULL; int32_t len = 0; - code = getSlotKey(pNode, NULL, &pName, &len); + code = getSlotKey(pNode, NULL, &pName, &len, 0); if (TSDB_CODE_SUCCESS == code) { code = tSimpleHashPut(pHash, pName, len, &pCol, POINTER_BYTES); } @@ -1286,7 +1310,7 @@ static int32_t sortHashJoinTargets(int16_t lBlkId, int16_t rBlkId, SHashJoinPhys char* pName = NULL; SColumnNode* pCol = (SColumnNode*)pNode; int32_t len = 0; - code = getSlotKey(pNode, NULL, &pName, &len); + code = getSlotKey(pNode, NULL, &pName, &len, 0); if (TSDB_CODE_SUCCESS == code) { SNode** p = tSimpleHashGet(pHash, pName, len); if (p) { @@ -1307,7 +1331,7 @@ static int32_t sortHashJoinTargets(int16_t lBlkId, int16_t rBlkId, SHashJoinPhys char* pName = NULL; SColumnNode* pCol = (SColumnNode*)pNode; int32_t len = 0; - code = getSlotKey(pNode, NULL, &pName, &len); + code = getSlotKey(pNode, NULL, &pName, &len, 0); if (TSDB_CODE_SUCCESS == code) { SNode** p = tSimpleHashGet(pHash, pName, len); if (p) { @@ -3006,6 +3030,7 @@ static void destoryLocationHash(void* p) { static void destoryPhysiPlanContext(SPhysiPlanContext* pCxt) { taosArrayDestroyEx(pCxt->pLocationHelper, destoryLocationHash); + taosArrayDestroyEx(pCxt->pProjIdxLocHelper, destoryLocationHash); } static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) { @@ -3037,9 +3062,12 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryP .errCode = TSDB_CODE_SUCCESS, .nextDataBlockId = 0, .pLocationHelper = taosArrayInit(32, POINTER_BYTES), + .pProjIdxLocHelper = taosArrayInit(32, POINTER_BYTES), .hasScan = false, .hasSysScan = false}; - if (NULL == cxt.pLocationHelper) { + if (NULL == cxt.pLocationHelper || !cxt.pProjIdxLocHelper) { + taosArrayDestroy(cxt.pLocationHelper); + taosArrayDestroy(cxt.pProjIdxLocHelper); return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/planner/src/planUtil.c b/source/libs/planner/src/planUtil.c index 8c319baa77..b5f0bc50e8 100644 --- a/source/libs/planner/src/planUtil.c +++ b/source/libs/planner/src/planUtil.c @@ -721,3 +721,11 @@ bool isColRefExpr(const SColumnNode* pCol, const SExprNode* pExpr) { return 0 == strcmp(pCol->colName, pExpr->aliasName); } + +void rewriteTargetsWithResId(SNodeList* pTargets) { + SNode* pNode; + FOREACH(pNode, pTargets) { + SColumnNode* pCol = (SColumnNode*)pNode; + pCol->resIdx = pCol->projRefIdx; + } +}