From e93ed3b55617494527d030f99c6b6268163a222d Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Wed, 16 Aug 2023 14:09:22 +0800 Subject: [PATCH] enhance: table san type and disable partition tags optimize for tag scan --- source/libs/executor/inc/executil.h | 2 +- source/libs/executor/src/cachescanoperator.c | 2 +- source/libs/executor/src/executil.c | 2 +- source/libs/executor/src/scanoperator.c | 15 +++++---------- source/libs/planner/src/planLogicCreater.c | 19 +++++++++---------- source/libs/planner/src/planOptimizer.c | 3 ++- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index f273f63770..2552523e73 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -117,7 +117,7 @@ void* tableListDestroy(STableListInfo* pTableListInfo); void tableListClear(STableListInfo* pTableListInfo); int32_t tableListGetOutputGroups(const STableListInfo* pTableList); bool oneTableForEachGroup(const STableListInfo* pTableList); -uint64_t getTableGroupId(const STableListInfo* pTableList, uint64_t tableUid); +uint64_t tableListGetTableGroupId(const STableListInfo* pTableList, uint64_t tableUid); int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid); int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalIndex, STableKeyInfo** pKeyInfo, int32_t* num); diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index ce39ebab59..a07a9d5dbd 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -218,7 +218,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { return NULL; } - pRes->info.id.groupId = getTableGroupId(pTableList, pRes->info.id.uid); + pRes->info.id.groupId = tableListGetTableGroupId(pTableList, pRes->info.id.uid); pInfo->indexOfBufferedRes += 1; return pRes; } else { diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 5bb8f8a38b..057847e57a 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -1930,7 +1930,7 @@ void tableListGetSourceTableInfo(const STableListInfo* pTableList, uint64_t* psu *type = pTableList->idInfo.tableType; } -uint64_t getTableGroupId(const STableListInfo* pTableList, uint64_t tableUid) { +uint64_t tableListGetTableGroupId(const STableListInfo* pTableList, uint64_t tableUid) { int32_t* slot = taosHashGet(pTableList->map, &tableUid, sizeof(tableUid)); ASSERT(pTableList->map != NULL && slot != NULL); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 09b45d1c9d..184cb558fe 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -693,7 +693,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { } if (pBlock->info.id.uid) { - pBlock->info.id.groupId = getTableGroupId(pTableScanInfo->base.pTableListInfo, pBlock->info.id.uid); + pBlock->info.id.groupId = tableListGetTableGroupId(pTableScanInfo->base.pTableListInfo, pBlock->info.id.uid); } uint32_t status = 0; @@ -1088,7 +1088,7 @@ static SSDataBlock* readPreVersionData(SOperatorInfo* pTableScanOp, uint64_t tbU if (hasNext) { /*SSDataBlock* p = */ pAPI->tsdReader.tsdReaderRetrieveDataBlock(pReader, NULL); doSetTagColumnData(&pTableScanInfo->base, pBlock, pTaskInfo, pBlock->info.rows); - pBlock->info.id.groupId = getTableGroupId(pTableScanInfo->base.pTableListInfo, pBlock->info.id.uid); + pBlock->info.id.groupId = tableListGetTableGroupId(pTableScanInfo->base.pTableListInfo, pBlock->info.id.uid); } pAPI->tsdReader.tsdReaderClose(pReader); @@ -1110,7 +1110,7 @@ static uint64_t getGroupIdByCol(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts, static uint64_t getGroupIdByUid(SStreamScanInfo* pInfo, uint64_t uid) { STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info; - return getTableGroupId(pTableScanInfo->base.pTableListInfo, uid); + return tableListGetTableGroupId(pTableScanInfo->base.pTableListInfo, uid); } static uint64_t getGroupIdByData(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts, int64_t maxVersion) { @@ -1651,7 +1651,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock pBlockInfo->version = pBlock->info.version; STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info; - pBlockInfo->id.groupId = getTableGroupId(pTableScanInfo->base.pTableListInfo, pBlock->info.id.uid); + pBlockInfo->id.groupId = tableListGetTableGroupId(pTableScanInfo->base.pTableListInfo, pBlock->info.id.uid); // todo extract method for (int32_t i = 0; i < taosArrayGetSize(pInfo->matchInfo.pList); ++i) { @@ -2795,11 +2795,6 @@ static void tagScanFilterByTagCond(SArray* aUidTags, SNode* pTagCond, SArray* aF static void tagScanFillOneCellWithTag(const STUidTagInfo* pUidTagInfo, SExprInfo* pExprInfo, SColumnInfoData* pColInfo, int rowIndex, const SStorageAPI* pAPI, void* pVnode) { if (fmIsScanPseudoColumnFunc(pExprInfo->pExpr->_function.functionId)) { // tbname char str[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; -// if (pUidTagInfo->name != NULL) { -// STR_TO_VARSTR(str, pUidTagInfo->name); -// } else { // name is not retrieved during filter -// pAPI->metaFn.getTableNameByUid(pVnode, pUidTagInfo->uid, str); -// } STR_TO_VARSTR(str, "ctbidx"); colDataSetVal(pColInfo, rowIndex, str, false); @@ -3106,7 +3101,7 @@ static SSDataBlock* getBlockForTableMergeScan(void* param) { continue; } - pBlock->info.id.groupId = getTableGroupId(pInfo->base.pTableListInfo, pBlock->info.id.uid); + pBlock->info.id.groupId = tableListGetTableGroupId(pInfo->base.pTableListInfo, pBlock->info.id.uid); pOperator->resultInfo.totalRows += pBlock->info.rows; pInfo->base.readRecorder.elapsedTime += (taosGetTimestampUs() - st) / 1000.0; diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 7c97ec81a0..3c02675bc7 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -253,7 +253,7 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols return SCAN_TYPE_SYSTEM_TABLE; } - if (tagScan) { + if (tagScan && 0 == LIST_LENGTH(pScanCols) && 0 != LIST_LENGTH(pScanPseudoCols)) { return SCAN_TYPE_TAG; } @@ -366,17 +366,16 @@ static bool tagScanNodeHasTbname(SNode* pKeys) { return hasTbname; } -static int32_t setTagScanExecutionMode(SScanLogicNode* pScan) { - //TODO: set pScan->onlyMetaCtbIdx - bool bOnlyMetaCtbIdx = false; +static int32_t tagScanSetExecutionMode(SScanLogicNode* pScan) { + pScan->onlyMetaCtbIdx = false; if (tagScanNodeListHasTbname(pScan->pScanPseudoCols)) { - bOnlyMetaCtbIdx = false; + pScan->onlyMetaCtbIdx = false; return TSDB_CODE_SUCCESS; } if (pScan->node.pConditions == NULL) { - bOnlyMetaCtbIdx = true; + pScan->onlyMetaCtbIdx = true; return TSDB_CODE_SUCCESS; } @@ -385,9 +384,9 @@ static int32_t setTagScanExecutionMode(SScanLogicNode* pScan) { SNode* pTagIndexCond = NULL; filterPartitionCond(&pCond, NULL, &pTagIndexCond, &pTagCond, NULL); if (pTagIndexCond || tagScanNodeHasTbname(pTagCond)) { - bOnlyMetaCtbIdx = false; + pScan->onlyMetaCtbIdx = false; } else { - bOnlyMetaCtbIdx = true; + pScan->onlyMetaCtbIdx = true; } nodesDestroyNode(pCond); nodesDestroyNode(pTagIndexCond); @@ -462,8 +461,8 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect code = createColumnByRewriteExprs(pScan->pScanPseudoCols, &pScan->node.pTargets); } - if (pSelect->tagScan) { - code = setTagScanExecutionMode(pScan); + if (pScan->scanType == SCAN_TYPE_TAG) { + code = tagScanSetExecutionMode(pScan); } if (TSDB_CODE_SUCCESS == code) { diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 6944fc9f18..ff95f9a988 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -1563,7 +1563,8 @@ static bool planOptNodeListHasTbname(SNodeList* pKeys) { static bool partTagsIsOptimizableNode(SLogicNode* pNode) { bool ret = 1 == LIST_LENGTH(pNode->pChildren) && - QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(nodesListGetNode(pNode->pChildren, 0)); + QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(nodesListGetNode(pNode->pChildren, 0) && + SCAN_TYPE_TAG != ((SScanLogicNode*)(nodesListGetNode(pNode->pChildren, 0)))->scanType); if (!ret) return ret; switch (nodeType(pNode)) { case QUERY_NODE_LOGIC_PLAN_PARTITION: {