diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-04-21 21:01:45 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-04-21 21:01:45 +0000 |
commit | afcf09dd9034f24e34dd46f69938882ab5b103d2 (patch) | |
tree | 497edd9a542b2bc9312afe2f39341f7b95a892c5 /src/backend/optimizer/path | |
parent | ac7e6c0665a377fb0e4e5b12cfc762c1b14e425e (diff) |
Some further performance tweaks for planning large inheritance trees that
are mostly excluded by constraints: do the CE test a bit earlier to save
some adjust_appendrel_attrs() work on excluded children, and arrange to
use array indexing rather than rt_fetch() to fetch RTEs in the main body
of the planner. The latter is something I'd wanted to do for awhile anyway,
but seeing list_nth_cell() as 35% of the runtime gets one's attention.
Diffstat (limited to 'src/backend/optimizer/path')
-rw-r--r-- | src/backend/optimizer/path/allpaths.c | 47 | ||||
-rw-r--r-- | src/backend/optimizer/path/clausesel.c | 4 | ||||
-rw-r--r-- | src/backend/optimizer/path/costsize.c | 8 |
3 files changed, 36 insertions, 23 deletions
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 0d87291025f..07a99e9c6b7 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.162 2007/04/21 06:18:52 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.163 2007/04/21 21:01:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -39,7 +39,8 @@ int geqo_threshold; static void set_base_rel_pathlists(PlannerInfo *root); -static void set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti); +static void set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, + Index rti, RangeTblEntry *rte); static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte); static void set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, @@ -144,7 +145,7 @@ set_base_rel_pathlists(PlannerInfo *root) if (rel->reloptkind != RELOPT_BASEREL) continue; - set_rel_pathlist(root, rel, rti); + set_rel_pathlist(root, rel, rti, root->simple_rte_array[rti]); } } @@ -153,10 +154,9 @@ set_base_rel_pathlists(PlannerInfo *root) * Build access paths for a base relation */ static void -set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti) +set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, + Index rti, RangeTblEntry *rte) { - RangeTblEntry *rte = rt_fetch(rti, root->parse->rtable); - if (rte->inh) { /* It's an "append relation", process accordingly */ @@ -200,8 +200,11 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) * If we can prove we don't need to scan the rel via constraint exclusion, * set up a single dummy path for it. (Rather than inventing a special * "dummy" path type, we represent this as an AppendPath with no members.) + * We only need to check for regular baserels; if it's an otherrel, CE + * was already checked in set_append_rel_pathlist(). */ - if (relation_excluded_by_constraints(rel, rte)) + if (rel->reloptkind == RELOPT_BASEREL && + relation_excluded_by_constraints(rel, rte)) { /* Set dummy size estimates --- we leave attr_widths[] as zeroes */ rel->rows = 0; @@ -294,6 +297,7 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, { AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l); int childRTindex; + RangeTblEntry *childRTE; RelOptInfo *childrel; Path *childpath; ListCell *parentvars; @@ -304,6 +308,7 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, continue; childRTindex = appinfo->child_relid; + childRTE = root->simple_rte_array[childRTindex]; /* * The child rel's RelOptInfo was already created during @@ -313,18 +318,29 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Assert(childrel->reloptkind == RELOPT_OTHER_MEMBER_REL); /* - * Copy the parent's targetlist and quals to the child, with - * appropriate substitution of variables. + * We have to copy the parent's targetlist and quals to the child, + * with appropriate substitution of variables. However, only the + * baserestrictinfo quals are needed before we can check for + * constraint exclusion; so do that first and then check to see + * if we can disregard this child. */ - childrel->reltargetlist = (List *) - adjust_appendrel_attrs((Node *) rel->reltargetlist, - appinfo); childrel->baserestrictinfo = (List *) adjust_appendrel_attrs((Node *) rel->baserestrictinfo, appinfo); + + if (relation_excluded_by_constraints(childrel, childRTE)) + { + /* this child need not be scanned, so just disregard it */ + continue; + } + + /* CE failed, so finish copying targetlist and join quals */ childrel->joininfo = (List *) adjust_appendrel_attrs((Node *) rel->joininfo, appinfo); + childrel->reltargetlist = (List *) + adjust_appendrel_attrs((Node *) rel->reltargetlist, + appinfo); /* * We have to make child entries in the EquivalenceClass data @@ -353,12 +369,9 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, * It's possible that the child is itself an appendrel, in which case * we can "cut out the middleman" and just add its child paths to our * own list. (We don't try to do this earlier because we need to - * apply both levels of transformation to the quals.) This test also - * handles the case where the child rel need not be scanned because of - * constraint exclusion: it'll have an Append path with no subpaths, - * and will vanish from our list. + * apply both levels of transformation to the quals.) */ - set_rel_pathlist(root, childrel, childRTindex); + set_rel_pathlist(root, childrel, childRTindex, childRTE); childpath = childrel->cheapest_total_path; if (IsA(childpath, AppendPath)) diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c index 405ab6fcc3a..b8bbc29c505 100644 --- a/src/backend/optimizer/path/clausesel.c +++ b/src/backend/optimizer/path/clausesel.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.84 2007/02/19 07:03:28 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.85 2007/04/21 21:01:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -500,7 +500,7 @@ clause_selectivity(PlannerInfo *root, if (var->varlevelsup == 0 && (varRelid == 0 || varRelid == (int) var->varno)) { - RangeTblEntry *rte = rt_fetch(var->varno, root->parse->rtable); + RangeTblEntry *rte = planner_rt_fetch(var->varno, root); if (rte->rtekind == RTE_SUBQUERY) { diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 42a5520b974..9cd3a51d897 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -54,7 +54,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.180 2007/04/21 02:41:13 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.181 2007/04/21 21:01:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -856,7 +856,7 @@ cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel) /* Should only be applied to base relations that are functions */ Assert(baserel->relid > 0); - rte = rt_fetch(baserel->relid, root->parse->rtable); + rte = planner_rt_fetch(baserel->relid, root); Assert(rte->rtekind == RTE_FUNCTION); /* Estimate costs of executing the function expression */ @@ -2297,7 +2297,7 @@ set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel) /* Should only be applied to base relations that are functions */ Assert(rel->relid > 0); - rte = rt_fetch(rel->relid, root->parse->rtable); + rte = planner_rt_fetch(rel->relid, root); Assert(rte->rtekind == RTE_FUNCTION); /* Estimate number of rows the function itself will return */ @@ -2323,7 +2323,7 @@ set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel) /* Should only be applied to base relations that are values lists */ Assert(rel->relid > 0); - rte = rt_fetch(rel->relid, root->parse->rtable); + rte = planner_rt_fetch(rel->relid, root); Assert(rte->rtekind == RTE_VALUES); /* |