From f3d7d6671b08f916e477907300f13024c70ba669 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 18 Jul 2022 20:06:29 +0800 Subject: [PATCH] fix(query):filter invisible columns --- source/libs/executor/src/scanoperator.c | 41 ++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index e60f6f8a5b..4796f0405e 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -1196,7 +1196,6 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock if (pResCol->info.colId == pColMatchInfo->colId) { SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId); colDataAssign(pDst, pResCol, pBlock->info.rows, &pInfo->pRes->info); - // taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, pResCol); colExists = true; break; } @@ -1225,6 +1224,40 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock return 0; } +// todo opt perf +static SSDataBlock* doDropInvisibleCol(SSDataBlock* pBlock, SArray* pColMatchInfo) { + size_t numOfMatchInfo = taosArrayGetSize(pColMatchInfo); + + bool ignoreCols = false; + for (int32_t j = 0; j < numOfMatchInfo; ++j) { + SColMatchInfo* pInfo = taosArrayGet(pColMatchInfo, j); + if (!pInfo->output) { + ignoreCols = true; + break; + } + } + + SSDataBlock* pRes = createOneDataBlock(pBlock, false); + if (ignoreCols) { + int32_t i = 0; + while(i < taosArrayGetSize(pRes->pDataBlock)) { + SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, i); + for (int32_t j = 0; j < numOfMatchInfo; ++j) { + SColMatchInfo* pInfo = taosArrayGet(pColMatchInfo, j); + if (pInfo->colId == pCol->info.colId && !pInfo->output) { + taosArrayRemove(pBlock->pDataBlock, i); + i -= 1; + break; + } + } + + i += 1; + } + } + + return pRes; +} + static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { // NOTE: this operator does never check if current status is done or not SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; @@ -1435,8 +1468,9 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } } } + qDebug("scan rows: %d", pBlockInfo->rows); - return (pBlockInfo->rows == 0) ? NULL : pInfo->pRes; + return (pBlockInfo->rows == 0) ? NULL : doDropInvisibleCol(pInfo->pRes, pInfo->pColMatchInfo); } else { ASSERT(0); @@ -1507,8 +1541,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys goto _error; } - SScanPhysiNode* pScanPhyNode = &pTableScanNode->scan; - + SScanPhysiNode* pScanPhyNode = &pTableScanNode->scan; SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc; pInfo->pTagCond = pTagCond; -- GitLab