Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee95532

Browse files
committed
Handle WindowClause.runCondition in tree walker/mutator functions.
Commit9d9c02c, which added the notion of a "run condition" forwindow functions, neglected to teach nodeFuncs.c to process the newfield. Remarkably, that doesn't seem to have had any ill effectsbefore we invented Var.varnullingrels, but now it can cause visiblefailures in join-removal scenarios.I have no faith that there's not reachable problems in v15 too,so back-patch the code change to v15 where9d9c02c came in.The test case seems irrelevant to v15, though.Per bug #18277 from Zuming Jiang. Diagnosis and patch byRichard Guo.Discussion:https://postgr.es/m/18277-089ead83b329a2fd@postgresql.org
1 parent65ee2ed commitee95532

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

‎src/backend/nodes/nodeFuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,8 @@ expression_tree_walker_impl(Node *node,
22832283
return true;
22842284
if (WALK(wc->endOffset))
22852285
return true;
2286+
if (WALK(wc->runCondition))
2287+
return true;
22862288
}
22872289
break;
22882290
caseT_CTECycleClause:
@@ -2627,6 +2629,8 @@ query_tree_walker_impl(Query *query,
26272629
return true;
26282630
if (WALK(wc->endOffset))
26292631
return true;
2632+
if (WALK(wc->runCondition))
2633+
return true;
26302634
}
26312635
}
26322636

@@ -3312,6 +3316,7 @@ expression_tree_mutator_impl(Node *node,
33123316
MUTATE(newnode->orderClause,wc->orderClause,List*);
33133317
MUTATE(newnode->startOffset,wc->startOffset,Node*);
33143318
MUTATE(newnode->endOffset,wc->endOffset,Node*);
3319+
MUTATE(newnode->runCondition,wc->runCondition,List*);
33153320
return (Node*)newnode;
33163321
}
33173322
break;
@@ -3641,6 +3646,7 @@ query_tree_mutator_impl(Query *query,
36413646
FLATCOPY(newnode,wc,WindowClause);
36423647
MUTATE(newnode->startOffset,wc->startOffset,Node*);
36433648
MUTATE(newnode->endOffset,wc->endOffset,Node*);
3649+
MUTATE(newnode->runCondition,wc->runCondition,List*);
36443650

36453651
resultlist=lappend(resultlist, (Node*)newnode);
36463652
}

‎src/test/regress/expected/window.out

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,6 +3804,32 @@ SELECT * FROM
38043804
sales | 3 | 4800 | 08-01-2007 | 3 | 1 | 3 | 3 | 1
38053805
(2 rows)
38063806

3807+
-- Ensure we remove references to reduced outer joins as nulling rels in run
3808+
-- conditions
3809+
EXPLAIN (COSTS OFF)
3810+
SELECT 1 FROM
3811+
(SELECT ntile(e2.salary) OVER (PARTITION BY e1.depname) AS c
3812+
FROM empsalary e1 LEFT JOIN empsalary e2 ON TRUE
3813+
WHERE e1.empno = e2.empno) s
3814+
WHERE s.c = 1;
3815+
QUERY PLAN
3816+
---------------------------------------------------------
3817+
Subquery Scan on s
3818+
Filter: (s.c = 1)
3819+
-> WindowAgg
3820+
Run Condition: (ntile(e2.salary) OVER (?) <= 1)
3821+
-> Sort
3822+
Sort Key: e1.depname
3823+
-> Merge Join
3824+
Merge Cond: (e1.empno = e2.empno)
3825+
-> Sort
3826+
Sort Key: e1.empno
3827+
-> Seq Scan on empsalary e1
3828+
-> Sort
3829+
Sort Key: e2.empno
3830+
-> Seq Scan on empsalary e2
3831+
(14 rows)
3832+
38073833
-- Tests to ensure we don't push down the run condition when it's not valid to
38083834
-- do so.
38093835
-- Ensure we don't push down when the frame options show that the window

‎src/test/regress/sql/window.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,15 @@ SELECT * FROM
12361236
FROM empsalary
12371237
) eWHERE rn<=1AND c1<=3AND nt<2;
12381238

1239+
-- Ensure we remove references to reduced outer joins as nulling rels in run
1240+
-- conditions
1241+
EXPLAIN (COSTS OFF)
1242+
SELECT1FROM
1243+
(SELECT ntile(e2.salary) OVER (PARTITION BYe1.depname)AS c
1244+
FROM empsalary e1LEFT JOIN empsalary e2ON TRUE
1245+
WHEREe1.empno=e2.empno) s
1246+
WHEREs.c=1;
1247+
12391248
-- Tests to ensure we don't push down the run condition when it's not valid to
12401249
-- do so.
12411250

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp