From 460d43f22c4c16321cf371e6a4d79ee3accd3092 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 8 Apr 2022 16:53:09 +0800 Subject: [PATCH] : fix index map error from table scan to sort output --- source/common/src/tdatablock.c | 12 +++++++----- source/libs/executor/inc/tsort.h | 5 ----- source/libs/executor/src/executorimpl.c | 3 +-- source/libs/executor/src/tsort.c | 8 +++++++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index abcb4283d2..111dfc7377 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -315,6 +315,7 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) { return 0; } +// if pIndexMap = NULL, merger one column by on column int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pIndexMap) { assert(pSrc != NULL && pDest != NULL); @@ -380,17 +381,18 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd size_t payloadSize = pageSize - (headerSize + colHeaderSize); // TODO speedup by checking if the whole page can fit in firstly. - /*if (!hasVarCol) { + if (!hasVarCol) { size_t rowSize = blockDataGetRowSize(pBlock); - int32_t capacity = (payloadSize / (rowSize * 8 + bitmapChar * numOfCols)) * 8; //if pageSize = 128, rowSize = 2, it will core in doAddToBuf:assert(size <= getBufPageSize(pHandle->pBuf)); + int32_t capacity = payloadSize / (rowSize + numOfCols * bitmapChar / 8.0); + ASSERT(capacity > 0); - *stopIndex = startIndex + capacity; + *stopIndex = startIndex + capacity - 1; if (*stopIndex >= numOfRows) { *stopIndex = numOfRows - 1; } return TSDB_CODE_SUCCESS; - }*/ + } // iterate the rows that can be fit in this buffer page int32_t size = (headerSize + colHeaderSize); @@ -532,7 +534,7 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) { size_t metaSize = pBlock->info.rows * sizeof(int32_t); if (IS_VAR_DATA_TYPE(pCol->info.type)) { - char* tmp = taosMemoryRealloc(pCol->varmeta.offset, metaSize); + char* tmp = taosMemoryRealloc(pCol->varmeta.offset, metaSize); // preview calloc is too small if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index f012cc2448..c584df05dd 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -52,11 +52,6 @@ typedef struct SMsortComparParam { SArray *orderInfo; // SArray } SMsortComparParam; -struct STupleHandle { - SSDataBlock* pBlock; - int32_t rowIndex; -}; - typedef struct SSortHandle SSortHandle; typedef struct STupleHandle STupleHandle; diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 0cc73bb2cd..a8857dbc1d 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -4734,8 +4734,7 @@ static void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHan for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); - SColumnInfoData* pColInfoSrc = taosArrayGet(pTupleHandle->pBlock->pDataBlock, i); - bool isNull = colDataIsNull(pColInfoSrc, 0, pTupleHandle->rowIndex, NULL); + bool isNull = tsortIsNullVal(pTupleHandle, i); if (isNull) { colDataAppend(pColInfo, pBlock->info.rows, NULL, true); } else { diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 965cf14400..3155b69a86 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -24,6 +24,11 @@ #include "tutil.h" #include "tcompare.h" +struct STupleHandle { + SSDataBlock* pBlock; + int32_t rowIndex; +}; + struct SSortHandle { int32_t type; @@ -678,7 +683,8 @@ STupleHandle* tsortNextTuple(SSortHandle* pHandle) { } bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colIndex) { - return false; + SColumnInfoData* pColInfoSrc = taosArrayGet(pVHandle->pBlock->pDataBlock, colIndex); + return colDataIsNull(pColInfoSrc, 0, pVHandle->rowIndex, NULL); } void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex) { -- GitLab