Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 25675c4

Browse files
committed
Fix unnecessary use of moving-aggregate mode with non-moving frame.
When a plain aggregate is used as a window function, and the window frame start is specified as UNBOUNDED PRECEDING, the frame's head cannot move so we do not need to use moving-aggregate mode. The check for that was put into initialize_peragg(), failing to notice that ExecInitWindowAgg() calls that function before it's filled in winstate->frameOptions. Since makeNode() would have zeroed the field, this didn't provoke uninitialized-value complaints, nor would the erroneous decision have resulted in more than a little inefficiency. Still, it's wrong, so move the initialization of winstate->frameOptions earlier to make it work properly. While here, also fix a thinko in a comment. Both errors crept in in commit a9d9acb which introduced the moving-aggregate mode. Spotted by Vallimaharajan G. Back-patch to all supported branches. Discussion: https://postgr.es/m/18e7f2a5167.fe36253866818.977923893562469143@zohocorp.com
1 parent a8b7408 commit 25675c4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/backend/executor/nodeWindowAgg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,9 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags)
22732273
winstate->ss.ps.state = estate;
22742274
winstate->ss.ps.ExecProcNode = ExecWindowAgg;
22752275

2276+
/* copy frame options to state node for easy access */
2277+
winstate->frameOptions = frameOptions;
2278+
22762279
/*
22772280
* Create expression contexts. We need two, one for per-input-tuple
22782281
* processing and one for per-output-tuple processing. We cheat a little
@@ -2500,9 +2503,6 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags)
25002503
winstate->agg_winobj = agg_winobj;
25012504
}
25022505

2503-
/* copy frame options to state node for easy access */
2504-
winstate->frameOptions = frameOptions;
2505-
25062506
/* initialize frame bound offset expressions */
25072507
winstate->startOffset = ExecInitExpr((Expr *) node->startOffset,
25082508
(PlanState *) winstate);
@@ -2653,7 +2653,7 @@ initialize_peragg(WindowAggState *winstate, WindowFunc *wfunc,
26532653

26542654
/*
26552655
* Figure out whether we want to use the moving-aggregate implementation,
2656-
* and collect the right set of fields from the pg_attribute entry.
2656+
* and collect the right set of fields from the pg_aggregate entry.
26572657
*
26582658
* It's possible that an aggregate would supply a safe moving-aggregate
26592659
* implementation and an unsafe normal one, in which case our hand is

0 commit comments

Comments
 (0)