Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 31468d0

Browse files
committed
Dept of better ideas: refrain from creating the planner's placeholder_list
until vars are distributed to rels during query_planner() startup. We don't really need it before that, and not building it early has some advantages. First, we don't need to put it through the various preprocessing steps, which saves some cycles and eliminates the need for a number of routines to support PlaceHolderInfo nodes at all. Second, this means one less unused plan for any sub-SELECT appearing in a placeholder's expression, since we don't build placeholder_list until after sublink expansion is complete.
1 parent b9856b6 commit 31468d0

File tree

8 files changed

+95
-168
lines changed

8 files changed

+95
-168
lines changed

src/backend/optimizer/plan/planmain.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.111 2008/10/21 20:42:53 tgl Exp $
17+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.112 2008/10/22 20:17:51 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -133,7 +133,7 @@ query_planner(PlannerInfo *root, List *tlist,
133133
* for "simple" rels.
134134
*
135135
* NOTE: append_rel_list was set up by subquery_planner, so do not touch
136-
* here; ditto placeholder_list; eq_classes may contain data already, too.
136+
* here; eq_classes may contain data already, too.
137137
*/
138138
root->simple_rel_array_size = list_length(parse->rtable) + 1;
139139
root->simple_rel_array = (RelOptInfo **)
@@ -145,6 +145,7 @@ query_planner(PlannerInfo *root, List *tlist,
145145
root->right_join_clauses = NIL;
146146
root->full_join_clauses = NIL;
147147
root->join_info_list = NIL;
148+
root->placeholder_list = NIL;
148149
root->initial_rels = NIL;
149150

150151
/*

src/backend/optimizer/plan/planner.c

+5-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.245 2008/10/21 20:42:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.246 2008/10/22 20:17:51 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -55,7 +55,7 @@ planner_hook_type planner_hook = NULL;
5555
#define EXPRKIND_RTFUNC 2
5656
#define EXPRKIND_VALUES 3
5757
#define EXPRKIND_LIMIT 4
58-
#define EXPRKIND_AUXINFO 5
58+
#define EXPRKIND_APPINFO 5
5959

6060

6161
static Node *preprocess_expression(PlannerInfo *root, Node *expr, int kind);
@@ -274,7 +274,6 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
274274
root->cte_plan_ids = NIL;
275275
root->eq_classes = NIL;
276276
root->append_rel_list = NIL;
277-
root->placeholder_list = NIL;
278277

279278
root->hasRecursion = hasRecursion;
280279
if (hasRecursion)
@@ -380,10 +379,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
380379

381380
root->append_rel_list = (List *)
382381
preprocess_expression(root, (Node *) root->append_rel_list,
383-
EXPRKIND_AUXINFO);
384-
root->placeholder_list = (List *)
385-
preprocess_expression(root, (Node *) root->placeholder_list,
386-
EXPRKIND_AUXINFO);
382+
EXPRKIND_APPINFO);
387383

388384
/* Also need to preprocess expressions for function and values RTEs */
389385
foreach(l, parse->rtable)
@@ -664,11 +660,10 @@ inheritance_planner(PlannerInfo *root)
664660
subroot.returningLists = NIL;
665661
subroot.init_plans = NIL;
666662
/* We needn't modify the child's append_rel_list */
667-
subroot.placeholder_list = (List *)
668-
adjust_appendrel_attrs((Node *) root->placeholder_list,
669-
appinfo);
670663
/* There shouldn't be any OJ info to translate, as yet */
671664
Assert(subroot.join_info_list == NIL);
665+
/* and we haven't created PlaceHolderInfos, either */
666+
Assert(subroot.placeholder_list == NIL);
672667

673668
/* Generate plan */
674669
subplan = grouping_planner(&subroot, 0.0 /* retrieve all tuples */ );

src/backend/optimizer/prep/prepjointree.c

+24-48
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.57 2008/10/21 20:42:53 tgl Exp $
19+
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.58 2008/10/22 20:17:52 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -565,7 +565,6 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
565565
subroot->cte_plan_ids = NIL;
566566
subroot->eq_classes = NIL;
567567
subroot->append_rel_list = NIL;
568-
subroot->placeholder_list = NIL;
569568
subroot->hasRecursion = false;
570569
subroot->wt_param_id = -1;
571570
subroot->non_recursive_plan = NULL;
@@ -627,20 +626,18 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
627626
/*
628627
* Adjust level-0 varnos in subquery so that we can append its rangetable
629628
* to upper query's. We have to fix the subquery's append_rel_list
630-
* and placeholder_list as well.
629+
* as well.
631630
*/
632631
rtoffset = list_length(parse->rtable);
633632
OffsetVarNodes((Node *) subquery, rtoffset, 0);
634633
OffsetVarNodes((Node *) subroot->append_rel_list, rtoffset, 0);
635-
OffsetVarNodes((Node *) subroot->placeholder_list, rtoffset, 0);
636634

637635
/*
638636
* Upper-level vars in subquery are now one level closer to their parent
639637
* than before.
640638
*/
641639
IncrementVarSublevelsUp((Node *) subquery, -1, 1);
642640
IncrementVarSublevelsUp((Node *) subroot->append_rel_list, -1, 1);
643-
IncrementVarSublevelsUp((Node *) subroot->placeholder_list, -1, 1);
644641

645642
/*
646643
* The subquery's targetlist items are now in the appropriate form to
@@ -706,48 +703,42 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
706703
parse->rowMarks = list_concat(parse->rowMarks, subquery->rowMarks);
707704

708705
/*
709-
* We also have to fix the relid sets of any FlattenedSubLink,
710-
* PlaceHolderVar, and PlaceHolderInfo nodes in the parent query.
711-
* (This could perhaps be done by ResolveNew, but it would clutter that
712-
* routine's API unreasonably.) Note in particular that any placeholder
713-
* nodes just created by insert_targetlist_placeholders() wiil be adjusted.
706+
* We also have to fix the relid sets of any FlattenedSubLink and
707+
* PlaceHolderVar nodes in the parent query. (This could perhaps be done
708+
* by ResolveNew, but it would clutter that routine's API unreasonably.)
709+
* Note in particular that any PlaceHolderVar nodes just created by
710+
* insert_targetlist_placeholders() will be adjusted, so having created
711+
* them with the subquery's varno is correct.
714712
*
715713
* Likewise, relids appearing in AppendRelInfo nodes have to be fixed (but
716714
* we took care of their translated_vars lists above). We already checked
717715
* that this won't require introducing multiple subrelids into the
718716
* single-slot AppendRelInfo structs.
719717
*/
720-
if (parse->hasSubLinks || root->placeholder_list || root->append_rel_list)
718+
if (parse->hasSubLinks || root->glob->lastPHId != 0 ||
719+
root->append_rel_list)
721720
{
722721
Relids subrelids;
723722

724723
subrelids = get_relids_in_jointree((Node *) subquery->jointree, false);
725-
substitute_multiple_relids((Node *) parse,
726-
varno, subrelids);
727-
substitute_multiple_relids((Node *) root->placeholder_list,
728-
varno, subrelids);
729-
fix_append_rel_relids(root->append_rel_list,
730-
varno, subrelids);
724+
substitute_multiple_relids((Node *) parse, varno, subrelids);
725+
fix_append_rel_relids(root->append_rel_list, varno, subrelids);
731726
}
732727

733728
/*
734-
* And now add subquery's AppendRelInfos and PlaceHolderInfos to our lists.
735-
* Note that any placeholders pulled up from the subquery will appear
736-
* after any we just created; this preserves the property that placeholders
737-
* can only refer to other placeholders that appear later in the list
738-
* (needed by fix_placeholder_eval_levels).
729+
* And now add subquery's AppendRelInfos to our list.
739730
*/
740731
root->append_rel_list = list_concat(root->append_rel_list,
741732
subroot->append_rel_list);
742-
root->placeholder_list = list_concat(root->placeholder_list,
743-
subroot->placeholder_list);
744733

745734
/*
746735
* We don't have to do the equivalent bookkeeping for outer-join info,
747-
* because that hasn't been set up yet.
736+
* because that hasn't been set up yet. placeholder_list likewise.
748737
*/
749738
Assert(root->join_info_list == NIL);
750739
Assert(subroot->join_info_list == NIL);
740+
Assert(root->placeholder_list == NIL);
741+
Assert(subroot->placeholder_list == NIL);
751742

752743
/*
753744
* Miscellaneous housekeeping.
@@ -1606,10 +1597,10 @@ reduce_outer_joins_pass2(Node *jtnode,
16061597
* substitute_multiple_relids - adjust node relid sets after pulling up
16071598
* a subquery
16081599
*
1609-
* Find any FlattenedSubLink, PlaceHolderVar, or PlaceHolderInfo nodes in the
1610-
* given tree that reference the pulled-up relid, and change them to reference
1611-
* the replacement relid(s). We do not need to recurse into subqueries, since
1612-
* no subquery of the current top query could (yet) contain such a reference.
1600+
* Find any FlattenedSubLink or PlaceHolderVar nodes in the given tree that
1601+
* reference the pulled-up relid, and change them to reference the replacement
1602+
* relid(s). We do not need to recurse into subqueries, since no subquery of
1603+
* the current top query could (yet) contain such a reference.
16131604
*
16141605
* NOTE: although this has the form of a walker, we cheat and modify the
16151606
* nodes in-place. This should be OK since the tree was copied by ResolveNew
@@ -1662,26 +1653,11 @@ substitute_multiple_relids_walker(Node *node,
16621653
}
16631654
/* fall through to examine children */
16641655
}
1665-
if (IsA(node, PlaceHolderInfo))
1666-
{
1667-
PlaceHolderInfo *phinfo = (PlaceHolderInfo *) node;
1656+
/* Shouldn't need to handle planner auxiliary nodes here */
1657+
Assert(!IsA(node, SpecialJoinInfo));
1658+
Assert(!IsA(node, AppendRelInfo));
1659+
Assert(!IsA(node, PlaceHolderInfo));
16681660

1669-
if (bms_is_member(context->varno, phinfo->ph_eval_at))
1670-
{
1671-
phinfo->ph_eval_at = bms_union(phinfo->ph_eval_at,
1672-
context->subrelids);
1673-
phinfo->ph_eval_at = bms_del_member(phinfo->ph_eval_at,
1674-
context->varno);
1675-
}
1676-
if (bms_is_member(context->varno, phinfo->ph_needed))
1677-
{
1678-
phinfo->ph_needed = bms_union(phinfo->ph_needed,
1679-
context->subrelids);
1680-
phinfo->ph_needed = bms_del_member(phinfo->ph_needed,
1681-
context->varno);
1682-
}
1683-
/* fall through to examine children */
1684-
}
16851661
return expression_tree_walker(node, substitute_multiple_relids_walker,
16861662
(void *) context);
16871663
}

src/backend/optimizer/prep/prepunion.c

+3-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.159 2008/10/21 20:42:53 tgl Exp $
25+
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.160 2008/10/22 20:17:52 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -1599,26 +1599,10 @@ adjust_appendrel_attrs_mutator(Node *node, AppendRelInfo *context)
15991599
context->child_relid);
16001600
return (Node *) phv;
16011601
}
1602-
if (IsA(node, PlaceHolderInfo))
1603-
{
1604-
/* Copy the PlaceHolderInfo node with correct mutation of subnodes */
1605-
PlaceHolderInfo *phinfo;
1606-
1607-
phinfo = (PlaceHolderInfo *) expression_tree_mutator(node,
1608-
adjust_appendrel_attrs_mutator,
1609-
(void *) context);
1610-
/* now fix PlaceHolderInfo's relid sets */
1611-
phinfo->ph_eval_at = adjust_relid_set(phinfo->ph_eval_at,
1612-
context->parent_relid,
1613-
context->child_relid);
1614-
phinfo->ph_needed = adjust_relid_set(phinfo->ph_needed,
1615-
context->parent_relid,
1616-
context->child_relid);
1617-
return (Node *) phinfo;
1618-
}
1619-
/* Shouldn't need to handle other planner auxiliary nodes here */
1602+
/* Shouldn't need to handle planner auxiliary nodes here */
16201603
Assert(!IsA(node, SpecialJoinInfo));
16211604
Assert(!IsA(node, AppendRelInfo));
1605+
Assert(!IsA(node, PlaceHolderInfo));
16221606

16231607
/*
16241608
* We have to process RestrictInfo nodes specially.

0 commit comments

Comments
 (0)