Skip to content

Commit d4b754c

Browse files
committed
Ensure dummy paths have correct required_outer if rel is parameterized.
The assertions added by commits 34ea1ab et al found another problem: set_dummy_rel_pathlist and mark_dummy_rel were failing to label the dummy paths they create with the correct outer_relids, in case the relation is necessarily parameterized due to having lateral references in its tlist. It's likely that this has no user-visible consequences in production builds, at the moment; but still an assertion failure is a bad thing, so back-patch the fix. Per bug #15694 from Roman Zharkov (via Alexander Lakhin) and an independent report by Tushar Ahuja. Discussion: https://postgr.es/m/15694-74f2ca97e7044f7f@postgresql.org Discussion: https://postgr.es/m/7d72ab20-c725-3ce2-f99d-4e64dd8a0de6@enterprisedb.com
1 parent 0ca982a commit d4b754c

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,9 @@ set_dummy_rel_pathlist(RelOptInfo *rel)
17681768
rel->partial_pathlist = NIL;
17691769

17701770
/* Set up the dummy path */
1771-
add_path(rel, (Path *) create_append_path(rel, NIL, NULL, 0, NIL));
1771+
add_path(rel, (Path *) create_append_path(rel, NIL,
1772+
rel->lateral_relids,
1773+
0, NIL));
17721774

17731775
/*
17741776
* We set the cheapest-path fields immediately, just in case they were

src/backend/optimizer/path/joinrels.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,9 @@ mark_dummy_rel(RelOptInfo *rel)
12451245
rel->partial_pathlist = NIL;
12461246

12471247
/* Set up the dummy path */
1248-
add_path(rel, (Path *) create_append_path(rel, NIL, NULL, 0, NIL));
1248+
add_path(rel, (Path *) create_append_path(rel, NIL,
1249+
rel->lateral_relids,
1250+
0, NIL));
12491251

12501252
/* Set or update cheapest_total_path and related fields */
12511253
set_cheapest(rel);

src/test/regress/expected/join.out

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5291,6 +5291,35 @@ select * from
52915291
Output: 3
52925292
(11 rows)
52935293

5294+
-- check dummy rels with lateral references (bug #15694)
5295+
explain (verbose, costs off)
5296+
select * from int8_tbl i8 left join lateral
5297+
(select *, i8.q2 from int4_tbl where false) ss on true;
5298+
QUERY PLAN
5299+
--------------------------------------
5300+
Nested Loop Left Join
5301+
Output: i8.q1, i8.q2, f1, (i8.q2)
5302+
-> Seq Scan on public.int8_tbl i8
5303+
Output: i8.q1, i8.q2
5304+
-> Result
5305+
Output: f1, i8.q2
5306+
One-Time Filter: false
5307+
(7 rows)
5308+
5309+
explain (verbose, costs off)
5310+
select * from int8_tbl i8 left join lateral
5311+
(select *, i8.q2 from int4_tbl i1, int4_tbl i2 where false) ss on true;
5312+
QUERY PLAN
5313+
-----------------------------------------
5314+
Nested Loop Left Join
5315+
Output: i8.q1, i8.q2, f1, f1, (i8.q2)
5316+
-> Seq Scan on public.int8_tbl i8
5317+
Output: i8.q1, i8.q2
5318+
-> Result
5319+
Output: f1, f1, i8.q2
5320+
One-Time Filter: false
5321+
(7 rows)
5322+
52945323
-- check handling of nested appendrels inside LATERAL
52955324
select * from
52965325
((select 2 as v) union all (select 3 as v)) as q1

src/test/regress/sql/join.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,14 @@ select * from
17301730
select * from (select 3 as z offset 0) z where z.z = x.x
17311731
) zz on zz.z = y.y;
17321732

1733+
-- check dummy rels with lateral references (bug #15694)
1734+
explain (verbose, costs off)
1735+
select * from int8_tbl i8 left join lateral
1736+
(select *, i8.q2 from int4_tbl where false) ss on true;
1737+
explain (verbose, costs off)
1738+
select * from int8_tbl i8 left join lateral
1739+
(select *, i8.q2 from int4_tbl i1, int4_tbl i2 where false) ss on true;
1740+
17331741
-- check handling of nested appendrels inside LATERAL
17341742
select * from
17351743
((select 2 as v) union all (select 3 as v)) as q1

0 commit comments

Comments
 (0)