diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 4347550c2d1bef28f31de0b1c69725e94fa1f11d..950c9348af69d8b4275785da95d0b64db490b811 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -177,6 +177,7 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t (*pIter)->iSttBlk = index; if (index != -1) { (*pIter)->pSttBlk = taosArrayGet(pBlockLoadInfo->aSttBlk, (*pIter)->iSttBlk); + (*pIter)->iRow = ((*pIter)->backward) ? (*pIter)->pSttBlk->nRow : -1; } _exit: @@ -306,7 +307,6 @@ bool tLDataIterNextRow(SLDataIter *pIter) { int32_t iBlockL = pIter->iSttBlk; SBlockData *pBlockData = loadBlockIfMissing(pIter); - pIter->iRow += step; while (1) { @@ -323,6 +323,7 @@ bool tLDataIterNextRow(SLDataIter *pIter) { if (iBlockL != pIter->iSttBlk) { pBlockData = loadBlockIfMissing(pIter); + pIter->iRow += step; } } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index e404dd3d3a001c7da93049f96f800e59655c1430..facfdb9a628c11c9b35e1dfb9a529b564308e7bb 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -228,9 +228,11 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableK for (int32_t j = 0; j < numOfTables; ++j) { STableBlockScanInfo info = {.lastKey = 0, .uid = idList[j].uid}; if (ASCENDING_TRAVERSE(pTsdbReader->order)) { - info.lastKey = pTsdbReader->window.skey - 1; + int64_t skey = pTsdbReader->window.skey; + info.lastKey = (skey > INT64_MIN)? (skey - 1):skey; } else { - info.lastKey = pTsdbReader->window.ekey + 1; + int64_t ekey = pTsdbReader->window.ekey; + info.lastKey = (ekey < INT64_MAX)? (ekey + 1):ekey; } taosHashPut(pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info)); @@ -342,10 +344,12 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, SArray* aDFileSet, STsdb pLReader->uid = 0; tMergeTreeClose(&pLReader->mergeTree); - pLReader->pInfo = tCreateLastBlockLoadInfo(); if (pLReader->pInfo == NULL) { - tsdbDebug("init fileset iterator failed, code:%s %s", tstrerror(terrno), pReader->idStr); - return terrno; + pLReader->pInfo = tCreateLastBlockLoadInfo(); + if (pLReader->pInfo == NULL) { + tsdbDebug("init fileset iterator failed, code:%s %s", tstrerror(terrno), pReader->idStr); + return terrno; + } } tsdbDebug("init fileset iterator, total files:%d %s", pIter->numOfFiles, pReader->idStr); @@ -1892,7 +1896,7 @@ static bool initLastBlockReader(SLastBlockReader* pLBlockReader, STableBlockScan int32_t code = tMergeTreeOpen(&pLBlockReader->mergeTree, (pLBlockReader->order == TSDB_ORDER_DESC), pReader->pFileReader, - pReader->suid, pScanInfo->uid, &w, &pLBlockReader->verRange, pLBlockReader->pInfo); + pReader->suid, pScanInfo->uid, &w, &pLBlockReader->verRange, pLBlockReader->pInfo); if (code != TSDB_CODE_SUCCESS) { return false; } diff --git a/tests/script/tsim/parser/commit.sim b/tests/script/tsim/parser/commit.sim index ae19a4803bc6bd0f75c2a307696d7b0fc6f1ecb6..a9bf8b26ebda178ed789f3119eac7203a6889f9b 100644 --- a/tests/script/tsim/parser/commit.sim +++ b/tests/script/tsim/parser/commit.sim @@ -97,6 +97,7 @@ while $loop <= $loops endw sql select count(*) from $stb if $data00 != $totalNum then + print expect $totalNum , actual: $data00 return -1 endi $loop = $loop + 1