From 864e2c60a70c6051c006c058ba7d1b5947d3e226 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 31 Oct 2022 09:48:23 +0800 Subject: [PATCH] fix(query): invoke the different api for extract queried table list. --- source/libs/executor/inc/executil.h | 2 - source/libs/executor/src/executil.c | 82 +++---------------------- source/libs/executor/src/executorimpl.c | 4 +- 3 files changed, 10 insertions(+), 78 deletions(-) diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index 31492cafa8..76a3359b5b 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -142,8 +142,6 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo); SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode); EDealRes doTranslateTagExpr(SNode** pNode, void* pContext); -int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, SNode* pTagIndexCond, - STableListInfo* pListInfo); int32_t getGroupIdFromTagsVal(void* pMeta, uint64_t uid, SNodeList* pGroupNode, char* keyBuf, uint64_t* pGroupId); size_t getTableTagsBufLen(const SNodeList* pGroups); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index be83a7c392..82427f6eff 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -46,6 +46,8 @@ typedef struct tagFilterAssist { static int32_t removeInvalidTable(SArray* uids, SHashObj* tags); static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond, SHashObj* tags); static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond); +static int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, + SNode* pTagIndexCond, STableListInfo* pListInfo); static int64_t getLimit(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->limit; } static int64_t getOffset(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->offset; } @@ -1006,13 +1008,14 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, size_t numOfTables = taosArrayGetSize(res); for (int i = 0; i < numOfTables; i++) { STableKeyInfo info = {.uid = *(uint64_t*)taosArrayGet(res, i), .groupId = 0}; - void* p = taosArrayPush(pListInfo->pTableList, &info); + + void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { taosArrayDestroy(res); return TSDB_CODE_OUT_OF_MEMORY; } - qDebug("tagfilter get uid:%" PRId64 "", info.uid); + qDebug("tagfilter get uid:%" PRIu64 "", info.uid); } taosArrayDestroy(res); @@ -1825,81 +1828,10 @@ static int32_t sortTableGroup(STableListInfo* pTableListInfo) { pTableListInfo->groupOffset = taosMemoryMalloc(sizeof(int32_t) * pTableListInfo->numOfOuputGroups); memcpy(pTableListInfo->groupOffset, taosArrayGet(pList, 0), sizeof(int32_t) * pTableListInfo->numOfOuputGroups); taosArrayDestroy(pList); - -# if 0 - SArray* sortSupport = taosArrayInit(16, sizeof(uint64_t)); - if (sortSupport == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - size_t num = taosArrayGetSize(pTableListInfo->pTableList); - for (int32_t i = 0; i < num; i++) { - STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i); - uint64_t* groupId = taosHashGet(pTableListInfo->map, &info->uid, sizeof(uint64_t)); - - int32_t index = taosArraySearchIdx(sortSupport, groupId, compareUint64Val, TD_EQ); - if (index == -1) { - void* p = taosArraySearch(sortSupport, groupId, compareUint64Val, TD_GT); - - SArray* tGroup = taosArrayInit(8, sizeof(STableKeyInfo)); - if (tGroup == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _error; - } - - if (taosArrayPush(tGroup, info) == NULL) { - qError("taos push info array error"); - code = TSDB_CODE_OUT_OF_MEMORY; - goto _error; - } - - if (p == NULL) { - if (taosArrayPush(sortSupport, groupId) == NULL) { - qError("taos push support array error"); - code = TSDB_CODE_OUT_OF_MEMORY; - goto _error; - } - - if (taosArrayPush(pTableListInfo->pGroupList, &tGroup) == NULL) { - qError("taos push group array error"); - code = TSDB_CODE_OUT_OF_MEMORY; - goto _error; - } - } else { - int32_t pos = TARRAY_ELEM_IDX(sortSupport, p); - if (taosArrayInsert(sortSupport, pos, groupId) == NULL) { - qError("taos insert support array error"); - code = TSDB_CODE_OUT_OF_MEMORY; - goto _error; - } - - if (taosArrayInsert(pTableListInfo->pGroupList, pos, &tGroup) == NULL) { - qError("taos insert group array error"); - code = TSDB_CODE_OUT_OF_MEMORY; - goto _error; - } - } - } else { - SArray* tGroup = (SArray*)taosArrayGetP(pTableListInfo->pGroupList, index); - if (taosArrayPush(tGroup, info) == NULL) { - qError("taos push uid array error"); - code = TSDB_CODE_OUT_OF_MEMORY; - goto _error; - } - } - } - - taosArrayDestroy(sortSupport); -#endif - return TDB_CODE_SUCCESS; - - _error: -// taosArrayDestroy(sortSupport); - return code; } -int32_t setGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* group, bool groupSort) { +int32_t buildGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* group, bool groupSort) { int32_t code = TSDB_CODE_SUCCESS; ASSERT(pTableListInfo->map != NULL); @@ -1966,7 +1898,7 @@ int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags return TSDB_CODE_SUCCESS; } - code = setGroupIdMapForAllTables(pTableListInfo, pHandle, pGroupTags, groupSort); + code = buildGroupIdMapForAllTables(pTableListInfo, pHandle, pGroupTags, groupSort); if (code != TSDB_CODE_SUCCESS) { return code; } diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 0d9d6eae06..8a2d92af02 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -3490,7 +3490,9 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pOperator = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pUser, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) { STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode; - int32_t code = getTableList(pHandle->meta, pHandle->vnode, pScanPhyNode, pTagCond, pTagIndexCond, pTableListInfo); + + int32_t code = createScanTableListInfo(pScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond, + pTagIndexCond, GET_TASKID(pTaskInfo)); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; qError("failed to getTableList, code: %s", tstrerror(code)); -- GitLab