From 20b36401ac3d657a73d35950e90b47d849c0de33 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 9 Apr 2022 19:03:31 +0800 Subject: [PATCH] fix[query]:fix limit/offset bug. --- source/common/src/tdatablock.c | 20 +++++++++----------- source/libs/executor/src/dataDispatcher.c | 3 +-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 66e7386b9b..053a1a1ee6 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -84,6 +84,14 @@ int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRo } } +int32_t colDataGetFullLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) { + if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { + return pColumnInfoData->varmeta.length + sizeof(int32_t) * numOfRows; + } else { + return pColumnInfoData->info.bytes * numOfRows + BitmapLen(numOfRows); + } +} + void colDataTrim(SColumnInfoData* pColumnInfoData) { // TODO } @@ -353,13 +361,7 @@ size_t blockDataGetSize(const SSDataBlock* pBlock) { for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); - total += colDataGetLength(pColInfoData, pBlock->info.rows); - - if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - total += sizeof(int32_t) * pBlock->info.rows; - } else { - total += BitmapLen(pBlock->info.rows); - } + total += colDataGetFullLength(pColInfoData, pBlock->info.rows); } return total; @@ -656,10 +658,6 @@ double blockDataGetSerialRowSize(const SSDataBlock* pBlock) { return rowSize; } -int32_t getAllowedRowsForPage(const SSDataBlock* pBlock, size_t pgSize) { - return (int32_t) ((pgSize - blockDataGetSerialMetaSize(pBlock))/ blockDataGetSerialRowSize(pBlock)); -} - typedef struct SSDataBlockSortHelper { SArray* orderInfo; // SArray SSDataBlock* pDataBlock; diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index bd96ab9e56..1edebcd7db 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -94,8 +94,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, // NOTE: there are four bytes of an integer more than the required buffer space. // struct size + data payload + length for each column + bitmap length - pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockDataGetSerialMetaSize(pInput->pData) + - ceil(blockDataGetSerialRowSize(pInput->pData) * pInput->pData->info.rows); + pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockDataGetSerialMetaSize(pInput->pData) + blockDataGetSize(pInput->pData); pBuf->pData = taosMemoryMalloc(pBuf->allocSize); if (pBuf->pData == NULL) {