pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Lift range_bounds_histogram requirement in pg_restore_extended_s
Date: Fri, 13 Nov 2026 02:38:56 +0000
Message-ID: <E1xRhBo-00000000Vh3-1wMh@gemulon.postgresql.org> (raw)

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.huinker@gmail.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(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1xRhBo-00000000Vh3-1wMh@gemulon.postgresql.org>
Permalink:  ../E1xRhBo-00000000Vh3-1wMh@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xRhBo-00000000Vh3-1wMh@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Lift range_bounds_histogram requirement in pg_restore_extended_s
  In-Reply-To: <E1xRhBo-00000000Vh3-1wMh@gemulon.postgresql.org>
  References: <E1xRhBo-00000000Vh3-1wMh@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox