File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -632,7 +632,11 @@ create_lateral_join_info(PlannerInfo *root)
632632 RelOptInfo * brel = root -> simple_rel_array [rti ];
633633 RangeTblEntry * brte = root -> simple_rte_array [rti ];
634634
635- if (brel == NULL )
635+ /*
636+ * Skip empty slots. Also skip non-simple relations i.e. dead
637+ * relations.
638+ */
639+ if (brel == NULL || !IS_SIMPLE_REL (brel ))
636640 continue ;
637641
638642 /*
@@ -644,7 +648,6 @@ create_lateral_join_info(PlannerInfo *root)
644648 * therefore be marked with the appropriate lateral info so that those
645649 * children eventually get marked also.
646650 */
647- Assert (IS_SIMPLE_REL (brel ));
648651 Assert (brte );
649652 if (brel -> reloptkind == RELOPT_OTHER_MEMBER_REL &&
650653 (brte -> rtekind != RTE_RELATION ||
Original file line number Diff line number Diff line change @@ -4060,6 +4060,18 @@ select i8.* from int8_tbl i8 left join (select f1 from int4_tbl group by f1) i4
40604060 Seq Scan on int8_tbl i8
40614061(1 row)
40624062
4063+ -- check join removal with lateral references
4064+ explain (costs off)
4065+ select 1 from (select a.id FROM a left join b on a.b_id = b.id) q,
4066+ lateral generate_series(1, q.id) gs(i) where q.id = gs.i;
4067+ QUERY PLAN
4068+ -------------------------------------------
4069+ Nested Loop
4070+ -> Seq Scan on a
4071+ -> Function Scan on generate_series gs
4072+ Filter: (a.id = i)
4073+ (4 rows)
4074+
40634075rollback;
40644076create temp table parent (k int primary key, pd int);
40654077create temp table child (k int unique, cd int);
Original file line number Diff line number Diff line change @@ -1336,6 +1336,11 @@ explain (costs off)
13361336select i8.* from int8_tbl i8 left join (select f1 from int4_tbl group by f1) i4
13371337 on i8 .q1 = i4 .f1 ;
13381338
1339+ -- check join removal with lateral references
1340+ explain (costs off)
1341+ select 1 from (select a .id FROM a left join b on a .b_id = b .id ) q,
1342+ lateral generate_series(1 , q .id ) gs(i) where q .id = gs .i ;
1343+
13391344rollback ;
13401345
13411346create temp table parent (k int primary key , pd int );
You can’t perform that action at this time.
0 commit comments