]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix overoptimistic assumptions in column width estimation for subqueries.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Aug 2011 21:11:41 +0000 (17:11 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Aug 2011 21:13:30 +0000 (17:13 -0400)
commit48f545a3aef461a635b975443a99dd268269590a
tree0fa47ea0a32c671ad9e883056384fb34cbc75be6
parent26a092657ba4ac52212d43bae9a822a119efbd8a
Fix overoptimistic assumptions in column width estimation for subqueries.

set_append_rel_pathlist supposed that, while computing per-column width
estimates for the appendrel, it could ignore child rels for which the
translated reltargetlist entry wasn't a Var.  This gave rise to completely
silly estimates in some common cases, such as constant outputs from some or
all of the arms of a UNION ALL.  Instead, fall back on get_typavgwidth to
estimate from the value's datatype; which might be a poor estimate but at
least it's not completely wacko.

That problem was exposed by an Assert in set_subquery_size_estimates, which
unfortunately was still overoptimistic even with that fix, since we don't
compute attr_widths estimates for appendrels that are entirely excluded by
constraints.  So remove the Assert; we'll just fall back on get_typavgwidth
in such cases.

Also, since set_subquery_size_estimates calls set_baserel_size_estimates
which calls set_rel_width, there's no need for set_subquery_size_estimates
to call get_typavgwidth; set_rel_width will handle it for us if we just
leave the estimate set to zero.  Remove the unnecessary code.

Per report from Erik Rijkers and subsequent investigation.
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/path/costsize.c