1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-14 08:21:07 +03:00

Improve relation width estimation for subqueries.

As per the ancient comment for set_rel_width, it really wasn't much good
for relations that aren't plain tables: it would never find any stats and
would always fall back on datatype-based estimates, which are often pretty
silly.  Fix that by copying up width estimates from the subquery planning
process.

At some point we might want to do this for CTEs too, but that would be a
significantly more invasive patch because the sub-PlannerInfo is no longer
accessible by the time it's needed.  I refrained from doing anything about
that, partly for fear of breaking the unmerged CTE-related patches.

In passing, also generate less bogus width estimates for whole-row Vars.

Per a gripe from Jon Nelson.
This commit is contained in:
Tom Lane
2010-11-19 17:31:50 -05:00
parent fe24d78161
commit 0f61d4dd1b
6 changed files with 150 additions and 20 deletions

View File

@ -758,11 +758,8 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
rel->subrtable = subroot->parse->rtable;
rel->subrowmark = subroot->rowMarks;
/* Copy number of output rows from subplan */
rel->tuples = rel->subplan->plan_rows;
/* Mark rel with estimated output rows, width, etc */
set_baserel_size_estimates(root, rel);
set_subquery_size_estimates(root, rel, subroot);
/* Convert subquery pathkeys to outer representation */
pathkeys = convert_subquery_pathkeys(root, rel, subroot->query_pathkeys);