8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.147 2009/02/20 00:01:03 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.148 2009/02/25 03:30:37 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -52,9 +52,6 @@ static void distribute_qual_to_rels(PlannerInfo *root, Node *clause,
52
52
Relids qualscope ,
53
53
Relids ojscope ,
54
54
Relids outerjoin_nonnullable );
55
- static void distribute_sublink_quals_to_rels (PlannerInfo * root ,
56
- FlattenedSubLink * fslink ,
57
- bool below_outer_join );
58
55
static bool check_outerjoin_delay (PlannerInfo * root , Relids * relids_p ,
59
56
bool is_pushed_down );
60
57
static bool check_redundant_nullability_qual (PlannerInfo * root , Node * clause );
@@ -336,15 +333,9 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
336
333
{
337
334
Node * qual = (Node * ) lfirst (l );
338
335
339
- /* FlattenedSubLink wrappers need special processing */
340
- if (qual && IsA (qual , FlattenedSubLink ))
341
- distribute_sublink_quals_to_rels (root ,
342
- (FlattenedSubLink * ) qual ,
343
- below_outer_join );
344
- else
345
- distribute_qual_to_rels (root , qual ,
346
- false, below_outer_join , JOIN_INNER ,
347
- * qualscope , NULL , NULL );
336
+ distribute_qual_to_rels (root , qual ,
337
+ false, below_outer_join , JOIN_INNER ,
338
+ * qualscope , NULL , NULL );
348
339
}
349
340
}
350
341
else if (IsA (jtnode , JoinExpr ))
@@ -399,6 +390,18 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
399
390
* inner_join_rels = bms_union (left_inners , right_inners );
400
391
nonnullable_rels = leftids ;
401
392
break ;
393
+ case JOIN_SEMI :
394
+ leftjoinlist = deconstruct_recurse (root , j -> larg ,
395
+ below_outer_join ,
396
+ & leftids , & left_inners );
397
+ rightjoinlist = deconstruct_recurse (root , j -> rarg ,
398
+ below_outer_join ,
399
+ & rightids , & right_inners );
400
+ * qualscope = bms_union (leftids , rightids );
401
+ * inner_join_rels = bms_union (left_inners , right_inners );
402
+ /* Semi join adds no restrictions for quals */
403
+ nonnullable_rels = NULL ;
404
+ break ;
402
405
case JOIN_FULL :
403
406
leftjoinlist = deconstruct_recurse (root , j -> larg ,
404
407
true,
@@ -425,6 +428,9 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
425
428
* semantic scope (ojscope) to pass to distribute_qual_to_rels. But
426
429
* we mustn't add it to join_info_list just yet, because we don't want
427
430
* distribute_qual_to_rels to think it is an outer join below us.
431
+ *
432
+ * Semijoins are a bit of a hybrid: we build a SpecialJoinInfo,
433
+ * but we want ojscope = NULL for distribute_qual_to_rels.
428
434
*/
429
435
if (j -> jointype != JOIN_INNER )
430
436
{
@@ -433,7 +439,11 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
433
439
* inner_join_rels ,
434
440
j -> jointype ,
435
441
(List * ) j -> quals );
436
- ojscope = bms_union (sjinfo -> min_lefthand , sjinfo -> min_righthand );
442
+ if (j -> jointype == JOIN_SEMI )
443
+ ojscope = NULL ;
444
+ else
445
+ ojscope = bms_union (sjinfo -> min_lefthand ,
446
+ sjinfo -> min_righthand );
437
447
}
438
448
else
439
449
{
@@ -446,16 +456,10 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
446
456
{
447
457
Node * qual = (Node * ) lfirst (l );
448
458
449
- /* FlattenedSubLink wrappers need special processing */
450
- if (qual && IsA (qual , FlattenedSubLink ))
451
- distribute_sublink_quals_to_rels (root ,
452
- (FlattenedSubLink * ) qual ,
453
- below_outer_join );
454
- else
455
- distribute_qual_to_rels (root , qual ,
456
- false, below_outer_join , j -> jointype ,
457
- * qualscope ,
458
- ojscope , nonnullable_rels );
459
+ distribute_qual_to_rels (root , qual ,
460
+ false, below_outer_join , j -> jointype ,
461
+ * qualscope ,
462
+ ojscope , nonnullable_rels );
459
463
}
460
464
461
465
/* Now we can add the SpecialJoinInfo to join_info_list */
@@ -1044,64 +1048,6 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
1044
1048
distribute_restrictinfo_to_rels (root , restrictinfo );
1045
1049
}
1046
1050
1047
- /*
1048
- * distribute_sublink_quals_to_rels
1049
- * Pull sublink quals out of a FlattenedSubLink node and distribute
1050
- * them appropriately; then add a SpecialJoinInfo node to the query's
1051
- * join_info_list. The FlattenedSubLink node itself is no longer
1052
- * needed and does not propagate into further processing.
1053
- */
1054
- static void
1055
- distribute_sublink_quals_to_rels (PlannerInfo * root ,
1056
- FlattenedSubLink * fslink ,
1057
- bool below_outer_join )
1058
- {
1059
- List * quals = make_ands_implicit (fslink -> quals );
1060
- SpecialJoinInfo * sjinfo ;
1061
- Relids qualscope ;
1062
- Relids ojscope ;
1063
- Relids outerjoin_nonnullable ;
1064
- ListCell * l ;
1065
-
1066
- /*
1067
- * Build a suitable SpecialJoinInfo for the sublink. Note: using
1068
- * righthand as inner_join_rels is the conservative worst case;
1069
- * it might be possible to use a smaller set and thereby allow
1070
- * the sublink join to commute with others inside its RHS.
1071
- */
1072
- sjinfo = make_outerjoininfo (root ,
1073
- fslink -> lefthand , fslink -> righthand ,
1074
- fslink -> righthand ,
1075
- fslink -> jointype ,
1076
- quals );
1077
-
1078
- /* Treat as inner join if SEMI, outer join if ANTI */
1079
- qualscope = bms_union (sjinfo -> syn_lefthand , sjinfo -> syn_righthand );
1080
- if (fslink -> jointype == JOIN_SEMI )
1081
- {
1082
- ojscope = outerjoin_nonnullable = NULL ;
1083
- }
1084
- else
1085
- {
1086
- Assert (fslink -> jointype == JOIN_ANTI );
1087
- ojscope = bms_union (sjinfo -> min_lefthand , sjinfo -> min_righthand );
1088
- outerjoin_nonnullable = fslink -> lefthand ;
1089
- }
1090
-
1091
- /* Distribute the join quals much as for a regular JOIN node */
1092
- foreach (l , quals )
1093
- {
1094
- Node * qual = (Node * ) lfirst (l );
1095
-
1096
- distribute_qual_to_rels (root , qual ,
1097
- false, below_outer_join , fslink -> jointype ,
1098
- qualscope , ojscope , outerjoin_nonnullable );
1099
- }
1100
-
1101
- /* Now we can add the SpecialJoinInfo to join_info_list */
1102
- root -> join_info_list = lappend (root -> join_info_list , sjinfo );
1103
- }
1104
-
1105
1051
/*
1106
1052
* check_outerjoin_delay
1107
1053
* Detect whether a qual referencing the given relids must be delayed
0 commit comments