Skip to content

Commit 98f8ffa

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 e7e78f1 commit 98f8ffa

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,8 @@ set_dummy_rel_pathlist(RelOptInfo *rel)
11451145
/* Discard any pre-existing paths; no further need for them */
11461146
rel->pathlist = NIL;
11471147

1148-
add_path(rel, (Path *) create_append_path(rel, NIL, NULL));
1148+
add_path(rel, (Path *) create_append_path(rel, NIL,
1149+
rel->lateral_relids));
11491150

11501151
/* Select cheapest path (pretty easy in this case...) */
11511152
set_cheapest(rel);

src/backend/optimizer/path/joinrels.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,8 @@ mark_dummy_rel(RelOptInfo *rel)
12181218
rel->pathlist = NIL;
12191219

12201220
/* Set up the dummy path */
1221-
add_path(rel, (Path *) create_append_path(rel, NIL, NULL));
1221+
add_path(rel, (Path *) create_append_path(rel, NIL,
1222+
rel->lateral_relids));
12221223

12231224
/* Set or update cheapest_total_path and related fields */
12241225
set_cheapest(rel);

src/test/regress/expected/join.out

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,6 +5091,37 @@ select * from
50915091
Output: 3
50925092
(11 rows)
50935093

5094+
-- check dummy rels with lateral references (bug #15694)
5095+
explain (verbose, costs off)
5096+
select * from int8_tbl i8 left join lateral
5097+
(select *, i8.q2 from int4_tbl where false) ss on true;
5098+
QUERY PLAN
5099+
----------------------------------------------
5100+
Nested Loop Left Join
5101+
Output: i8.q1, i8.q2, int4_tbl.f1, (i8.q2)
5102+
-> Seq Scan on public.int8_tbl i8
5103+
Output: i8.q1, i8.q2
5104+
-> Result
5105+
Output: int4_tbl.f1, (i8.q2)
5106+
One-Time Filter: false
5107+
-> Seq Scan on public.int4_tbl
5108+
Output: int4_tbl.f1, i8.q2
5109+
(9 rows)
5110+
5111+
explain (verbose, costs off)
5112+
select * from int8_tbl i8 left join lateral
5113+
(select *, i8.q2 from int4_tbl i1, int4_tbl i2 where false) ss on true;
5114+
QUERY PLAN
5115+
-----------------------------------------
5116+
Nested Loop Left Join
5117+
Output: i8.q1, i8.q2, f1, f1, (i8.q2)
5118+
-> Seq Scan on public.int8_tbl i8
5119+
Output: i8.q1, i8.q2
5120+
-> Result
5121+
Output: f1, f1, i8.q2
5122+
One-Time Filter: false
5123+
(7 rows)
5124+
50945125
-- check handling of nested appendrels inside LATERAL
50955126
select * from
50965127
((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
@@ -1631,6 +1631,14 @@ select * from
16311631
select * from (select 3 as z) z where z.z = x.x
16321632
) zz on zz.z = y.y;
16331633

1634+
-- check dummy rels with lateral references (bug #15694)
1635+
explain (verbose, costs off)
1636+
select * from int8_tbl i8 left join lateral
1637+
(select *, i8.q2 from int4_tbl where false) ss on true;
1638+
explain (verbose, costs off)
1639+
select * from int8_tbl i8 left join lateral
1640+
(select *, i8.q2 from int4_tbl i1, int4_tbl i2 where false) ss on true;
1641+
16341642
-- check handling of nested appendrels inside LATERAL
16351643
select * from
16361644
((select 2 as v) union all (select 3 as v)) as q1

0 commit comments

Comments
 (0)