提交 10dc27b1 编写于 作者: X xywang

[TS-1318]<fix>: introduced binary search algorithm into tsdbSetReadTable

上级 7c9f8cfb
...@@ -172,12 +172,9 @@ int tsdbSetReadTable(SReadH *pReadh, STable *pTable) { ...@@ -172,12 +172,9 @@ int tsdbSetReadTable(SReadH *pReadh, STable *pTable) {
size_t size = taosArrayGetSize(pReadh->aBlkIdx); size_t size = taosArrayGetSize(pReadh->aBlkIdx);
if (size > 0) { if (size > 0) {
while (true) { size_t left = 0, right = size - 1;
if (pReadh->cidx >= size) { while (left <= right) {
pReadh->pBlkIdx = NULL; pReadh->cidx = (int)((left + right) / 2);
break;
}
SBlockIdx *pBlkIdx = taosArrayGet(pReadh->aBlkIdx, pReadh->cidx); SBlockIdx *pBlkIdx = taosArrayGet(pReadh->aBlkIdx, pReadh->cidx);
if (pBlkIdx->tid == TABLE_TID(pTable)) { if (pBlkIdx->tid == TABLE_TID(pTable)) {
if (pBlkIdx->uid == TABLE_UID(pTable)) { if (pBlkIdx->uid == TABLE_UID(pTable)) {
...@@ -185,15 +182,18 @@ int tsdbSetReadTable(SReadH *pReadh, STable *pTable) { ...@@ -185,15 +182,18 @@ int tsdbSetReadTable(SReadH *pReadh, STable *pTable) {
} else { } else {
pReadh->pBlkIdx = NULL; pReadh->pBlkIdx = NULL;
} }
pReadh->cidx++;
break;
} else if (pBlkIdx->tid > TABLE_TID(pTable)) {
pReadh->pBlkIdx = NULL;
break; break;
} else if (pBlkIdx->tid < TABLE_TID(pTable)) {
left = pReadh->cidx + 1;
} else { } else {
pReadh->cidx++; right = pReadh->cidx - 1;
} }
} }
if (left > right) {
pReadh->pBlkIdx = NULL;
}
} else { } else {
pReadh->pBlkIdx = NULL; pReadh->pBlkIdx = NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册