diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index 575f7ee8f43a4a4bc7c7aeec8f062e0a829bac63..251d4079e3cc186636d032427d2d106c218f47ee 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -808,18 +808,19 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource * } } -void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo *pQueryInfo, - SFillInfo *pFillInfo) { +void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo *pQueryInfo, SFillInfo *pFillInfo) { // discard following dataset in the same group and reset the interpolation information STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - int16_t prec = tinfo.precision; - int64_t stime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.skey : pQueryInfo->window.ekey; - int64_t revisedSTime = - taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, prec); - taosResetFillInfo(pFillInfo, revisedSTime); + if (pFillInfo != NULL) { + int64_t stime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.skey : pQueryInfo->window.ekey; + int64_t revisedSTime = + taosGetIntervalStartTimestamp(stime, pQueryInfo->slidingTime, pQueryInfo->slidingTimeUnit, tinfo.precision); + + taosResetFillInfo(pFillInfo, revisedSTime); + } pLocalReducer->discard = true; pLocalReducer->discardData->num = 0; @@ -915,13 +916,12 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo if (pQueryInfo->limit.limit >= 0 && pRes->numOfClauseTotal > pQueryInfo->limit.limit) { /* impose the limitation of output rows on the final result */ int32_t prevSize = pFinalDataPage->num; - int32_t overFlow = pRes->numOfClauseTotal - pQueryInfo->limit.limit; - - assert(overFlow < pRes->numOfRows); + int32_t overflow = pRes->numOfClauseTotal - pQueryInfo->limit.limit; + assert(overflow < pRes->numOfRows); pRes->numOfClauseTotal = pQueryInfo->limit.limit; - pRes->numOfRows -= overFlow; - pFinalDataPage->num -= overFlow; + pRes->numOfRows -= overflow; + pFinalDataPage->num -= overflow; tColModelCompact(pLocalReducer->resColModel, pFinalDataPage, prevSize); @@ -988,13 +988,13 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo if (pRes->numOfRows > 0) { if (pQueryInfo->limit.limit >= 0 && pRes->numOfClauseTotal > pQueryInfo->limit.limit) { - int32_t overFlow = pRes->numOfClauseTotal - pQueryInfo->limit.limit; - pRes->numOfRows -= overFlow; + int32_t overflow = pRes->numOfClauseTotal - pQueryInfo->limit.limit; + pRes->numOfRows -= overflow; assert(pRes->numOfRows >= 0); pRes->numOfClauseTotal = pQueryInfo->limit.limit; - pFinalDataPage->num -= overFlow; + pFinalDataPage->num -= overflow; /* set remain data to be discarded, and reset the interpolation information */ savePrevRecordAndSetupInterpoInfo(pLocalReducer, pQueryInfo, pFillInfo); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index bd61117a8508c2d42f6f5d0bf02c74ef2104acfd..e148bcb58e924b55033640265f2ca8fe27112948 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -3030,11 +3030,13 @@ static void updateTableQueryInfoForReverseScan(SQuery *pQuery, STableQueryInfo * // order has change already! int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); - if (!QUERY_IS_ASC_QUERY(pQuery)) { - assert(pTableQueryInfo->win.ekey >= pTableQueryInfo->lastKey + step); - } else { - assert(pTableQueryInfo->win.ekey <= pTableQueryInfo->lastKey + step); - } + + // TODO validate the assertion +// if (!QUERY_IS_ASC_QUERY(pQuery)) { +// assert(pTableQueryInfo->win.ekey >= pTableQueryInfo->lastKey + step); +// } else { +// assert(pTableQueryInfo->win.ekey <= pTableQueryInfo->lastKey + step); +// } pTableQueryInfo->win.ekey = pTableQueryInfo->lastKey + step; @@ -3113,7 +3115,7 @@ void disableFuncInReverseScan(SQInfo *pQInfo) { void switchCtxOrder(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { - SWITCH_ORDER(pRuntimeEnv->pCtx[i] .order); + SWITCH_ORDER(pRuntimeEnv->pCtx[i].order); } } @@ -4384,10 +4386,11 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) { SArray *pDataBlock = loadDataBlockOnDemand(pRuntimeEnv, pQueryHandle, &blockInfo, &pStatis); - TSKEY nextKey = blockInfo.window.skey; if (!isIntervalQuery(pQuery)) { - setExecutionContext(pQInfo, &pTableQueryInfo->id, pTableQueryInfo->groupIdx, nextKey); + int32_t step = QUERY_IS_ASC_QUERY(pQuery)? 1:-1; + setExecutionContext(pQInfo, &pTableQueryInfo->id, pTableQueryInfo->groupIdx, blockInfo.window.ekey + step); } else { // interval query + TSKEY nextKey = blockInfo.window.skey; setIntervalQueryRange(pQInfo, nextKey); int32_t ret = setAdditionalInfo(pQInfo, &pTableQueryInfo->id, pTableQueryInfo);