diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 209ffb9101374b1a546876f3419900bd15553ff5..f3711034909a610038e7c290d6cdc8dff5c03260 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -6513,9 +6513,9 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR return NULL; } - pInfo->bufPageSize = rowSize < 1024 ? 1024 : rowSize; + pInfo->bufPageSize = rowSize < 1024 ? 1024 : rowSize*2; - pInfo->sortBufSize = pInfo->bufPageSize * 16; // 1MB, TODO dynamic set the available sort buffer + pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer pInfo->numOfRowsInRes = 1024; pInfo->pDataBlock = pResBlock; pInfo->pSortInfo = pSortInfo; diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index ba95aa0a47a926ad30c2c5b47b25d4a987959be4..cc7416bc876edd8e315198741df112bc964356a3 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -141,8 +141,8 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSource (*sourceId) += 1; int32_t rowSize = blockDataGetSerialRowSize(pSource->src.pBlock); - int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(pBlock))/rowSize; - + int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(pBlock))/rowSize; // The value of numOfRows must be greater than 0, which is guaranteed by the previous memory allocation + ASSERT(numOfRows > 0); return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); } @@ -421,7 +421,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { size_t pgSize = pHandle->pageSize; int32_t numOfRows = (pgSize - blockDataGetSerialMetaSize(pHandle->pDataBlock))/ blockDataGetSerialRowSize(pHandle->pDataBlock); - // blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); // useless, it is already enough + blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); // useless, it is already enough size_t numOfSorted = taosArrayGetSize(pHandle->pOrderedSource); for(int32_t t = 0; t < sortPass; ++t) { diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 73808f86b261f181e2f2653dc4ddfc6e47a4fef4..229b84b9235e0a613073a317825ed8cc17a94ec5 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -83,7 +83,7 @@ SSDataBlock* getSingleColStrBlock(void* param) { SColumnInfoData colInfo = {0}; colInfo.info.type = TSDB_DATA_TYPE_NCHAR; - colInfo.info.bytes = TSDB_NCHAR_SIZE * 32; + colInfo.info.bytes = TSDB_NCHAR_SIZE * 16; colInfo.info.colId = 1; colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); @@ -92,7 +92,7 @@ SSDataBlock* getSingleColStrBlock(void* param) { for (int32_t i = 0; i < pInfo->pageRows; ++i) { SColumnInfoData* pColInfo = static_cast(TARRAY_GET_ELEM(pBlock->pDataBlock, 0)); - int32_t size = taosRand() % 32; + int32_t size = taosRand() % 16; char str[64] = {0}; taosRandStr(varDataVal(str), size); varDataSetLen(str, size); @@ -101,6 +101,8 @@ SSDataBlock* getSingleColStrBlock(void* param) { pBlock->info.rows = pInfo->pageRows; pBlock->info.numOfCols = 1; + pBlock->info.hasVarCol = true; + return pBlock; } @@ -218,7 +220,7 @@ TEST(testCase, external_mem_sort_Test) { SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 32, 6, NULL, "test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 128, 6, NULL, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); _info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info));