diff --git a/include/util/tdef.h b/include/util/tdef.h index 556ad6b680f94d0aa93ed0461e304b4e5e10a9e4..48dedd3e3e5bc80f703662cc25644b6ccf8cac76 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -489,6 +489,9 @@ enum { #define MAX_META_MSG_IN_BATCH 1048576 #define MAX_META_BATCH_RSP_SIZE (1 * 1048576 * 1024) +// sort page size by default +#define DEFAULT_PAGESIZE 4096 + #ifdef __cplusplus } #endif diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index 5591299d308acc0277a31f351e743d4dacf4e60f..51440a7f59567daaf3d76929628946a1d4c0544a 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -163,9 +163,10 @@ SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle); /** * get proper sort buffer pages according to the row size * @param rowSize + * @param numOfCols columns count that be put into page * @return */ -int32_t getProperSortPageSize(size_t rowSize); +int32_t getProperSortPageSize(size_t rowSize, uint32_t numOfCols); #ifdef __cplusplus } diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 77d2aeba282ce71b1ca03351119cb242f25235b3..145f2360403279b68a975f2535691fa753fd897e 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -4822,7 +4822,8 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN initLimitInfo(pTableScanNode->scan.node.pLimit, pTableScanNode->scan.node.pSlimit, &pInfo->limitInfo); int32_t rowSize = pInfo->pResBlock->info.rowSize; - pInfo->bufPageSize = getProperSortPageSize(rowSize); + uint32_t numOfCols = taosArrayGetSize(pInfo->pResBlock->pDataBlock); + pInfo->bufPageSize = getProperSortPageSize(rowSize, numOfCols); setOperatorInfo(pOperator, "TableMergeScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index fc53623d44607ad17503d43351340348ace6b3fb..add580ce7c89d03e9ca85f01a738ed80e6663722 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -760,7 +760,8 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size pInfo->groupSort = pMergePhyNode->groupSort; pInfo->pSortInfo = createSortInfo(pMergePhyNode->pMergeKeys); pInfo->pInputBlock = pInputBlock; - pInfo->bufPageSize = getProperSortPageSize(rowSize); + size_t numOfCols = taosArrayGetSize(pInfo->binfo.pRes->pDataBlock); + pInfo->bufPageSize = getProperSortPageSize(rowSize, numOfCols); pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1); // one additional is reserved for merged result. setOperatorInfo(pOperator, "MultiwayMergeOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE, false, OP_NOT_OPENED, pInfo, pTaskInfo); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 71fad2e27c8fb13da291460c92847a69a7191d9f..9c10b51b1f2968500071cb0d14400ed631b7d887 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -584,15 +584,11 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { return 0; } -// TODO consider the page meta size -int32_t getProperSortPageSize(size_t rowSize) { - uint32_t defaultPageSize = 4096; - - uint32_t pgSize = 0; - if (rowSize * 4 > defaultPageSize) { - pgSize = rowSize * 4; - } else { - pgSize = defaultPageSize; +// get sort page size +int32_t getProperSortPageSize(size_t rowSize, uint32_t numOfCols) { + uint32_t pgSize = rowSize * 4 + blockDataGetSerialMetaSize(numOfCols); + if (pgSize < DEFAULT_PAGESIZE) { + return DEFAULT_PAGESIZE; } return pgSize; @@ -612,7 +608,8 @@ static int32_t createInitialSources(SSortHandle* pHandle) { } if (pHandle->pDataBlock == NULL) { - pHandle->pageSize = getProperSortPageSize(blockDataGetRowSize(pBlock)); + uint32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + pHandle->pageSize = getProperSortPageSize(blockDataGetRowSize(pBlock), numOfCols); // todo, number of pages are set according to the total available sort buffer pHandle->numOfPages = 1024;