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

Commitd641b82

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 parent5b2da24 commitd641b82

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
@@ -4181,6 +4181,32 @@ SELECT * FROM
41814181
sales | 3 | 4800 | 08-01-2007 | 3 | 1 | 3 | 3 | 1
41824182
(2 rows)
41834183

4184+
-- Ensure we remove references to reduced outer joins as nulling rels in run
4185+
-- conditions
4186+
EXPLAIN (COSTS OFF)
4187+
SELECT 1 FROM
4188+
(SELECT ntile(e2.salary) OVER (PARTITION BY e1.depname) AS c
4189+
FROM empsalary e1 LEFT JOIN empsalary e2 ON TRUE
4190+
WHERE e1.empno = e2.empno) s
4191+
WHERE s.c = 1;
4192+
QUERY PLAN
4193+
---------------------------------------------------------
4194+
Subquery Scan on s
4195+
Filter: (s.c = 1)
4196+
-> WindowAgg
4197+
Run Condition: (ntile(e2.salary) OVER (?) <= 1)
4198+
-> Sort
4199+
Sort Key: e1.depname
4200+
-> Merge Join
4201+
Merge Cond: (e1.empno = e2.empno)
4202+
-> Sort
4203+
Sort Key: e1.empno
4204+
-> Seq Scan on empsalary e1
4205+
-> Sort
4206+
Sort Key: e2.empno
4207+
-> Seq Scan on empsalary e2
4208+
(14 rows)
4209+
41844210
-- Tests to ensure we don't push down the run condition when it's not valid to
41854211
-- do so.
41864212
-- 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
@@ -1368,6 +1368,15 @@ SELECT * FROM
13681368
FROM empsalary
13691369
) eWHERE rn<=1AND c1<=3AND nt<2;
13701370

1371+
-- Ensure we remove references to reduced outer joins as nulling rels in run
1372+
-- conditions
1373+
EXPLAIN (COSTS OFF)
1374+
SELECT1FROM
1375+
(SELECT ntile(e2.salary) OVER (PARTITION BYe1.depname)AS c
1376+
FROM empsalary e1LEFT JOIN empsalary e2ON TRUE
1377+
WHEREe1.empno=e2.empno) s
1378+
WHEREs.c=1;
1379+
13711380
-- Tests to ensure we don't push down the run condition when it's not valid to
13721381
-- do so.
13731382

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp