diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-08-05 15:00:57 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-08-05 15:01:09 -0400 |
commit | 3ced8837db2cd602422bb36102cec73289691d40 (patch) | |
tree | 0fae9ca9ba7f5f259ef678d685717a70710ac0c4 /src/backend/optimizer/util/relnode.c | |
parent | 841c29c8b3be98ee30486ee245ebee782d4dedd4 (diff) |
Simplify query_planner's API by having it return the top-level RelOptInfo.
Formerly, query_planner returned one or possibly two Paths for the topmost
join relation, so that grouping_planner didn't see the join RelOptInfo
(at least not directly; it didn't have any hesitation about examining
cheapest_path->parent, though). However, correct selection of the Paths
involved a significant amount of coupling between query_planner and
grouping_planner, a problem which has gotten worse over time. It seems
best to give up on this API choice and instead return the topmost
RelOptInfo explicitly. Then grouping_planner can pull out the Paths it
wants from the rel's path list. In this way we can remove all knowledge
of grouping behaviors from query_planner.
The only real benefit of the old way is that in the case of an empty
FROM clause, we never made any RelOptInfos at all, just a Path. Now
we have to gin up a dummy RelOptInfo to represent the empty FROM clause.
That's not a very big deal though.
While at it, simplify query_planner's API a bit more by having the caller
set up root->tuple_fraction and root->limit_tuples, rather than passing
those values as separate parameters. Since query_planner no longer does
anything with either value, requiring it to fill the PlannerInfo fields
seemed pretty arbitrary.
This patch just rearranges code; it doesn't (intentionally) change any
behaviors. Followup patches will do more interesting things.
Diffstat (limited to 'src/backend/optimizer/util/relnode.c')
-rw-r--r-- | src/backend/optimizer/util/relnode.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index 8ee5671a551..1f198201c32 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -677,6 +677,36 @@ subbuild_joinrel_joinlist(RelOptInfo *joinrel, /* + * build_empty_join_rel + * Build a dummy join relation describing an empty set of base rels. + * + * This is used for queries with empty FROM clauses, such as "SELECT 2+2" or + * "INSERT INTO foo VALUES(...)". We don't try very hard to make the empty + * joinrel completely valid, since no real planning will be done with it --- + * we just need it to carry a simple Result path out of query_planner(). + */ +RelOptInfo * +build_empty_join_rel(PlannerInfo *root) +{ + RelOptInfo *joinrel; + + /* The dummy join relation should be the only one ... */ + Assert(root->join_rel_list == NIL); + + joinrel = makeNode(RelOptInfo); + joinrel->reloptkind = RELOPT_JOINREL; + joinrel->relids = NULL; /* empty set */ + joinrel->rows = 1; /* we produce one row for such cases */ + joinrel->width = 0; /* it contains no Vars */ + joinrel->rtekind = RTE_JOIN; + + root->join_rel_list = lappend(root->join_rel_list, joinrel); + + return joinrel; +} + + +/* * find_childrel_appendrelinfo * Get the AppendRelInfo associated with an appendrel child rel. * |