Merge pull request #17236 from taosdata/feature/3_liaohj
enh(query): optimize the perf for ordinary table query
This commit is contained in:
commit
329b76edad
|
@ -235,8 +235,13 @@ static int32_t binarySearchForStartRowIndex(uint64_t* uidList, int32_t num, uint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool queryChildTable(uint64_t suid) {
|
||||||
|
return suid != 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid,
|
int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid,
|
||||||
uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange, SSttBlockLoadInfo* pBlockLoadInfo) {
|
uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange, SSttBlockLoadInfo* pBlockLoadInfo,
|
||||||
|
const char* idStr) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
*pIter = taosMemoryCalloc(1, sizeof(SLDataIter));
|
*pIter = taosMemoryCalloc(1, sizeof(SLDataIter));
|
||||||
if (*pIter == NULL) {
|
if (*pIter == NULL) {
|
||||||
|
@ -252,15 +257,22 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
|
||||||
(*pIter)->timeWindow = *pTimeWindow;
|
(*pIter)->timeWindow = *pTimeWindow;
|
||||||
|
|
||||||
(*pIter)->pBlockLoadInfo = pBlockLoadInfo;
|
(*pIter)->pBlockLoadInfo = pBlockLoadInfo;
|
||||||
if (taosArrayGetSize(pBlockLoadInfo->aSttBlk) == 0) {
|
|
||||||
|
size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk);
|
||||||
|
if (size == 0) {
|
||||||
|
int64_t st = taosGetTimestampUs();
|
||||||
|
|
||||||
code = tsdbReadSttBlk(pReader, iStt, pBlockLoadInfo->aSttBlk);
|
code = tsdbReadSttBlk(pReader, iStt, pBlockLoadInfo->aSttBlk);
|
||||||
if (code) {
|
if (code) {
|
||||||
goto _exit;
|
goto _exit;
|
||||||
} else {
|
}
|
||||||
size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk);
|
|
||||||
SArray* pTmp = taosArrayInit(size, sizeof(SSttBlk));
|
// only apply to the child tables, ordinary tables will not incur this filter procedure.
|
||||||
for(int32_t i = 0; i < size; ++i) {
|
if (queryChildTable(suid)) {
|
||||||
SSttBlk* p = taosArrayGet(pBlockLoadInfo->aSttBlk, i);
|
size = taosArrayGetSize(pBlockLoadInfo->aSttBlk);
|
||||||
|
SArray *pTmp = taosArrayInit(size, sizeof(SSttBlk));
|
||||||
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
|
SSttBlk *p = taosArrayGet(pBlockLoadInfo->aSttBlk, i);
|
||||||
if (p->suid == suid) {
|
if (p->suid == suid) {
|
||||||
taosArrayPush(pTmp, p);
|
taosArrayPush(pTmp, p);
|
||||||
}
|
}
|
||||||
|
@ -269,9 +281,12 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
|
||||||
taosArrayDestroy(pBlockLoadInfo->aSttBlk);
|
taosArrayDestroy(pBlockLoadInfo->aSttBlk);
|
||||||
pBlockLoadInfo->aSttBlk = pTmp;
|
pBlockLoadInfo->aSttBlk = pTmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double el = (taosGetTimestampUs() - st)/1000.0;
|
||||||
|
tsdbDebug("load the last file info completed, elapsed time:%.2fms, %s", el, idStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk);
|
size = taosArrayGetSize(pBlockLoadInfo->aSttBlk);
|
||||||
|
|
||||||
// find the start block
|
// find the start block
|
||||||
(*pIter)->iSttBlk = binarySearchForStartBlock(pBlockLoadInfo->aSttBlk->pData, size, uid, backward);
|
(*pIter)->iSttBlk = binarySearchForStartBlock(pBlockLoadInfo->aSttBlk->pData, size, uid, backward);
|
||||||
|
@ -493,7 +508,7 @@ int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFRead
|
||||||
|
|
||||||
for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) { // open all last file
|
for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) { // open all last file
|
||||||
struct SLDataIter* pIter = NULL;
|
struct SLDataIter* pIter = NULL;
|
||||||
code = tLDataIterOpen(&pIter, pFReader, i, pMTree->backward, suid, uid, pTimeWindow, pVerRange, &pMTree->pLoadInfo[i]);
|
code = tLDataIterOpen(&pIter, pFReader, i, pMTree->backward, suid, uid, pTimeWindow, pVerRange, &pMTree->pLoadInfo[i], pMTree->idStr);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue