From c5e094efd0fd053914cbc8d1954c0e1d8728889a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 9 Oct 2022 14:34:10 +0800 Subject: [PATCH] enh(query): optimize the perf for ordinary table query with data in last file. --- source/dnode/vnode/src/tsdb/tsdbMergeTree.c | 23 ++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 7e6a0d04ff..ef1650a8dc 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -235,6 +235,10 @@ 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, uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange, SSttBlockLoadInfo* pBlockLoadInfo) { int32_t code = 0; @@ -252,15 +256,20 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t (*pIter)->timeWindow = *pTimeWindow; (*pIter)->pBlockLoadInfo = pBlockLoadInfo; - if (taosArrayGetSize(pBlockLoadInfo->aSttBlk) == 0) { + + size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); + if (size == 0) { code = tsdbReadSttBlk(pReader, iStt, pBlockLoadInfo->aSttBlk); if (code) { goto _exit; - } else { - size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); - SArray* pTmp = taosArrayInit(size, sizeof(SSttBlk)); - for(int32_t i = 0; i < size; ++i) { - SSttBlk* p = taosArrayGet(pBlockLoadInfo->aSttBlk, i); + } + + // only apply to the child tables, ordinary tables will not incur this filter procedure. + if (queryChildTable(suid)) { + 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) { taosArrayPush(pTmp, p); } @@ -271,7 +280,7 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t } } - size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); + size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); // find the start block (*pIter)->iSttBlk = binarySearchForStartBlock(pBlockLoadInfo->aSttBlk->pData, size, uid, backward); -- GitLab