From 70fffcb63696b08c3c178368f1d89bdb3166a25b Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 1 Sep 2021 13:50:05 +0800 Subject: [PATCH] fix interval query issue --- src/query/src/qExecutor.c | 14 +++++++------- src/tsdb/src/tsdbRead.c | 26 +++++++++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 69d45c9c82..5cadb6a763 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -4099,7 +4099,7 @@ void setParamForStableStddevByColData(SQueryRuntimeEnv* pRuntimeEnv, SQLFunction * merged during merge stage. In this case, we need the pTableQueryInfo->lastResRows to decide if there * is a previous result generated or not. */ -void setIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY key) { +void setIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STimeWindow* winx, int32_t tid) { SQueryAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; STableQueryInfo *pTableQueryInfo = pRuntimeEnv->current; SResultRowInfo *pResultRowInfo = &pTableQueryInfo->resInfo; @@ -4108,7 +4108,9 @@ void setIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY key) { return; } - qDebug("0x%"PRIx64" update query window, %"PRId64" - %"PRId64", old:%"PRId64" - %"PRId64, GET_QID(pRuntimeEnv), key, pTableQueryInfo->win.ekey, + TSKEY key = QUERY_IS_ASC_QUERY(pQueryAttr)? winx->skey:winx->ekey; + + qDebug("0x%"PRIx64" update query window, tid:%d, %"PRId64" - %"PRId64", old:%"PRId64" - %"PRId64, GET_QID(pRuntimeEnv), tid, key, pTableQueryInfo->win.ekey, pTableQueryInfo->win.skey, pTableQueryInfo->win.ekey); pTableQueryInfo->win.skey = key; @@ -6035,7 +6037,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) { setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); - setIntervalQueryRange(pRuntimeEnv, pBlock->info.window.skey); + setIntervalQueryRange(pRuntimeEnv, &pBlock->info.window, pBlock->info.tid); hashIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex); } @@ -6090,7 +6092,8 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) { setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); - setIntervalQueryRange(pRuntimeEnv, pBlock->info.window.skey); + + setIntervalQueryRange(pRuntimeEnv, &pBlock->info.window, pBlock->info.tid); hashAllIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex); } @@ -6108,9 +6111,6 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) { return pIntervalInfo->pRes; } - - - static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; STableQueryInfo* item = pRuntimeEnv->current; diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index f6aef766d5..582de1c286 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -859,13 +859,25 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; } return r1; - } else if (r1 < r2 && ASCENDING_TRAVERSE(order)) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; - return r1; - } - else { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - return r2; + } else { + if (ASCENDING_TRAVERSE(order)) { + if (r1 < r2) { + pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; + return r1; + } else { + pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; + return r2; + } + } else { + if (r1 < r2) { + pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; + return r2; + } else { + pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; + return r1; + } + } + } } -- GitLab