diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 952ca1ca9043e4cc2999fd12d24f8df179e07032..4f47d9d7b2de463ed458f11e952585ebbb39df53 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -183,7 +183,6 @@ static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle); static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock); static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, STsdbQueryHandle* pQueryHandle); -static int32_t tsdbCheckInfoCompar(const void* key1, const void* key2); static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SMemRef* pMemRef); static void* doFreeColumnInfoData(SArray* pColumnInfoData); static void* destroyTableCheckInfo(SArray* pTableCheckInfo); @@ -333,8 +332,6 @@ static SArray* createCheckInfoFromTableGroup(STsdbQueryHandle* pQueryHandle, STa } } - taosArraySort(pTableCheckInfo, tsdbCheckInfoCompar); - size_t gsize = taosArrayGetSize(pTableCheckInfo); for (int32_t i = 0; i < gsize; ++i) { @@ -3913,17 +3910,6 @@ static int32_t tableGroupComparFn(const void *p1, const void *p2, const void *pa return 0; } -static int tsdbCheckInfoCompar(const void* key1, const void* key2) { - if (((STableCheckInfo*)key1)->tableId.tid < ((STableCheckInfo*)key2)->tableId.tid) { - return -1; - } else if (((STableCheckInfo*)key1)->tableId.tid > ((STableCheckInfo*)key2)->tableId.tid) { - return 1; - } else { - ASSERT(false); - return 0; - } -} - void createTableGroupImpl(SArray* pGroups, SArray* pTableList, size_t numOfTables, TSKEY skey, STableGroupSupporter* pSupp, __ext_compar_fn_t compareFn) { STable* pTable = taosArrayGetP(pTableList, 0); @@ -4662,4 +4648,4 @@ void tsdbAddScanCallback(TsdbQueryHandleT* queryHandle, readover_callback callba pQueryHandle->readover_cb = callback; pQueryHandle->param = param; return ; -} \ No newline at end of file +} diff --git a/src/tsdb/src/tsdbReadImpl.c b/src/tsdb/src/tsdbReadImpl.c index f2678c627fa61aff227ae61749d2ed76ef5e2db8..57b91e5f3d867c79b3739bfe2f88e73239dd2eb6 100644 --- a/src/tsdb/src/tsdbReadImpl.c +++ b/src/tsdb/src/tsdbReadImpl.c @@ -172,28 +172,28 @@ int tsdbSetReadTable(SReadH *pReadh, STable *pTable) { size_t size = taosArrayGetSize(pReadh->aBlkIdx); if (size > 0) { - while (true) { - if (pReadh->cidx >= size) { - pReadh->pBlkIdx = NULL; - break; - } - - SBlockIdx *pBlkIdx = taosArrayGet(pReadh->aBlkIdx, pReadh->cidx); + int64_t left = 0, right = size - 1; + while (left <= right) { + int64_t mid = (left + right) / 2; + SBlockIdx *pBlkIdx = taosArrayGet(pReadh->aBlkIdx, (size_t)mid); if (pBlkIdx->tid == TABLE_TID(pTable)) { if (pBlkIdx->uid == TABLE_UID(pTable)) { pReadh->pBlkIdx = pBlkIdx; } else { pReadh->pBlkIdx = NULL; } - pReadh->cidx++; - break; - } else if (pBlkIdx->tid > TABLE_TID(pTable)) { - pReadh->pBlkIdx = NULL; + break; + } else if (pBlkIdx->tid < TABLE_TID(pTable)) { + left = mid + 1; } else { - pReadh->cidx++; + right = mid - 1; } } + + if (left > right) { + pReadh->pBlkIdx = NULL; + } } else { pReadh->pBlkIdx = NULL; }