diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 24e978b0ea10f19ddbfdec5756d81e0fd35626a8..d06f9beb7fec68f0ae0e1baade202370ffccc2a9 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1590,18 +1590,35 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize, int int32_t nRows = payloadSize / rowSize; ASSERT(nRows >= 1); - // the true value must be less than the value of nRows - int32_t additional = 0; + int32_t numVarCols = 0; + int32_t numFixCols = 0; for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, i); if (IS_VAR_DATA_TYPE(pCol->info.type)) { - additional += nRows * sizeof(int32_t); + ++numVarCols; + } else { + ++numFixCols; + } + } + + // find the data payload whose size is greater than payloadSize + int result = -1; + int start = 1; + int end = nRows; + while (start <= end) { + int mid = start + (end - start) / 2; + //data size + var data type columns offset + fixed data type columns bitmap len + int midSize = rowSize * mid + numVarCols * sizeof(int32_t) * mid + numFixCols * BitmapLen(mid); + if (midSize > payloadSize) { + result = mid; + end = mid - 1; } else { - additional += BitmapLen(nRows); + start = mid + 1; } } - int32_t newRows = (payloadSize - additional) / rowSize; + int32_t newRows = (result != -1) ? result - 1 : nRows; + // the true value must be less than the value of nRows ASSERT(newRows <= nRows && newRows >= 1); return newRows; diff --git a/tests/script/tsim/query/sys_tbname.sim b/tests/script/tsim/query/sys_tbname.sim index 849aeb2ac5dabc46e6770de956e4e885e988e2ab..f49a8e0a7d7e4c0780e77bb3ad3f1ae8ef5a3b65 100644 --- a/tests/script/tsim/query/sys_tbname.sim +++ b/tests/script/tsim/query/sys_tbname.sim @@ -131,4 +131,8 @@ print $rows if $rows != 9 then return -1 endi + +print =========================== td-24781 +sql select DISTINCT (`precision`) from `information_schema`.`ins_databases` PARTITION BY `precision` + #system sh/exec.sh -n dnode1 -s stop -x SIGINT