]> granicus.if.org Git - postgresql/commitdiff
Ensure dummy paths have correct required_outer if rel is parameterized.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 14 Mar 2019 16:16:10 +0000 (12:16 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 14 Mar 2019 16:16:10 +0000 (12:16 -0400)
The assertions added by commits 34ea1ab7f 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

src/backend/optimizer/path/allpaths.c
src/backend/optimizer/path/joinrels.c
src/test/regress/expected/join.out
src/test/regress/sql/join.sql

index 42d7aa6c3fbe16b1980c8cd59399a76be242f591..60fe4bfb5ec25ec958df5df687434d0f21ef97fe 100644 (file)
@@ -1257,7 +1257,8 @@ set_dummy_rel_pathlist(RelOptInfo *rel)
        /* Discard any pre-existing paths; no further need for them */
        rel->pathlist = NIL;
 
-       add_path(rel, (Path *) create_append_path(rel, NIL, NULL));
+       add_path(rel, (Path *) create_append_path(rel, NIL,
+                                                                                         rel->lateral_relids));
 
        /*
         * We set the cheapest path immediately, to ensure that IS_DUMMY_REL()
index 428c4826ecc3eaf1e7d1aaacb6f15d265b5a430b..801458a60bf72244f21a7b9140f7676be4ccc321 100644 (file)
@@ -1197,7 +1197,8 @@ mark_dummy_rel(RelOptInfo *rel)
        rel->pathlist = NIL;
 
        /* Set up the dummy path */
-       add_path(rel, (Path *) create_append_path(rel, NIL, NULL));
+       add_path(rel, (Path *) create_append_path(rel, NIL,
+                                                                                         rel->lateral_relids));
 
        /* Set or update cheapest_total_path and related fields */
        set_cheapest(rel);
index 3589361b44fcde68ffcd7c284eae6449c2f1e2e8..7ee0d122cbe41926bca3647f89a02ae88d6f8198 100644 (file)
@@ -5290,6 +5290,37 @@ select * from
          Output: 3
 (11 rows)
 
+-- check dummy rels with lateral references (bug #15694)
+explain (verbose, costs off)
+select * from int8_tbl i8 left join lateral
+  (select *, i8.q2 from int4_tbl where false) ss on true;
+                  QUERY PLAN                  
+----------------------------------------------
+ Nested Loop Left Join
+   Output: i8.q1, i8.q2, int4_tbl.f1, (i8.q2)
+   ->  Seq Scan on public.int8_tbl i8
+         Output: i8.q1, i8.q2
+   ->  Result
+         Output: int4_tbl.f1, (i8.q2)
+         One-Time Filter: false
+         ->  Seq Scan on public.int4_tbl
+               Output: int4_tbl.f1, i8.q2
+(9 rows)
+
+explain (verbose, costs off)
+select * from int8_tbl i8 left join lateral
+  (select *, i8.q2 from int4_tbl i1, int4_tbl i2 where false) ss on true;
+               QUERY PLAN                
+-----------------------------------------
+ Nested Loop Left Join
+   Output: i8.q1, i8.q2, f1, f1, (i8.q2)
+   ->  Seq Scan on public.int8_tbl i8
+         Output: i8.q1, i8.q2
+   ->  Result
+         Output: f1, f1, i8.q2
+         One-Time Filter: false
+(7 rows)
+
 -- check handling of nested appendrels inside LATERAL
 select * from
   ((select 2 as v) union all (select 3 as v)) as q1
index 3bda4313e6e7beb3489c5c1a89ffa380cd1b0604..b0b83893dc4484b36cb0ec7e63d3aed4e3637216 100644 (file)
@@ -1726,6 +1726,14 @@ select * from
     select * from (select 3 as z offset 0) z where z.z = x.x
   ) zz on zz.z = y.y;
 
+-- check dummy rels with lateral references (bug #15694)
+explain (verbose, costs off)
+select * from int8_tbl i8 left join lateral
+  (select *, i8.q2 from int4_tbl where false) ss on true;
+explain (verbose, costs off)
+select * from int8_tbl i8 left join lateral
+  (select *, i8.q2 from int4_tbl i1, int4_tbl i2 where false) ss on true;
+
 -- check handling of nested appendrels inside LATERAL
 select * from
   ((select 2 as v) union all (select 3 as v)) as q1