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

Commit 94985c2

Browse files
committed
Add subquery pullup handling for WindowClause runCondition
9d9c02c added code to allow WindowAgg to take some shortcuts when a monotonic WindowFunc reached some value that it could never come back from due to the function's monotonic nature. That commit added a runCondition field to WindowClause to store the condition which, when it becomes false we can start taking shortcuts in nodeWindowAgg.c. Here we fix an issue where subquery pullups didn't properly update the runCondition to update the Vars to properly reference the new query level. Here we also add a missing call to preprocess_expression() for the WindowClause's runCondtion. The WindowFuncs in the targetlist will have had this process done, so we must also do it for the WindowFuncs in the runCondition so that they can be correctly found in the targetlist during setrefs.c Bug: #17709 Reported-by: Alexey Makhmutov Author: Richard Guo, David Rowley Discussion: https://postgr.es/m/17709-4f557160e3e8ee9a@postgresql.org Backpatch-through: 15, where 9d9c02c was introduced
1 parent 66dcb09 commit 94985c2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/backend/optimizer/plan/planner.c

+3
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
833833
EXPRKIND_LIMIT);
834834
wc->endOffset = preprocess_expression(root, wc->endOffset,
835835
EXPRKIND_LIMIT);
836+
wc->runCondition = (List *) preprocess_expression(root,
837+
(Node *) wc->runCondition,
838+
EXPRKIND_TARGET);
836839
}
837840

838841
parse->limitOffset = preprocess_expression(root, parse->limitOffset,

src/backend/optimizer/prep/prepjointree.c

+9
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
21202120
pullup_replace_vars((Node *) parse->targetList, rvcontext);
21212121
parse->returningList = (List *)
21222122
pullup_replace_vars((Node *) parse->returningList, rvcontext);
2123+
2124+
foreach(lc, parse->windowClause)
2125+
{
2126+
WindowClause *wc = lfirst_node(WindowClause, lc);
2127+
2128+
if (wc->runCondition != NIL)
2129+
wc->runCondition = (List *)
2130+
pullup_replace_vars((Node *) wc->runCondition, rvcontext);
2131+
}
21232132
if (parse->onConflict)
21242133
{
21252134
parse->onConflict->onConflictSet = (List *)

0 commit comments

Comments
 (0)