diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index a53f67d949..130a89af5c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -105,12 +105,16 @@ void tLDataIterNextBlock(SLDataIter *pIter) { size_t size = taosArrayGetSize(pIter->aBlockL); for(int32_t i = pIter->iBlockL; i < size && i >= 0; i += step) { SBlockL *p = taosArrayGet(pIter->aBlockL, i); - if (p->minUid <= pIter->uid && p->maxUid >= pIter->uid) { - index = i; + if ((!pIter->backward) && p->minUid > pIter->uid) { break; } - if (p->minUid > pIter->uid) { + if (pIter->backward && p->maxUid < pIter->uid) { + break; + } + + if (p->minUid <= pIter->uid && p->maxUid >= pIter->uid) { + index = i; break; } } @@ -145,8 +149,18 @@ static void findNextValidRow(SLDataIter* pIter) { } int64_t ts = pIter->bData.aTSKEY[i]; - if (ts < pIter->timeWindow.skey) { - continue; + if (!pIter->backward) { // asc + if (ts > pIter->timeWindow.ekey) { // no more data + break; + } else if (ts < pIter->timeWindow.skey) { + continue; + } + } else { + if (ts < pIter->timeWindow.skey) { + break; + } else if (ts > pIter->timeWindow.ekey) { + continue; + } } int64_t ver = pIter->bData.aVersion[i]; @@ -154,11 +168,6 @@ static void findNextValidRow(SLDataIter* pIter) { continue; } - // no data any more, todo opt handle desc case - if (ts > pIter->timeWindow.ekey) { - continue; - } - // todo opt handle desc case if (ver > pIter->verRange.maxVer) { continue; @@ -235,8 +244,7 @@ _exit: } SRowInfo *tLDataIterGet(SLDataIter *pIter) { - // TODO - return NULL; + return &pIter->rInfo; } // SMergeTree ================================================= diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index ec0dd8cec4..7ce73adf2a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -636,6 +636,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SArray* { // 1. time range check + printf("%ld, %ld\n", pLastBlock->minKey, pLastBlock->maxKey); if (pLastBlock->minKey > pReader->window.ekey || pLastBlock->maxKey < pReader->window.skey) { continue; }