diff --git a/include/util/tdef.h b/include/util/tdef.h index e4af88bf10..0a0fe22449 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -223,6 +223,7 @@ typedef enum ELogicConditionType { #define TSDB_SUBSCRIBE_KEY_LEN (TSDB_CGROUP_LEN + TSDB_TOPIC_FNAME_LEN + 2) #define TSDB_PARTITION_KEY_LEN (TSDB_SUBSCRIBE_KEY_LEN + 20) #define TSDB_COL_NAME_LEN 65 +#define TSDB_COL_FNAME_LEN (TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN + TSDB_NAME_DELIMITER_LEN) #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 #define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE #define TSDB_MAX_SQL_SHOW_LEN 1024 diff --git a/source/libs/planner/inc/planInt.h b/source/libs/planner/inc/planInt.h index 092fe17411..b70b04bb88 100644 --- a/source/libs/planner/inc/planInt.h +++ b/source/libs/planner/inc/planInt.h @@ -36,6 +36,7 @@ int32_t createColumnByRewriteExprs(SNodeList* pExprs, SNodeList** pList); int32_t createColumnByRewriteExpr(SNode* pExpr, SNodeList** pList); int32_t replaceLogicNode(SLogicSubplan* pSubplan, SLogicNode* pOld, SLogicNode* pNew); int32_t adjustLogicNodeDataRequirement(SLogicNode* pNode, EDataOrderLevel requirement); +int32_t createMD5HashFromName(char *pName, int32_t len); int32_t createLogicPlan(SPlanContext* pCxt, SLogicSubplan** pLogicSubplan); int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicSubplan* pLogicSubplan); diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 5765e304a9..920d465412 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -1610,8 +1610,12 @@ static int32_t partTagsOptRebuildTbanme(SNodeList* pPartKeys) { } // todo refact: just to mask compilation warnings -static void partTagsSetAlias(char* pAlias, int32_t len, const char* pTableAlias, const char* pColName) { - snprintf(pAlias, len, "%s.%s", pTableAlias, pColName); +static void partTagsSetAlias(char* pAlias, const char* pTableAlias, const char* pColName) { + char name[TSDB_COL_FNAME_LEN + 1] = {0}; + int32_t len = snprintf(name, TSDB_COL_FNAME_LEN, "%s.%s", pTableAlias, pColName); + + createMD5HashFromName(name, len); + strcpy(pAlias, name); } static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) { @@ -1623,7 +1627,7 @@ static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) { snprintf(pFunc->functionName, sizeof(pFunc->functionName), "%s", pFuncName); if (QUERY_NODE_COLUMN == nodeType(pNode) && COLUMN_TYPE_TBNAME != ((SColumnNode*)pNode)->colType) { SColumnNode* pCol = (SColumnNode*)pNode; - partTagsSetAlias(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), pCol->tableAlias, pCol->colName); + partTagsSetAlias(pFunc->node.aliasName, pCol->tableAlias, pCol->colName); } else { strcpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName); } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 06859e195d..8aa5303a20 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -39,26 +39,32 @@ typedef struct SPhysiPlanContext { bool hasSysScan; } SPhysiPlanContext; -static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) { +static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey, int32_t keyBufSize) { + int32_t len = 0; if (QUERY_NODE_COLUMN == nodeType(pNode)) { SColumnNode* pCol = (SColumnNode*)pNode; if (NULL != pStmtName) { if ('\0' != pStmtName[0]) { - return sprintf(pKey, "%s.%s", pStmtName, pCol->node.aliasName); + len = snprintf(pKey, keyBufSize, "%s.%s", pStmtName, pCol->node.aliasName); + return createMD5HashFromName(pKey, len); } else { - return sprintf(pKey, "%s", pCol->node.aliasName); + return snprintf(pKey, keyBufSize, "%s", pCol->node.aliasName); } } if ('\0' == pCol->tableAlias[0]) { - return sprintf(pKey, "%s", pCol->colName); + return snprintf(pKey, keyBufSize, "%s", pCol->colName); } - return sprintf(pKey, "%s.%s", pCol->tableAlias, pCol->colName); + + len = snprintf(pKey, keyBufSize, "%s.%s", pCol->tableAlias, pCol->colName); + return createMD5HashFromName(pKey, len); } if (NULL != pStmtName && '\0' != pStmtName[0]) { - return sprintf(pKey, "%s.%s", pStmtName, ((SExprNode*)pNode)->aliasName); + len = snprintf(pKey, keyBufSize, "%s.%s", pStmtName, ((SExprNode*)pNode)->aliasName); + return createMD5HashFromName(pKey, len); } - return sprintf(pKey, "%s", ((SExprNode*)pNode)->aliasName); + + return snprintf(pKey, keyBufSize, "%s", ((SExprNode*)pNode)->aliasName); } static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const char* pName, const SNode* pNode, int16_t slotId, @@ -136,8 +142,8 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD int16_t slotId = 0; SNode* pNode = NULL; FOREACH(pNode, pList) { - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; - getSlotKey(pNode, NULL, name); + char name[TSDB_COL_FNAME_LEN + 1] = {0}; + getSlotKey(pNode, NULL, name, TSDB_COL_FNAME_LEN); code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, name, pNode, slotId, true, false)); if (TSDB_CODE_SUCCESS == code) { code = putSlotToHash(name, pDataBlockDesc->dataBlockId, slotId, pNode, pHash); @@ -199,8 +205,8 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SNode* pNode = NULL; FOREACH(pNode, pList) { SNode* pExpr = QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode) ? ((SOrderByExprNode*)pNode)->pExpr : pNode; - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN] = {0}; - int32_t len = getSlotKey(pExpr, pStmtName, name); + char name[TSDB_COL_FNAME_LEN + 1] = {0}; + int32_t len = getSlotKey(pExpr, pStmtName, name, TSDB_COL_FNAME_LEN); SSlotIndex* pIndex = taosHashGet(pHash, name, len); if (NULL == pIndex) { code = @@ -288,8 +294,8 @@ static void dumpSlots(const char* pName, SHashObj* pHash) { static EDealRes doSetSlotId(SNode* pNode, void* pContext) { if (QUERY_NODE_COLUMN == nodeType(pNode) && 0 != strcmp(((SColumnNode*)pNode)->colName, "*")) { SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext; - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; - int32_t len = getSlotKey(pNode, NULL, name); + char name[TSDB_COL_FNAME_LEN + 1] = {0}; + int32_t len = getSlotKey(pNode, NULL, name, TSDB_COL_FNAME_LEN); SSlotIndex* pIndex = taosHashGet(pCxt->pLeftHash, name, len); if (NULL == pIndex) { pIndex = taosHashGet(pCxt->pRightHash, name, len); diff --git a/source/libs/planner/src/planUtil.c b/source/libs/planner/src/planUtil.c index 88086cde1d..32f4a25a42 100644 --- a/source/libs/planner/src/planUtil.c +++ b/source/libs/planner/src/planUtil.c @@ -374,4 +374,17 @@ bool isPartTableWinodw(SWindowLogicNode* pWindow) { return stbHasPartTbname(stbSplGetPartKeys((SLogicNode*)nodesListGetNode(pWindow->node.pChildren, 0))); } +int32_t createMD5HashFromName(char *pName, int32_t len) { + T_MD5_CTX ctx; + tMD5Init(&ctx); + tMD5Update(&ctx, (uint8_t*)pName, len); + tMD5Final(&ctx); + char* p = pName; + int32_t resLen = 0; + for (uint8_t i = 0; i < tListLen(ctx.digest); ++i) { + resLen += snprintf(p, 3, "%02x", ctx.digest[i]); + p += 2; + } + return resLen; +}