| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Lift range_bounds_histogram requirement in pg_restore_extended_s |
| Date: | 2026-11-13 02:38:56 |
| Message-ID: | E1xRhBo-00000000Vh3-1wMh@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Lift range_bounds_histogram requirement in pg_restore_extended_stats()
pg_restore_extended_stats() required range_bounds_histogram,
range_length_histogram and range_empty_frac to be either all set or
all missing for an expression. This is an incorrect assumption, due to:
* range_length_histogram and range_empty_frac sharing the
STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM slot.
* range_bounds_histogram having its own STATISTIC_KIND_BOUNDS_HISTOGRAM
slot.
Only the first two need to be given together. Note that
pg_restore_attribute_stats() already works this way.
ANALYZE generates a bounds histogram only when there are at least two
non-empty range values, and it always stores the length histogram
slot with the fraction of empty ranges. An empty array of values for
the histogram is used if there are fewer than two non-empty values.
Hence, the statistics of an expression with fewer than two non-empty
range values could never be restored, as the bounds histogram was
missing.
This is a pretty narrow case, unlikely going to be hit in practice. Its
consequence was a failure when restoring the statistics of the extstats
object being processed, in the shape of a warning and missing stats
after an upgrade or the restore of a dump.
Issue noticed by Corey, while digging into a separate issue.
Author: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Discussion: https://postgr.es/m/19842-ca042326dd2430a4@postgresql.org
Backpatch-through: 19
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/13eb56409f5b6ed15e3ab5fa2b1fa98f66932c10
Modified Files
--------------
src/backend/statistics/extended_stats_funcs.c | 20 ++++++-----------
src/test/regress/expected/stats_import.out | 31 +++++++++++----------------
src/test/regress/sql/stats_import.sql | 19 ++++++++--------
3 files changed, 29 insertions(+), 41 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-11-13 04:26:00 | pgsql: Allow empty arrays of values in pg_restore_extended_stats() |
| Previous Message | Richard Guo | 2026-11-13 00:54:38 | pgsql: Fix GROUP BY column removal for NULLS NOT DISTINCT indexes |