File tree 3 files changed +39
-1
lines changed 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 16
16
*
17
17
*
18
18
* IDENTIFICATION
19
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/analyzejoins.c,v 1.1 2010/03/28 22:59:32 tgl Exp $
19
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/analyzejoins.c,v 1.2 2010/05/23 16:34:38 tgl Exp $
20
20
*
21
21
*-------------------------------------------------------------------------
22
22
*/
@@ -343,6 +343,24 @@ remove_rel_from_query(PlannerInfo *root, int relid)
343
343
}
344
344
}
345
345
346
+ /*
347
+ * Likewise remove references from SpecialJoinInfo data structures.
348
+ *
349
+ * This is relevant in case the outer join we're deleting is nested
350
+ * inside other outer joins: the upper joins' relid sets have to be
351
+ * adjusted. The RHS of the target outer join will be made empty here,
352
+ * but that's OK since caller will delete that SpecialJoinInfo entirely.
353
+ */
354
+ foreach (l , root -> join_info_list )
355
+ {
356
+ SpecialJoinInfo * sjinfo = (SpecialJoinInfo * ) lfirst (l );
357
+
358
+ sjinfo -> min_lefthand = bms_del_member (sjinfo -> min_lefthand , relid );
359
+ sjinfo -> min_righthand = bms_del_member (sjinfo -> min_righthand , relid );
360
+ sjinfo -> syn_lefthand = bms_del_member (sjinfo -> syn_lefthand , relid );
361
+ sjinfo -> syn_righthand = bms_del_member (sjinfo -> syn_righthand , relid );
362
+ }
363
+
346
364
/*
347
365
* Likewise remove references from PlaceHolderVar data structures.
348
366
*
Original file line number Diff line number Diff line change @@ -2525,6 +2525,20 @@ explain (costs off)
2525
2525
Seq Scan on a
2526
2526
(1 row)
2527
2527
2528
+ -- check optimization of outer join within another special join
2529
+ explain (costs off)
2530
+ select id from a where id in (
2531
+ select b.id from b left join c on b.id = c.id
2532
+ );
2533
+ QUERY PLAN
2534
+ ----------------------------
2535
+ Hash Semi Join
2536
+ Hash Cond: (a.id = b.id)
2537
+ -> Seq Scan on a
2538
+ -> Hash
2539
+ -> Seq Scan on b
2540
+ (5 rows)
2541
+
2528
2542
rollback;
2529
2543
create temp table parent (k int primary key, pd int);
2530
2544
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "parent_pkey" for table "parent"
Original file line number Diff line number Diff line change @@ -588,6 +588,12 @@ explain (costs off)
588
588
SELECT a.* FROM a LEFT JOIN (b left join c on b .c_id = c .id )
589
589
ON (a .b_id = b .id );
590
590
591
+ -- check optimization of outer join within another special join
592
+ explain (costs off)
593
+ select id from a where id in (
594
+ select b .id from b left join c on b .id = c .id
595
+ );
596
+
591
597
rollback ;
592
598
593
599
create temp table parent (k int primary key , pd int );
You can’t perform that action at this time.
0 commit comments