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

Commitcde9f85

Browse files
committed
Now that switch_outer processing no longer relies on being run after
join_references(), it's practical to consolidate all join_references()processing into the set_plan_references traversal in setrefs.c. Thisseems considerably cleaner than the old way where we did it for joinquals in createplan.c and for targetlists in setrefs.c.
1 parent606d4f7 commitcde9f85

File tree

3 files changed

+136
-154
lines changed

3 files changed

+136
-154
lines changed

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

Lines changed: 15 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.130 2003/01/1519:35:40 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.131 2003/01/1523:10:32 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -651,20 +651,6 @@ create_functionscan_plan(Path *best_path, List *tlist, List *scan_clauses)
651651
*
652652
*JOIN METHODS
653653
*
654-
* A general note about join_references() processing in these routines:
655-
* once we have changed a Var node to refer to a subplan output rather than
656-
* the original relation, it is no longer equal() to an unmodified Var node
657-
* for the same var. So, we cannot easily compare reference-adjusted qual
658-
* clauses to clauses that have not been adjusted.Fortunately, that
659-
* doesn't seem to be necessary; all the decisions are made before we do
660-
* the reference adjustments.
661-
*
662-
* A cleaner solution would be to not call join_references() here at all,
663-
* but leave it for setrefs.c to do at the end of plan tree construction.
664-
* But some care would be needed to get setrefs.c to do the right thing with
665-
* nestloop inner indexscan quals. So, we do subplan reference adjustment
666-
* here for quals of join nodes (and *only* for quals of join nodes).
667-
*
668654
*****************************************************************************/
669655

670656
staticNestLoop*
@@ -676,95 +662,34 @@ create_nestloop_plan(Query *root,
676662
Plan*outer_plan,
677663
Plan*inner_plan)
678664
{
679-
List*outer_tlist=outer_plan->targetlist;
680-
List*inner_tlist=inner_plan->targetlist;
681665
NestLoop*join_plan;
682666

683667
if (IsA(inner_plan,IndexScan))
684668
{
685669
/*
686670
* An index is being used to reduce the number of tuples scanned
687671
* in the inner relation. If there are join clauses being used
688-
* with the index, we must update their outer-rel var nodes to
689-
* refer to the outer side of the join.
690-
*
691-
* We can also remove those join clauses from the list of clauses
692-
* that have to be checked as qpquals at the join node, but only
693-
* if there's just one indexscan in the inner path (otherwise,
694-
* several different sets of clauses are being ORed together).
672+
* with the index, we may remove those join clauses from the list of
673+
* clauses that have to be checked as qpquals at the join node ---
674+
* but only if there's just one indexscan in the inner path
675+
* (otherwise, several different sets of clauses are being ORed
676+
* together).
695677
*
696-
* Note: if the index is lossy, the same clauses may also be getting
697-
* checked as qpquals in the indexscan. We can still remove them
698-
* from the nestloop's qpquals, but we gotta update the outer-rel
699-
* vars in the indexscan's qpquals too.
700-
*
701-
* Note: we can safely do set_difference() against my clauses and
702-
* join_references() because the innerscan is a primitive plan,
703-
* and therefore has not itself done join_references renumbering
704-
* of the vars in its quals.
678+
* Note we must compare against indxqualorig not the "fixed" indxqual
679+
* (which has index attnos instead of relation attnos, and may have
680+
* been commuted as well).
705681
*/
706682
IndexScan*innerscan= (IndexScan*)inner_plan;
707683
List*indxqualorig=innerscan->indxqualorig;
708684

709-
/* No work needed if indxqual refers only to its own relation... */
710-
if (NumRelids((Node*)indxqualorig)>1)
685+
if (length(indxqualorig)==1)/* single indexscan? */
711686
{
712-
Indexinnerrel=innerscan->scan.scanrelid;
713-
714-
/*
715-
* Remove redundant tests from my clauses, if possible. Note
716-
* we must compare against indxqualorig not the "fixed"
717-
* indxqual (which has index attnos instead of relation
718-
* attnos, and may have been commuted as well).
719-
*/
720-
if (length(indxqualorig)==1)/* single indexscan? */
687+
/* No work needed if indxqual refers only to its own relation... */
688+
if (NumRelids((Node*)indxqualorig)>1)
721689
joinclauses=set_difference(joinclauses,
722690
lfirst(indxqualorig));
723-
724-
/* only refs to outer vars get changed in the inner indexqual */
725-
innerscan->indxqualorig=join_references(indxqualorig,
726-
root->rtable,
727-
outer_tlist,
728-
NIL,
729-
innerrel);
730-
innerscan->indxqual=join_references(innerscan->indxqual,
731-
root->rtable,
732-
outer_tlist,
733-
NIL,
734-
innerrel);
735-
/* fix the inner qpqual too, if it has join clauses */
736-
if (NumRelids((Node*)inner_plan->qual)>1)
737-
inner_plan->qual=join_references(inner_plan->qual,
738-
root->rtable,
739-
outer_tlist,
740-
NIL,
741-
innerrel);
742691
}
743692
}
744-
elseif (IsA(inner_plan,TidScan))
745-
{
746-
TidScan*innerscan= (TidScan*)inner_plan;
747-
748-
innerscan->tideval=join_references(innerscan->tideval,
749-
root->rtable,
750-
outer_tlist,
751-
inner_tlist,
752-
innerscan->scan.scanrelid);
753-
}
754-
755-
/*
756-
* Set quals to contain INNER/OUTER var references.
757-
*/
758-
joinclauses=join_references(joinclauses,
759-
root->rtable,
760-
outer_tlist,
761-
inner_tlist,
762-
(Index)0);
763-
otherclauses=join_references(otherclauses,
764-
root->rtable,
765-
outer_tlist,
766-
inner_tlist,
767-
(Index)0);
768693

769694
join_plan=make_nestloop(tlist,
770695
joinclauses,
@@ -787,8 +712,6 @@ create_mergejoin_plan(Query *root,
787712
Plan*outer_plan,
788713
Plan*inner_plan)
789714
{
790-
List*outer_tlist=outer_plan->targetlist;
791-
List*inner_tlist=inner_plan->targetlist;
792715
List*mergeclauses;
793716
MergeJoin*join_plan;
794717

@@ -806,25 +729,6 @@ create_mergejoin_plan(Query *root,
806729
mergeclauses=get_switched_clauses(best_path->path_mergeclauses,
807730
best_path->jpath.outerjoinpath->parent->relids);
808731

809-
/*
810-
* Fix all the join clauses to contain INNER/OUTER var references.
811-
*/
812-
joinclauses=join_references(joinclauses,
813-
root->rtable,
814-
outer_tlist,
815-
inner_tlist,
816-
(Index)0);
817-
otherclauses=join_references(otherclauses,
818-
root->rtable,
819-
outer_tlist,
820-
inner_tlist,
821-
(Index)0);
822-
mergeclauses=join_references(mergeclauses,
823-
root->rtable,
824-
outer_tlist,
825-
inner_tlist,
826-
(Index)0);
827-
828732
/*
829733
* Create explicit sort nodes for the outer and inner join paths if
830734
* necessary. The sort cost was already accounted for in the path.
@@ -868,8 +772,6 @@ create_hashjoin_plan(Query *root,
868772
Plan*outer_plan,
869773
Plan*inner_plan)
870774
{
871-
List*outer_tlist=outer_plan->targetlist;
872-
List*inner_tlist=inner_plan->targetlist;
873775
List*hashclauses;
874776
HashJoin*join_plan;
875777
Hash*hash_plan;
@@ -890,25 +792,6 @@ create_hashjoin_plan(Query *root,
890792
hashclauses=get_switched_clauses(best_path->path_hashclauses,
891793
best_path->jpath.outerjoinpath->parent->relids);
892794

893-
/*
894-
* Fix all the join clauses to contain INNER/OUTER var references.
895-
*/
896-
joinclauses=join_references(joinclauses,
897-
root->rtable,
898-
outer_tlist,
899-
inner_tlist,
900-
(Index)0);
901-
otherclauses=join_references(otherclauses,
902-
root->rtable,
903-
outer_tlist,
904-
inner_tlist,
905-
(Index)0);
906-
hashclauses=join_references(hashclauses,
907-
root->rtable,
908-
outer_tlist,
909-
inner_tlist,
910-
(Index)0);
911-
912795
/*
913796
* Extract the inner hash keys (right-hand operands of the hashclauses)
914797
* to put in the Hash node.
@@ -922,7 +805,9 @@ create_hashjoin_plan(Query *root,
922805
/*
923806
* Build the hash node and hash join node.
924807
*/
925-
hash_plan=make_hash(inner_tlist,innerhashkeys,inner_plan);
808+
hash_plan=make_hash(inner_plan->targetlist,
809+
innerhashkeys,
810+
inner_plan);
926811
join_plan=make_hashjoin(tlist,
927812
joinclauses,
928813
otherclauses,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp