From 68842b9c641507e71e793bcf62e27e2ae818ae50 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 10 Oct 2022 14:55:58 +0800 Subject: [PATCH] refactor: do some internal refactor. --- include/libs/function/function.h | 2 +- source/dnode/vnode/src/tsdb/tsdbMergeTree.c | 47 +++++++++++++++------ source/libs/function/src/builtins.c | 2 +- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/include/libs/function/function.h b/include/libs/function/function.h index 60c7b18367..1796956f96 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -54,7 +54,7 @@ typedef struct SFuncExecFuncs { FExecCombine combine; } SFuncExecFuncs; -#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results +#define MAX_INTERVAL_TIME_WINDOW 10000000 // maximum allowed time windows in final results #define TOP_BOTTOM_QUERY_LIMIT 100 #define FUNCTIONS_NAME_MAX_LENGTH 16 diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index bf94ae68ff..4a6f677787 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -265,24 +265,43 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t // only apply to the child tables, ordinary tables will not incur this filter procedure. size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); - SArray *pTmp = taosArrayInit(size, sizeof(SSttBlk)); - for (int32_t i = 0; i < size; ++i) { - SSttBlk *p = taosArrayGet(pBlockLoadInfo->aSttBlk, i); - uint64_t s = p->suid; - if (s < suid) { - continue; - } - if (s == suid) { - taosArrayPush(pTmp, p); - } else if (s > suid) { - break; + if (size > 1) { + SSttBlk *pStart = taosArrayGet(pBlockLoadInfo->aSttBlk, 0); + SSttBlk *pEnd = taosArrayGet(pBlockLoadInfo->aSttBlk, size - 1); + + // all identical + if (pStart->suid == pEnd->suid) { + if (pStart->suid == suid) { + // do nothing + } else if (pStart->suid != suid) { + // no qualified stt block existed + (*pIter)->iSttBlk = -1; + double el = (taosGetTimestampUs() - st)/1000.0; + tsdbDebug("load the last file info completed, elapsed time:%.2fms, %s", el, idStr); + return code; + } + } else { + SArray *pTmp = taosArrayInit(size, sizeof(SSttBlk)); + for (int32_t i = 0; i < size; ++i) { + SSttBlk *p = taosArrayGet(pBlockLoadInfo->aSttBlk, i); + uint64_t s = p->suid; + if (s < suid) { + continue; + } + + if (s == suid) { + taosArrayPush(pTmp, p); + } else if (s > suid) { + break; + } + } + + taosArrayDestroy(pBlockLoadInfo->aSttBlk); + pBlockLoadInfo->aSttBlk = pTmp; } } - taosArrayDestroy(pBlockLoadInfo->aSttBlk); - pBlockLoadInfo->aSttBlk = pTmp; - double el = (taosGetTimestampUs() - st)/1000.0; tsdbDebug("load the last file info completed, elapsed time:%.2fms, %s", el, idStr); } diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index e9415dc879..2308aaf214 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -662,7 +662,7 @@ static int32_t translateTopBot(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - if (pValue->datum.i < 1 || pValue->datum.i > 100) { + if (pValue->datum.i < 1 || pValue->datum.i > TOP_BOTTOM_QUERY_LIMIT) { return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); } -- GitLab