File tree 3 files changed +29
-3
lines changed
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -1522,19 +1522,24 @@ replace_varno_walker(Node *node, ReplaceVarnoContext *ctx)
1522
1522
1523
1523
/*
1524
1524
* Substitute newId by oldId in relids.
1525
+ *
1526
+ * We must make a copy of the original Bitmapset before making any
1527
+ * modifications, because the same pointer to it might be shared among
1528
+ * different places.
1525
1529
*/
1526
1530
static Bitmapset *
1527
1531
replace_relid (Relids relids , int oldId , int newId )
1528
1532
{
1529
1533
if (oldId < 0 )
1530
1534
return relids ;
1531
1535
1536
+ /* Delete relid without substitution. */
1532
1537
if (newId < 0 )
1533
- /* Delete relid without substitution. */
1534
- return bms_del_member (relids , oldId );
1538
+ return bms_del_member (bms_copy (relids ), oldId );
1535
1539
1540
+ /* Substitute newId for oldId. */
1536
1541
if (bms_is_member (oldId , relids ))
1537
- return bms_add_member (bms_del_member (relids , oldId ), newId );
1542
+ return bms_add_member (bms_del_member (bms_copy ( relids ) , oldId ), newId );
1538
1543
1539
1544
return relids ;
1540
1545
}
Original file line number Diff line number Diff line change @@ -6853,6 +6853,21 @@ on true;
6853
6853
Filter: (t3.id IS NOT NULL)
6854
6854
(8 rows)
6855
6855
6856
+ -- Check that SJE replaces join clauses involving the removed rel correctly
6857
+ explain (costs off)
6858
+ select * from emp1 t1
6859
+ inner join emp1 t2 on t1.id = t2.id
6860
+ left join emp1 t3 on t1.id > 1 and t1.id < 2;
6861
+ QUERY PLAN
6862
+ ----------------------------------------------
6863
+ Nested Loop Left Join
6864
+ Join Filter: ((t2.id > 1) AND (t2.id < 2))
6865
+ -> Seq Scan on emp1 t2
6866
+ Filter: (id IS NOT NULL)
6867
+ -> Materialize
6868
+ -> Seq Scan on emp1 t3
6869
+ (6 rows)
6870
+
6856
6871
-- We can remove the join even if we find the join can't duplicate rows and
6857
6872
-- the base quals of each side are different. In the following case we end up
6858
6873
-- moving quals over to s1 to make it so it can't match any rows.
Original file line number Diff line number Diff line change @@ -2610,6 +2610,12 @@ select * from generate_series(1,10) t1(id) left join
2610
2610
lateral (select t1 .id as t1id, t2 .id from emp1 t2 join emp1 t3 on t2 .id = t3 .id )
2611
2611
on true;
2612
2612
2613
+ -- Check that SJE replaces join clauses involving the removed rel correctly
2614
+ explain (costs off)
2615
+ select * from emp1 t1
2616
+ inner join emp1 t2 on t1 .id = t2 .id
2617
+ left join emp1 t3 on t1 .id > 1 and t1 .id < 2 ;
2618
+
2613
2619
-- We can remove the join even if we find the join can't duplicate rows and
2614
2620
-- the base quals of each side are different. In the following case we end up
2615
2621
-- moving quals over to s1 to make it so it can't match any rows.
You can’t perform that action at this time.
0 commit comments