diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-09-03 15:35:12 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-09-03 15:36:24 -0400 |
commit | b3aaf9081a1a95c245fd605dcf02c91b3a5c3a29 (patch) | |
tree | c3c0c1bd1fdc77722d139f1add99c7abb7a922ef /src/backend/optimizer/util/relnode.c | |
parent | 42ad992fdc25fa69db03ff242216f6712da2c56a (diff) | |
download | postgresql-b3aaf9081a1a95c245fd605dcf02c91b3a5c3a29.tar.gz |
Rearrange planner to save the whole PlannerInfo (subroot) for a subquery.
Formerly, set_subquery_pathlist and other creators of plans for subqueries
saved only the rangetable and rowMarks lists from the lower-level
PlannerInfo. But there's no reason not to remember the whole PlannerInfo,
and indeed this turns out to simplify matters in a number of places.
The immediate reason for doing this was so that the subroot will still be
accessible when we're trying to extract column statistics out of an
already-planned subquery. But now that I've done it, it seems like a good
code-beautification effort in its own right.
I also chose to get rid of the transient subrtable and subrowmark fields in
SubqueryScan nodes, in favor of having setrefs.c look up the subquery's
RelOptInfo. That required changing all the APIs in setrefs.c to pass
PlannerInfo not PlannerGlobal, which was a large but quite mechanical
transformation.
One side-effect not foreseen at the beginning is that this finally broke
inheritance_planner's assumption that replanning the same subquery RTE N
times would necessarily give interchangeable results each time. That
assumption was always pretty risky, but now we really have to make a
separate RTE for each instance so that there's a place to carry the
separate subroots.
Diffstat (limited to 'src/backend/optimizer/util/relnode.c')
-rw-r--r-- | src/backend/optimizer/util/relnode.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index b59eb090aa..1df727d9fc 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -46,6 +46,35 @@ static List *subbuild_joinrel_joinlist(RelOptInfo *joinrel, /* + * setup_simple_rel_arrays + * Prepare the arrays we use for quickly accessing base relations. + */ +void +setup_simple_rel_arrays(PlannerInfo *root) +{ + Index rti; + ListCell *lc; + + /* Arrays are accessed using RT indexes (1..N) */ + root->simple_rel_array_size = list_length(root->parse->rtable) + 1; + + /* simple_rel_array is initialized to all NULLs */ + root->simple_rel_array = (RelOptInfo **) + palloc0(root->simple_rel_array_size * sizeof(RelOptInfo *)); + + /* simple_rte_array is an array equivalent of the rtable list */ + root->simple_rte_array = (RangeTblEntry **) + palloc0(root->simple_rel_array_size * sizeof(RangeTblEntry *)); + rti = 1; + foreach(lc, root->parse->rtable) + { + RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc); + + root->simple_rte_array[rti++] = rte; + } +} + +/* * build_simple_rel * Construct a new RelOptInfo for a base relation or 'other' relation. */ @@ -81,8 +110,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptKind reloptkind) rel->pages = 0; rel->tuples = 0; rel->subplan = NULL; - rel->subrtable = NIL; - rel->subrowmark = NIL; + rel->subroot = NULL; rel->baserestrictinfo = NIL; rel->baserestrictcost.startup = 0; rel->baserestrictcost.per_tuple = 0; @@ -335,8 +363,7 @@ build_join_rel(PlannerInfo *root, joinrel->pages = 0; joinrel->tuples = 0; joinrel->subplan = NULL; - joinrel->subrtable = NIL; - joinrel->subrowmark = NIL; + joinrel->subroot = NULL; joinrel->baserestrictinfo = NIL; joinrel->baserestrictcost.startup = 0; joinrel->baserestrictcost.per_tuple = 0; |