From 40380ef9c1862f472288be1df19eae181dfbd19a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 10 Jul 2022 10:15:27 +0800 Subject: [PATCH] refactor: do internal refactor. --- include/common/tcommon.h | 4 +- source/dnode/vnode/inc/vnode.h | 2 +- source/dnode/vnode/src/tsdb/tsdbRead.c | 8 +- source/libs/executor/inc/executorimpl.h | 7 -- source/libs/executor/src/executil.c | 94 +++++++++++++++++-- source/libs/executor/src/executorimpl.c | 16 ++-- source/libs/executor/src/scanoperator.c | 73 ++++---------- source/libs/executor/src/timewindowoperator.c | 88 +---------------- 8 files changed, 121 insertions(+), 171 deletions(-) diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 28d771bbbd..614e7c9974 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -155,8 +155,8 @@ typedef struct SQueryTableDataCond { int32_t numOfCols; SColumnInfo* colList; int32_t type; // data block load type: - int32_t numOfTWindows; - STimeWindow* twindows; +// int32_t numOfTWindows; + STimeWindow twindows; int64_t startVersion; int64_t endVersion; } SQueryTableDataCond; diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index ff29305b74..8ffa569865 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -133,7 +133,7 @@ bool tsdbNextDataBlock(STsdbReader *pReader); void tsdbRetrieveDataBlockInfo(STsdbReader *pReader, SDataBlockInfo *pDataBlockInfo); int32_t tsdbRetrieveDatablockSMA(STsdbReader *pReader, SColumnDataAgg ***pBlockStatis, bool *allHave); SArray *tsdbRetrieveDataBlock(STsdbReader *pTsdbReadHandle, SArray *pColumnIdList); -int32_t tsdbReaderReset(STsdbReader *pReader, SQueryTableDataCond *pCond, int32_t tWinIdx); +int32_t tsdbReaderReset(STsdbReader *pReader, SQueryTableDataCond *pCond); int32_t tsdbGetFileBlocksDistInfo(STsdbReader *pReader, STableBlockDistInfo *pTableBlockInfo); int64_t tsdbGetNumOfRowsInMemTable(STsdbReader *pHandle); void *tsdbGetIdx(SMeta *pMeta); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 9e01468fc7..f650480ff2 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -356,14 +356,14 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd initReaderStatus(&pReader->status); pReader->pTsdb = - getTsdbByRetentions(pVnode, pCond->twindows[0].skey, pVnode->config.tsdbCfg.retentions, idstr, &level); + getTsdbByRetentions(pVnode, pCond->twindows.skey, pVnode->config.tsdbCfg.retentions, idstr, &level); pReader->suid = pCond->suid; pReader->order = pCond->order; pReader->capacity = 4096; pReader->idStr = (idstr != NULL) ? strdup(idstr) : NULL; pReader->verRange = getQueryVerRange(pVnode, pCond, level); pReader->type = pCond->type; - pReader->window = updateQueryTimeWindow(pVnode->pTsdb, pCond->twindows); + pReader->window = updateQueryTimeWindow(pVnode->pTsdb, &pCond->twindows); ASSERT(pCond->numOfCols > 0); @@ -2954,7 +2954,7 @@ SArray* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) { return pReader->pResBlock->pDataBlock; } -int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond, int32_t tWinIdx) { +int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { if (isEmptyQueryTimeWindow(&pReader->window)) { return TSDB_CODE_SUCCESS; } @@ -2964,7 +2964,7 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond, int32_ pReader->status.loadFromFile = true; pReader->status.pTableIter = NULL; - pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows[tWinIdx]); + pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows); // allocate buffer in order to load data blocks from file memset(&pReader->suppInfo.tsColAgg, 0, sizeof(SColumnDataAgg)); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 72eddcfc51..c0983e29cc 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -278,9 +278,6 @@ typedef struct STableScanInfo { SScanInfo scanInfo; int32_t scanTimes; SNode* pFilterNode; // filter info, which is push down by optimizer - SqlFunctionCtx* pCtx; // which belongs to the direct upstream operator operator query context,todo: remove this by using SExprSup - int32_t* rowEntryInfoOffset; // todo: remove this by using SExprSup - SExprInfo* pExpr;// todo: remove this by using SExprSup SSDataBlock* pResBlock; SArray* pColMatchInfo; @@ -289,14 +286,10 @@ typedef struct STableScanInfo { int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan int32_t dataBlockLoadFlag; SInterval interval; // if the upstream is an interval operator, the interval info is also kept here to get the time window to check if current data block needs to be loaded. - SSampleExecInfo sample; // sample execution info - int32_t curTWinIdx; int32_t currentGroupId; int32_t currentTable; - uint64_t queryId; // todo remove it - uint64_t taskId; // todo remove it struct { uint64_t uid; diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index a9cbb89eec..ef16192614 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include #include "function.h" #include "functionMgt.h" #include "index.h" @@ -769,12 +770,9 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi // pCond->twindow = pTableScanNode->scanRange; // TODO: get it from stable scan node - pCond->numOfTWindows = 1; - pCond->twindows = taosMemoryCalloc(pCond->numOfTWindows, sizeof(STimeWindow)); - pCond->twindows[0] = pTableScanNode->scanRange; - pCond->suid = pTableScanNode->scan.suid; - - pCond->type = BLOCK_LOAD_OFFSET_ORDER; + pCond->twindows = pTableScanNode->scanRange; + pCond->suid = pTableScanNode->scan.suid; + pCond->type = BLOCK_LOAD_OFFSET_ORDER; pCond->startVersion = -1; pCond->endVersion = -1; // pCond->type = pTableScanNode->scanFlag; @@ -826,3 +824,87 @@ int32_t convertFillType(int32_t mode) { return type; } + +static void getInitialStartTimeWindow(SInterval* pInterval, TSKEY ts, STimeWindow* w, bool ascQuery) { + if (ascQuery) { + getAlignQueryTimeWindow(pInterval, pInterval->precision, ts, w); + } else { + // the start position of the first time window in the endpoint that spreads beyond the queried last timestamp + getAlignQueryTimeWindow(pInterval, pInterval->precision, ts, w); + + int64_t key = w->skey; + while (key < ts) { // moving towards end + key = taosTimeAdd(key, pInterval->sliding, pInterval->slidingUnit, pInterval->precision); + if (key >= ts) { + break; + } + + w->skey = key; + } + } +} + +static STimeWindow doCalculateTimeWindow(int64_t ts, SInterval* pInterval) { + STimeWindow w = {0}; + + if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') { + w.skey = taosTimeTruncate(ts, pInterval, pInterval->precision); + w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; + } else { + int64_t st = w.skey; + + if (st > ts) { + st -= ((st - ts + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; + } + + int64_t et = st + pInterval->interval - 1; + if (et < ts) { + st += ((ts - et + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; + } + + w.skey = st; + w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; + } + + return w; +} + +static STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order) { + int32_t factor = (order == TSDB_ORDER_ASC)? -1:1; + + STimeWindow win = *pWindow; + STimeWindow save = win; + while(win.skey <= ts && win.ekey >= ts) { + save = win; + win.skey = taosTimeAdd(win.skey, factor * pInterval->sliding, pInterval->slidingUnit, pInterval->precision); + win.ekey = taosTimeAdd(win.ekey, factor * pInterval->sliding, pInterval->slidingUnit, pInterval->precision); + } + + return save; +} + +// get the correct time window according to the handled timestamp +STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval, + int32_t order) { + STimeWindow w = {0}; + if (pResultRowInfo->cur.pageId == -1) { // the first window, from the previous stored value + getInitialStartTimeWindow(pInterval, ts, &w, (order == TSDB_ORDER_ASC)); + w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; + return w; + } + + w = getResultRowByPos(pBuf, &pResultRowInfo->cur)->win; + + // in case of typical time window, we can calculate time window directly. + if (w.skey > ts || w.ekey < ts) { + w = doCalculateTimeWindow(ts, pInterval); + } + + if (pInterval->interval != pInterval->sliding) { + // it is an sliding window query, in which sliding value is not equalled to + // interval value, and we need to find the first qualified time window. + w = getFirstQualifiedTimeWindow(ts, &w, pInterval, order); + } + + return w; +} \ No newline at end of file diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 359b342f93..b8ba72aa8a 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -1038,6 +1038,7 @@ static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockI #endif static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock) { +#if 0 SqlFunctionCtx* pCtx = pTableScanInfo->pCtx; uint32_t status = BLK_DATA_NOT_LOAD; @@ -1059,6 +1060,8 @@ static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSData } return status; +#endif + return 0; } int32_t loadDataBlockOnDemand(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, @@ -2887,12 +2890,11 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) { ASSERT(found); tsdbSetTableId(pInfo->dataReader, uid); - int64_t oldSkey = pInfo->cond.twindows[0].skey; - pInfo->cond.twindows[0].skey = ts + 1; - tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); - pInfo->cond.twindows[0].skey = oldSkey; + int64_t oldSkey = pInfo->cond.twindows.skey; + pInfo->cond.twindows.skey = ts + 1; + tsdbReaderReset(pInfo->dataReader, &pInfo->cond); + pInfo->cond.twindows.skey = oldSkey; pInfo->scanTimes = 0; - pInfo->curTWinIdx = 0; qDebug("tsdb reader offset seek to uid %ld ts %ld, table cur set to %d , all table num %d", uid, ts, pInfo->currentTable, tableSz); @@ -4347,9 +4349,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo cond.colList->type = TSDB_DATA_TYPE_TIMESTAMP; cond.colList->bytes = sizeof(TSKEY); - cond.numOfTWindows = 1; - cond.twindows = taosMemoryCalloc(1, sizeof(STimeWindow)); - cond.twindows[0] = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; + cond.twindows = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; cond.suid = pBlockNode->suid; cond.type = BLOCK_LOAD_OFFSET_ORDER; } diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 471d510385..db45ddb801 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -293,13 +293,8 @@ static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunction // setupQueryRangeForReverseScan(pTableScanInfo); pTableScanInfo->cond.order = TSDB_ORDER_DESC; - for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { - STimeWindow* pTWindow = &pTableScanInfo->cond.twindows[i]; - TSWAP(pTWindow->skey, pTWindow->ekey); - } - - SQueryTableDataCond* pCond = &pTableScanInfo->cond; - taosqsort(pCond->twindows, pCond->numOfTWindows, sizeof(STimeWindow), pCond, compareTimeWindow); + STimeWindow* pTWindow = &pTableScanInfo->cond.twindows; + TSWAP(pTWindow->skey, pTWindow->ekey); } int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, @@ -446,16 +441,10 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { // do the ascending order traverse in the first place. while (pTableScanInfo->scanTimes < pTableScanInfo->scanInfo.numOfAsc) { - while (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - SSDataBlock* p = doTableScanImpl(pOperator); - if (p != NULL) { - ASSERT(p->info.uid != 0); - return p; - } - pTableScanInfo->curTWinIdx += 1; - if (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, pTableScanInfo->curTWinIdx); - } + SSDataBlock* p = doTableScanImpl(pOperator); + if (p != NULL) { + ASSERT(p->info.uid != 0); + return p; } pTableScanInfo->scanTimes += 1; @@ -464,40 +453,25 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTableScanInfo->scanFlag = REPEAT_SCAN; qDebug("%s start to repeat ascending order scan data blocks due to query func required", GET_TASKID(pTaskInfo)); - for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { - STimeWindow* pWin = &pTableScanInfo->cond.twindows[i]; - qDebug("%s qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); - } + // do prepare for the next round table scan operation - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); - pTableScanInfo->curTWinIdx = 0; + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); } } int32_t total = pTableScanInfo->scanInfo.numOfAsc + pTableScanInfo->scanInfo.numOfDesc; if (pTableScanInfo->scanTimes < total) { if (pTableScanInfo->cond.order == TSDB_ORDER_ASC) { - prepareForDescendingScan(pTableScanInfo, pTableScanInfo->pCtx, 0); - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); - pTableScanInfo->curTWinIdx = 0; + prepareForDescendingScan(pTableScanInfo, pOperator->exprSupp.pCtx, 0); + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); } qDebug("%s start to descending order scan data blocks due to query func required", GET_TASKID(pTaskInfo)); - for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { - STimeWindow* pWin = &pTableScanInfo->cond.twindows[i]; - qDebug("%s qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); - } while (pTableScanInfo->scanTimes < total) { - while (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - SSDataBlock* p = doTableScanImpl(pOperator); - if (p != NULL) { - return p; - } - pTableScanInfo->curTWinIdx += 1; - if (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, pTableScanInfo->curTWinIdx); - } + SSDataBlock* p = doTableScanImpl(pOperator); + if (p != NULL) { + return p; } pTableScanInfo->scanTimes += 1; @@ -508,12 +482,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { qDebug("%s start to repeat descending order scan data blocks due to query func required", GET_TASKID(pTaskInfo)); - for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { - STimeWindow* pWin = &pTableScanInfo->cond.twindows[i]; - qDebug("%s qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); - } - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); - pTableScanInfo->curTWinIdx = 0; + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); } } } @@ -540,9 +509,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { } STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, pInfo->currentTable); tsdbSetTableId(pInfo->dataReader, pTableInfo->uid); - tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); + tsdbReaderReset(pInfo->dataReader, &pInfo->cond); pInfo->scanTimes = 0; - pInfo->curTWinIdx = 0; } } @@ -574,8 +542,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId); // tsdbSetTableList(pInfo->dataReader, tableList); - tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); - pInfo->curTWinIdx = 0; + tsdbReaderReset(pInfo->dataReader, &pInfo->cond); pInfo->scanTimes = 0; result = doTableScanGroup(pOperator); @@ -646,7 +613,6 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; pInfo->scanFlag = MAIN_SCAN; pInfo->pColMatchInfo = pColList; - pInfo->curTWinIdx = 0; pInfo->currentGroupId = -1; pOperator->name = "TableScanOperator"; // for debug purpose @@ -875,12 +841,7 @@ static void setGroupId(SStreamScanInfo* pInfo, SSDataBlock* pBlock, int32_t grou } void resetTableScanInfo(STableScanInfo* pTableScanInfo, STimeWindow* pWin) { - pTableScanInfo->cond.twindows[0] = *pWin; - pTableScanInfo->curTWinIdx = 0; - // tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); - // if (!pTableScanInfo->dataReader) { - // return false; - // } + pTableScanInfo->cond.twindows = *pWin; pTableScanInfo->scanTimes = 0; pTableScanInfo->currentGroupId = -1; } diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 987882706a..ebe645df4e 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -59,92 +59,6 @@ static void doCloseWindow(SResultRowInfo* pResultRowInfo, const SIntervalAggOper static TSKEY getStartTsKey(STimeWindow* win, const TSKEY* tsCols) { return tsCols == NULL ? win->skey : tsCols[0]; } -static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, TSKEY ts, STimeWindow* w, - bool ascQuery) { - if (ascQuery) { - getAlignQueryTimeWindow(pInterval, precision, ts, w); - } else { - // the start position of the first time window in the endpoint that spreads beyond the queried last timestamp - getAlignQueryTimeWindow(pInterval, precision, ts, w); - - int64_t key = w->skey; - while (key < ts) { // moving towards end - key = taosTimeAdd(key, pInterval->sliding, pInterval->slidingUnit, precision); - if (key >= ts) { - break; - } - - w->skey = key; - } - } -} - -static STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order) { - int32_t factor = (order == TSDB_ORDER_ASC)? -1:1; - - STimeWindow win = *pWindow; - STimeWindow save = win; - while(win.skey <= ts && win.ekey >= ts) { - save = win; - win.skey = taosTimeAdd(win.skey, factor * pInterval->sliding, pInterval->slidingUnit, pInterval->precision); - win.ekey = taosTimeAdd(win.ekey, factor * pInterval->sliding, pInterval->slidingUnit, pInterval->precision); - } - - return save; -} - -static STimeWindow doCalculateTimeWindow(int64_t ts, SInterval* pInterval) { - STimeWindow w = {0}; - - if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') { - w.skey = taosTimeTruncate(ts, pInterval, pInterval->precision); - w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; - } else { - int64_t st = w.skey; - - if (st > ts) { - st -= ((st - ts + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; - } - - int64_t et = st + pInterval->interval - 1; - if (et < ts) { - st += ((ts - et + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; - } - - w.skey = st; - w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; - } - - return w; -} - -// todo do refactor -// get the correct time window according to the handled timestamp -STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval, - int32_t order) { - STimeWindow w = {0}; - if (pResultRowInfo->cur.pageId == -1) { // the first window, from the previous stored value - getInitialStartTimeWindow(pInterval, pInterval->precision, ts, &w, (order == TSDB_ORDER_ASC)); - w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; - return w; - } - - w = getResultRowByPos(pBuf, &pResultRowInfo->cur)->win; - - // in case of typical time window, we can calculate time window directly. - if (w.skey > ts || w.ekey < ts) { - w = doCalculateTimeWindow(ts, pInterval); - } - - if (pInterval->interval != pInterval->sliding) { - // it is an sliding window query, in which sliding value is not equalled to - // interval value, and we need to find the first qualified time window. - w = getFirstQualifiedTimeWindow(ts, &w, pInterval, order); - } - - return w; -} - static int32_t setTimeWindowOutputBuf(SResultRowInfo* pResultRowInfo, STimeWindow* win, bool masterscan, SResultRow** pResult, int64_t tableGroupId, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup, @@ -4679,7 +4593,7 @@ static int32_t outputPrevIntervalResult(SOperatorInfo* pOperatorInfo, uint64_t t continue; } STimeWindow* prevWin = &prevGrpWin->window; - if ((ascScan && newWin->skey > prevWin->ekey || (!ascScan) && newWin->skey < prevWin->ekey)) { + if ((ascScan && newWin->skey > prevWin->ekey) || ((!ascScan) && newWin->skey < prevWin->ekey)) { finalizeWindowResult(pOperatorInfo, tableGroupId, prevWin, pResultBlock); tdListPopNode(miaInfo->groupIntervals, listNode); } -- GitLab