From 5d9b00f0b33542360410ca098274ee42377c17c9 Mon Sep 17 00:00:00 2001 From: Andy Fan Date: Tue, 5 Apr 2022 15:08:33 +0800 Subject: [PATCH v1 3/3] Try to remove enum WindowAggStatus. WINDOWAGG_DONE is left only, but it can be replaced with previous all_done field. --- src/backend/executor/nodeWindowAgg.c | 80 +++++++++++----------------- 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index ad592e9283a..05e2944e12a 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -2116,29 +2116,9 @@ ExecWindowAgg(PlanState *pstate) /* we don't need to invalidate grouptail here; see below */ } -retry: - /* - * Spool all tuples up to and including the current row, if we haven't - * already - */ - if (winstate->status == WINDOWAGG_PASSTHROUGH ) - { - /* All the next tuples in this partition is not interest. */ - - /* let's read all of them in once. */ - spool_tuples(winstate, -1); - - /* - * And stop handling them one by one. we just act as we have - * read up to the last tuple. - */ - winstate->currentpos = winstate->spooled_rows; - } - else - { - spool_tuples(winstate, winstate->currentpos); - } + spool_tuples(winstate, winstate->currentpos); +retry: /* Move to the next partition if we reached the end of this partition */ if (winstate->partition_spooled && winstate->currentpos >= winstate->spooled_rows) @@ -2149,9 +2129,6 @@ retry: { begin_partition(winstate); Assert(winstate->spooled_rows > 0); - - /* Come out of pass-through mode when changing partition */ - winstate->status = WINDOWAGG_RUN; } else { @@ -2207,31 +2184,27 @@ retry: elog(ERROR, "unexpected end of tuplestore"); } - /* don't evaluate the window functions when we're in pass-through mode */ - if (winstate->status == WINDOWAGG_RUN) + /* + * Evaluate true window functions + */ + numfuncs = winstate->numfuncs; + for (i = 0; i < numfuncs; i++) { - /* - * Evaluate true window functions - */ - numfuncs = winstate->numfuncs; - for (i = 0; i < numfuncs; i++) - { - WindowStatePerFunc perfuncstate = &(winstate->perfunc[i]); - - if (perfuncstate->plain_agg) - continue; - eval_windowfunction(winstate, perfuncstate, - &(econtext->ecxt_aggvalues[perfuncstate->wfuncstate->wfuncno]), - &(econtext->ecxt_aggnulls[perfuncstate->wfuncstate->wfuncno])); - } + WindowStatePerFunc perfuncstate = &(winstate->perfunc[i]); - /* - * Evaluate aggregates - */ - if (winstate->numaggs > 0) - eval_windowaggregates(winstate); + if (perfuncstate->plain_agg) + continue; + eval_windowfunction(winstate, perfuncstate, + &(econtext->ecxt_aggvalues[perfuncstate->wfuncstate->wfuncno]), + &(econtext->ecxt_aggnulls[perfuncstate->wfuncstate->wfuncno])); } + /* + * Evaluate aggregates + */ + if (winstate->numaggs > 0) + eval_windowaggregates(winstate); + /* * If we have created auxiliary read pointers for the frame or group * boundaries, force them to be kept up-to-date, because we don't know @@ -2268,8 +2241,7 @@ retry: * window function or if we can stop completely. */ econtext->ecxt_scantuple = slot; - if (winstate->status == WINDOWAGG_RUN && - !ExecQual(winstate->runcondition, econtext)) + if (!ExecQual(winstate->runcondition, econtext)) { /* * When the runcondition is no longer true we can either abort @@ -2280,7 +2252,17 @@ retry: */ if (winstate->use_pass_through) { - winstate->status = WINDOWAGG_PASSTHROUGH; + /* All the next tuples in this partition is not interest. */ + + /* let's read all of them in once. */ + spool_tuples(winstate, -1); + + /* + * And stop handling them one by one. we just act as we have + * read up to the last tuple. + */ + winstate->currentpos = winstate->spooled_rows; + goto retry; } else -- 2.21.0