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

Commitbb94ce4

Browse files
committed
Teach reparameterize_path() to handle AppendPaths.
If we're inside a lateral subquery, there may be no unparameterized pathsfor a particular child relation of an appendrel, in which case we *must*be able to create similarly-parameterized paths for each other childrelation, else the planner will fail with "could not devise a query planfor the given query". This means that there are situations where we'dbetter be able to reparameterize at least one path for each child.This calls into question the assumption in reparameterize_path() thatit can just punt if it feels like it. However, the only case that isknown broken right now is where the child is itself an appendrel so thatall its paths are AppendPaths. (I think possibly I disregarded that inthe original coding on the theory that nested appendrels would get foldedtogether --- but that only happens *after* reparameterize_path(), so it'snot excused from handling a child AppendPath.) Given that this code's beenlike this since 9.3 when LATERAL was introduced, it seems likely we'd haveheard of other cases by now if there were a larger problem.Per report from Elvis Pranskevichus. Back-patch to 9.3.Discussion:https://postgr.es/m/5981018.zdth1YWmNy@hammer.magicstack.net
1 parent95be5ce commitbb94ce4

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

‎src/backend/optimizer/util/pathnode.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,40 @@ reparameterize_path(PlannerInfo *root, Path *path,
35403540
spath->path.pathkeys,
35413541
required_outer);
35423542
}
3543+
caseT_Append:
3544+
{
3545+
AppendPath*apath= (AppendPath*)path;
3546+
List*childpaths=NIL;
3547+
List*partialpaths=NIL;
3548+
inti;
3549+
ListCell*lc;
3550+
3551+
/* Reparameterize the children */
3552+
i=0;
3553+
foreach(lc,apath->subpaths)
3554+
{
3555+
Path*spath= (Path*)lfirst(lc);
3556+
3557+
spath=reparameterize_path(root,spath,
3558+
required_outer,
3559+
loop_count);
3560+
if (spath==NULL)
3561+
returnNULL;
3562+
/* We have to re-split the regular and partial paths */
3563+
if (i<apath->first_partial_path)
3564+
childpaths=lappend(childpaths,spath);
3565+
else
3566+
partialpaths=lappend(partialpaths,spath);
3567+
i++;
3568+
}
3569+
return (Path*)
3570+
create_append_path(rel,childpaths,partialpaths,
3571+
required_outer,
3572+
apath->path.parallel_workers,
3573+
apath->path.parallel_aware,
3574+
apath->partitioned_rels,
3575+
-1);
3576+
}
35433577
default:
35443578
break;
35453579
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5188,6 +5188,25 @@ select * from
51885188
Output: 3
51895189
(11 rows)
51905190

5191+
-- check handling of nested appendrels inside LATERAL
5192+
select * from
5193+
((select 2 as v) union all (select 3 as v)) as q1
5194+
cross join lateral
5195+
((select * from
5196+
((select 4 as v) union all (select 5 as v)) as q3)
5197+
union all
5198+
(select q1.v)
5199+
) as q2;
5200+
v | v
5201+
---+---
5202+
2 | 4
5203+
2 | 5
5204+
2 | 2
5205+
3 | 4
5206+
3 | 5
5207+
3 | 3
5208+
(6 rows)
5209+
51915210
-- check we don't try to do a unique-ified semijoin with LATERAL
51925211
explain (verbose, costs off)
51935212
select * from

‎src/test/regress/sql/join.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,16 @@ select * from
16821682
select*from (select3as z offset0) zwherez.z=x.x
16831683
) zzonzz.z=y.y;
16841684

1685+
-- check handling of nested appendrels inside LATERAL
1686+
select*from
1687+
((select2as v)union all (select3as v))as q1
1688+
cross join lateral
1689+
((select*from
1690+
((select4as v)union all (select5as v))as q3)
1691+
union all
1692+
(selectq1.v)
1693+
)as q2;
1694+
16851695
-- check we don't try to do a unique-ified semijoin with LATERAL
16861696
explain (verbose, costs off)
16871697
select*from

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp