pgsql: Fix compute_scalar_stats() for case that all values exceed WIDTH

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix compute_scalar_stats() for case that all values exceed WIDTH
Date: 2014-01-11 18:43:03
Message-ID: E1W23WR-0004P6-F0@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix compute_scalar_stats() for case that all values exceed WIDTH_THRESHOLD.

The standard typanalyze functions skip over values whose detoasted size
exceeds WIDTH_THRESHOLD (1024 bytes), so as to limit memory bloat during
ANALYZE. However, we (I think I, actually :-() failed to consider the
possibility that *every* non-null value in a column is too wide. While
compute_minimal_stats() seems to behave reasonably anyway in such a case,
compute_scalar_stats() just fell through and generated no pg_statistic
entry at all. That's unnecessarily pessimistic: we can still produce
valid stanullfrac and stawidth values in such cases, since we do include
too-wide values in the average-width calculation. Furthermore, since the
general assumption in this code is that too-wide values are probably all
distinct from each other, it seems reasonable to set stadistinct to -1
("all distinct").

Per complaint from Kadri Raudsepp. This has been like this since roughly
neolithic times, so back-patch to all supported branches.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/6286526207d53e5b31968103adb89b4c9cd21499

Modified Files
--------------
src/backend/commands/analyze.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2014-01-11 19:01:14 pgsql: Revert fd2ace802811c333b0b4e1a28b138fd4774745f3
Previous Message Bruce Momjian 2014-01-11 18:41:43 pgsql: docs: remove undocumented assign syntax in plpgsql examples