OSDN Git Service

Improve relation width estimation for subqueries.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Nov 2010 22:31:50 +0000 (17:31 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Nov 2010 22:31:50 +0000 (17:31 -0500)
commit0f61d4dd1b4f95832dcd81c9688dac56fd6b5687
tree9bb1e825dc323f19cc1969b1bcbdfd13b80fce98
parentfe24d781612700646bfb3e08925e34c43926f9df
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.
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/util/plancat.c
src/include/optimizer/cost.h
src/include/optimizer/plancat.h