From 01a25256d0ffa310297ed558d8f8dab5f9e6ecb9 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 21 Apr 2007 06:18:52 +0000 Subject: [PATCH] Avoid useless work during set_plain_rel_pathlist() when the relation will be excluded by constraint exclusion anyway. Greg Stark --- src/backend/optimizer/path/allpaths.c | 34 ++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 88a4cdcf5f..469e056c2d 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -196,20 +196,6 @@ set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti) static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) { - /* Mark rel with estimated output rows, width, etc */ - set_baserel_size_estimates(root, rel); - - /* Test any partial indexes of rel for applicability */ - check_partial_indexes(root, rel); - - /* - * Check to see if we can extract any restriction conditions from join - * quals that are OR-of-AND structures. If so, add them to the rel's - * restriction list, and recompute the size estimates. - */ - if (create_or_index_quals(root, rel)) - set_baserel_size_estimates(root, rel); - /* * 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 @@ -217,8 +203,9 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) */ if (relation_excluded_by_constraints(rel, rte)) { - /* Reset output-rows estimate to 0 */ + /* Set dummy size estimates --- we leave attr_widths[] as zeroes */ rel->rows = 0; + rel->width = 0; add_path(rel, (Path *) create_append_path(rel, NIL)); @@ -228,6 +215,20 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) return; } + /* Mark rel with estimated output rows, width, etc */ + set_baserel_size_estimates(root, rel); + + /* Test any partial indexes of rel for applicability */ + check_partial_indexes(root, rel); + + /* + * Check to see if we can extract any restriction conditions from join + * quals that are OR-of-AND structures. If so, add them to the rel's + * restriction list, and recompute the size estimates. + */ + if (create_or_index_quals(root, rel)) + set_baserel_size_estimates(root, rel); + /* * Generate paths and add them to the rel's pathlist. * @@ -369,7 +370,8 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, /* * Propagate size information from the child back to the parent. For * simplicity, we use the largest widths from any child as the parent - * estimates. + * estimates. (If you want to change this, beware of child + * attr_widths[] entries that haven't been set and are still 0.) */ rel->rows += childrel->rows; if (childrel->width > rel->width) -- 2.39.5