From 211e1502dbe2ab7d9aeb2c785c79123eb135f3b4 Mon Sep 17 00:00:00 2001 From: Andy Fan Date: Tue, 5 Apr 2022 14:41:48 +0800 Subject: [PATCH v1 1/3] When we are in PASSTHROUGH mode, all the following tuples in this partition is not interesting, so we quickly ignore all of them. --- src/backend/executor/nodeWindowAgg.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index 869dcd74dff..f8792407773 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -2120,7 +2120,23 @@ ExecWindowAgg(PlanState *pstate) * Spool all tuples up to and including the current row, if we haven't * already */ - spool_tuples(winstate, winstate->currentpos); + 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); + } /* Move to the next partition if we reached the end of this partition */ if (winstate->partition_spooled && -- 2.21.0