From 6ae82b071e85c1d0902f72d65eff7e8c68f8f8e6 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 11 Nov 2022 18:28:16 +0800 Subject: [PATCH] refactor: do some internal refactor. --- source/libs/executor/src/sortoperator.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index fc53623d44..9a5f6a031d 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -536,6 +536,7 @@ typedef struct SMultiwayMergeOperatorInfo { SSortHandle* pSortHandle; SColMatchInfo matchInfo; SSDataBlock* pInputBlock; + SSDataBlock* pIntermediateBlock; // to hold the intermediate result int64_t startTs; // sort start time bool groupSort; bool hasGroupId; @@ -635,12 +636,19 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; blockDataCleanup(pDataBlock); - SSDataBlock* p = tsortGetSortedDataBlock(pHandle); - if (p == NULL) { - return NULL; + if (pInfo->pIntermediateBlock == NULL) { + pInfo->pIntermediateBlock = tsortGetSortedDataBlock(pHandle); + if (pInfo->pIntermediateBlock == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + blockDataEnsureCapacity(pInfo->pIntermediateBlock, capacity); + } else { + blockDataCleanup(pInfo->pIntermediateBlock); } - blockDataEnsureCapacity(p, capacity); + SSDataBlock* p = pInfo->pIntermediateBlock; + while (1) { doGetSortedBlockData(pInfo, pHandle, capacity, p); if (p->info.rows == 0) { @@ -670,7 +678,6 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData pDataBlock->info.groupId = pInfo->groupId; } - blockDataDestroy(p); qDebug("%s get sorted block, groupId:0x%" PRIx64 " rows:%d", GET_TASKID(pTaskInfo), pDataBlock->info.groupId, pDataBlock->info.rows); @@ -704,6 +711,7 @@ void destroyMultiwayMergeOperatorInfo(void* param) { SMultiwayMergeOperatorInfo* pInfo = (SMultiwayMergeOperatorInfo*)param; pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes); pInfo->pInputBlock = blockDataDestroy(pInfo->pInputBlock); + pInfo->pIntermediateBlock = blockDataDestroy(pInfo->pIntermediateBlock); tsortDestroySortHandle(pInfo->pSortHandle); taosArrayDestroy(pInfo->pSortInfo); -- GitLab