Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7027dd4

Browse files
committed
Remove deduplication logic from find_window_functions
This code thought it was optimizing WindowAgg evaluation by getting rid of duplicate WindowFuncs, but it turns out all it does today is lead to cost-underestimations and makes it possible that optimize_window_clauses could miss some of the WindowFuncs that must receive an updated winref. The deduplication likely was useful when it was first added, but since the projection code was changed in b8d7f05, the list of WindowFuncs gathered by find_window_functions isn't used during execution. Instead, the expression evaluation code will process the node's targetlist to find the WindowFuncs. The reason the deduplication could cause issues for optimize_window_clauses() is because if a WindowFunc is moved to another WindowClause, the winref is adjusted to reference the new WindowClause. If any duplicate WindowFuncs were discarded in find_window_functions() then the WindowFuncLists may not include all the WindowFuncs that need their winref adjusted. This could lead to an error message such as: ERROR: WindowFunc with winref 2 assigned to WindowAgg with winref 1 The back-branches will receive a different fix so that the WindowAgg costs are not affected. Author: Meng Zhang <[email protected]> Reviewed-by: David Rowley <[email protected]> Discussion: https://postgr.es/m/CAErYLFAuxmW0UVdgrz7iiuNrxGQnFK_OP9hBD5CUzRgjrVrz=Q@mail.gmail.com
1 parent 6ceef94 commit 7027dd4

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,10 @@ find_window_functions_walker(Node *node, WindowFuncLists *lists)
261261
if (wfunc->winref > lists->maxWinRef)
262262
elog(ERROR, "WindowFunc contains out-of-range winref %u",
263263
wfunc->winref);
264-
/* eliminate duplicates, so that we avoid repeated computation */
265-
if (!list_member(lists->windowFuncs[wfunc->winref], wfunc))
266-
{
267-
lists->windowFuncs[wfunc->winref] =
268-
lappend(lists->windowFuncs[wfunc->winref], wfunc);
269-
lists->numWindowFuncs++;
270-
}
264+
265+
lists->windowFuncs[wfunc->winref] =
266+
lappend(lists->windowFuncs[wfunc->winref], wfunc);
267+
lists->numWindowFuncs++;
271268

272269
/*
273270
* We assume that the parser checked that there are no window

0 commit comments

Comments
 (0)