diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 1facab0b34e271394c37486ee2b900ec89c8f71c..7630cc1a98689260f2eb770870e56ee5e43e00f1 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1744,6 +1744,9 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; STableQueryInfo* item = pRuntimeEnv->current; + SQueryAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; + bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); + // primary timestamp column SColumnInfoData* pColInfoData = taosArrayGet(pSDataBlock->pDataBlock, 0); @@ -1783,7 +1786,9 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); } - doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, + int32_t forwardStep = pInfo->numOfRows; + int32_t offset = (ascQuery) ? pInfo->start : pInfo->start + forwardStep - 1; + doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, offset, forwardStep, tsList, pSDataBlock->info.rows, pOperator->numOfOutput); pInfo->curWindow.skey = tsList[j]; @@ -1803,7 +1808,9 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); } - doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, + int32_t forwardStep = pInfo->numOfRows; + int32_t offset = (ascQuery) ? pInfo->start : pInfo->start + forwardStep - 1; + doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, offset, forwardStep, tsList, pSDataBlock->info.rows, pOperator->numOfOutput); } diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index 95c7f81ed68d0ef8f303ee45deda89e347d163d9..6673f1308177fe39960297f947172fdb67ffad5e 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -618,6 +618,13 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { op = OP_Project; taosArrayPush(plan, &op); } + + int32_t orderColId = pQueryAttr->order.orderColId; + + if (orderColId != INT32_MIN) { + op = OP_Order; + taosArrayPush(plan, &op); + } } else if (pQueryAttr->stateWindow) { op = OP_StateWindow; taosArrayPush(plan, &op);