pgsql: Fix overoptimistic assumptions in column width estimation for su

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix overoptimistic assumptions in column width estimation for su
Date: 2011-08-23 21:13:59
Message-ID: E1QvyIJ-0001mi-Lq@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/43f0c20839aa82705700e4de5bb452b7f044c838

Modified Files
--------------
src/backend/optimizer/path/allpaths.c | 45 ++++++++++++++++++++++++---------
src/backend/optimizer/path/costsize.c | 21 ++++++++-------
2 files changed, 44 insertions(+), 22 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2011-08-24 01:49:45 pgsql: Make CREATE EXTENSION check schema creation permissions.
Previous Message Peter Eisentraut 2011-08-23 19:02:34 pgsql: Use consistent format for reporting GetLastError()