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

Commitc5e59bb

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 parentbfe23f8 commitc5e59bb

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,30 @@ reparameterize_path(PlannerInfo *root, Path *path,
34233423
spath->path.pathkeys,
34243424
required_outer);
34253425
}
3426+
caseT_Append:
3427+
{
3428+
AppendPath*apath= (AppendPath*)path;
3429+
List*childpaths=NIL;
3430+
ListCell*lc;
3431+
3432+
/* Reparameterize the children */
3433+
foreach(lc,apath->subpaths)
3434+
{
3435+
Path*spath= (Path*)lfirst(lc);
3436+
3437+
spath=reparameterize_path(root,spath,
3438+
required_outer,
3439+
loop_count);
3440+
if (spath==NULL)
3441+
returnNULL;
3442+
childpaths=lappend(childpaths,spath);
3443+
}
3444+
return (Path*)
3445+
create_append_path(rel,childpaths,
3446+
required_outer,
3447+
apath->path.parallel_workers,
3448+
apath->partitioned_rels);
3449+
}
34263450
default:
34273451
break;
34283452
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5154,6 +5154,25 @@ select * from
51545154
Output: 3
51555155
(11 rows)
51565156

5157+
-- check handling of nested appendrels inside LATERAL
5158+
select * from
5159+
((select 2 as v) union all (select 3 as v)) as q1
5160+
cross join lateral
5161+
((select * from
5162+
((select 4 as v) union all (select 5 as v)) as q3)
5163+
union all
5164+
(select q1.v)
5165+
) as q2;
5166+
v | v
5167+
---+---
5168+
2 | 4
5169+
2 | 5
5170+
2 | 2
5171+
3 | 4
5172+
3 | 5
5173+
3 | 3
5174+
(6 rows)
5175+
51575176
-- check we don't try to do a unique-ified semijoin with LATERAL
51585177
explain (verbose, costs off)
51595178
select * from

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

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

1671+
-- check handling of nested appendrels inside LATERAL
1672+
select*from
1673+
((select2as v)union all (select3as v))as q1
1674+
cross join lateral
1675+
((select*from
1676+
((select4as v)union all (select5as v))as q3)
1677+
union all
1678+
(selectq1.v)
1679+
)as q2;
1680+
16711681
-- check we don't try to do a unique-ified semijoin with LATERAL
16721682
explain (verbose, costs off)
16731683
select*from

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp