Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa0fb53

Browse files
committed
Be a little smarter about qual handling for semi-joins: a qual that mentions
only the outer side can be pushed down rather than having to be evaluatedat the join.
1 parentddbe8dc commitaa0fb53

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

‎src/backend/optimizer/plan/initsplan.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.143 2008/10/21 20:42:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.144 2008/10/25 19:51:32 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -48,6 +48,7 @@ static SpecialJoinInfo *make_outerjoininfo(PlannerInfo *root,
4848
staticvoiddistribute_qual_to_rels(PlannerInfo*root,Node*clause,
4949
boolis_deduced,
5050
boolbelow_outer_join,
51+
JoinTypejointype,
5152
Relidsqualscope,
5253
Relidsojscope,
5354
Relidsouterjoin_nonnullable);
@@ -342,7 +343,7 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
342343
below_outer_join);
343344
else
344345
distribute_qual_to_rels(root,qual,
345-
false,below_outer_join,
346+
false,below_outer_join,JOIN_INNER,
346347
*qualscope,NULL,NULL);
347348
}
348349
}
@@ -452,7 +453,7 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
452453
below_outer_join);
453454
else
454455
distribute_qual_to_rels(root,qual,
455-
false,below_outer_join,
456+
false,below_outer_join,j->jointype,
456457
*qualscope,
457458
ojscope,nonnullable_rels);
458459
}
@@ -712,6 +713,7 @@ make_outerjoininfo(PlannerInfo *root,
712713
* 'is_deduced': TRUE if the qual came from implied-equality deduction
713714
* 'below_outer_join': TRUE if the qual is from a JOIN/ON that is below the
714715
*nullable side of a higher-level outer join
716+
* 'jointype': type of join the qual is from (JOIN_INNER for a WHERE clause)
715717
* 'qualscope': set of baserels the qual's syntactic scope covers
716718
* 'ojscope': NULL if not an outer-join qual, else the minimum set of baserels
717719
*needed to form this join
@@ -728,6 +730,7 @@ static void
728730
distribute_qual_to_rels(PlannerInfo*root,Node*clause,
729731
boolis_deduced,
730732
boolbelow_outer_join,
733+
JoinTypejointype,
731734
Relidsqualscope,
732735
Relidsojscope,
733736
Relidsouterjoin_nonnullable)
@@ -848,11 +851,16 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
848851
maybe_equivalence= false;
849852
maybe_outer_join= false;
850853
}
851-
elseif (bms_overlap(relids,outerjoin_nonnullable))
854+
elseif (bms_overlap(relids,outerjoin_nonnullable)&&
855+
(jointype!=JOIN_SEMI||
856+
bms_nonempty_difference(relids,outerjoin_nonnullable)))
852857
{
853858
/*
854859
* The qual is attached to an outer join and mentions (some of the)
855-
* rels on the nonnullable side, so it's not degenerate.
860+
* rels on the nonnullable side, so it's not degenerate. (For a
861+
* JOIN_SEMI qual, we consider it non-degenerate only if it mentions
862+
* both sides of the join --- if it mentions only one side, it can
863+
* be pushed down.)
856864
*
857865
* We can't use such a clause to deduce equivalence (the left and
858866
* right sides might be unequal above the join because one of them has
@@ -1024,7 +1032,7 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
10241032
restrictinfo);
10251033
return;
10261034
}
1027-
if (bms_equal(outerjoin_nonnullable,qualscope))
1035+
if (jointype==JOIN_FULL)
10281036
{
10291037
/* FULL JOIN (above tests cannot match in this case) */
10301038
root->full_join_clauses=lappend(root->full_join_clauses,
@@ -1077,9 +1085,8 @@ distribute_sublink_quals_to_rels(PlannerInfo *root,
10771085
Node*qual= (Node*)lfirst(l);
10781086

10791087
distribute_qual_to_rels(root,qual,
1080-
false,below_outer_join,
1081-
qualscope,ojscope,
1082-
fslink->lefthand);
1088+
false,below_outer_join,fslink->jointype,
1089+
qualscope,ojscope,fslink->lefthand);
10831090
}
10841091

10851092
/* Now we can add the SpecialJoinInfo to join_info_list */
@@ -1373,7 +1380,7 @@ process_implied_equality(PlannerInfo *root,
13731380
* Push the new clause into all the appropriate restrictinfo lists.
13741381
*/
13751382
distribute_qual_to_rels(root, (Node*)clause,
1376-
true,below_outer_join,
1383+
true,below_outer_join,JOIN_INNER,
13771384
qualscope,NULL,NULL);
13781385
}
13791386

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp