Skip to content

Commit 5b86600

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 da45300 commit 5b86600

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,8 @@ set_dummy_rel_pathlist(RelOptInfo *rel)
20222022
rel->partial_pathlist = NIL;
20232023

20242024
/* Set up the dummy path */
2025-
add_path(rel, (Path *) create_append_path(NULL, rel, NIL, NIL, NULL,
2025+
add_path(rel, (Path *) create_append_path(NULL, rel, NIL, NIL,
2026+
rel->lateral_relids,
20262027
0, false, NIL, -1));
20272028

20282029
/*

src/backend/optimizer/path/joinrels.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,8 @@ mark_dummy_rel(RelOptInfo *rel)
12601260
rel->partial_pathlist = NIL;
12611261

12621262
/* Set up the dummy path */
1263-
add_path(rel, (Path *) create_append_path(NULL, rel, NIL, NIL, NULL,
1263+
add_path(rel, (Path *) create_append_path(NULL, rel, NIL, NIL,
1264+
rel->lateral_relids,
12641265
0, false, NIL, -1));
12651266

12661267
/* Set or update cheapest_total_path and related fields */

src/test/regress/expected/join.out

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5325,6 +5325,35 @@ select * from
53255325
Output: 3
53265326
(11 rows)
53275327

5328+
-- check dummy rels with lateral references (bug #15694)
5329+
explain (verbose, costs off)
5330+
select * from int8_tbl i8 left join lateral
5331+
(select *, i8.q2 from int4_tbl where false) ss on true;
5332+
QUERY PLAN
5333+
--------------------------------------
5334+
Nested Loop Left Join
5335+
Output: i8.q1, i8.q2, f1, (i8.q2)
5336+
-> Seq Scan on public.int8_tbl i8
5337+
Output: i8.q1, i8.q2
5338+
-> Result
5339+
Output: f1, i8.q2
5340+
One-Time Filter: false
5341+
(7 rows)
5342+
5343+
explain (verbose, costs off)
5344+
select * from int8_tbl i8 left join lateral
5345+
(select *, i8.q2 from int4_tbl i1, int4_tbl i2 where false) ss on true;
5346+
QUERY PLAN
5347+
-----------------------------------------
5348+
Nested Loop Left Join
5349+
Output: i8.q1, i8.q2, f1, f1, (i8.q2)
5350+
-> Seq Scan on public.int8_tbl i8
5351+
Output: i8.q1, i8.q2
5352+
-> Result
5353+
Output: f1, f1, i8.q2
5354+
One-Time Filter: false
5355+
(7 rows)
5356+
53285357
-- check handling of nested appendrels inside LATERAL
53295358
select * from
53305359
((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
@@ -1744,6 +1744,14 @@ select * from
17441744
select * from (select 3 as z offset 0) z where z.z = x.x
17451745
) zz on zz.z = y.y;
17461746

1747+
-- check dummy rels with lateral references (bug #15694)
1748+
explain (verbose, costs off)
1749+
select * from int8_tbl i8 left join lateral
1750+
(select *, i8.q2 from int4_tbl where false) ss on true;
1751+
explain (verbose, costs off)
1752+
select * from int8_tbl i8 left join lateral
1753+
(select *, i8.q2 from int4_tbl i1, int4_tbl i2 where false) ss on true;
1754+
17471755
-- check handling of nested appendrels inside LATERAL
17481756
select * from
17491757
((select 2 as v) union all (select 3 as v)) as q1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy