public inbox for [email protected]  
help / color / mirror / Atom feed
From: Michael Paquier <[email protected]>
To: [email protected]
Subject: pgsql: Reject incorrect range_bounds_histograms in stats import functio
Date: Thu, 09 Jul 2026 05:40:27 +0000
Message-ID: <[email protected]> (raw)

Reject incorrect range_bounds_histograms in stats import functions

pg_restore_attribute_stats() and pg_restore_extended_stats()
(expressions) can handle a STATISTIC_KIND_BOUNDS_HISTOGRAM value, but
did not check its shape when importing, especially regarding:
- Empty ranges.
- Unsorted elements.

These properties are respected by ANALYZE in compute_range_stats(), when
computing a histogram for a [multi]range, and by the planner when
reading the data from the stats catalogs.  The effects of importing data
with these properties depend on the compilation options:
- A assertion would be hit, if enabled.
- A non-sensical value that would make the load of the stats fail.
- A failure is hit if an empty range is loaded.

While the owner of the table or the one with MAINTAIN rights is
responsible for the stats data inserted, buggy data makes little sense
if their load is going to fail.  This commit adds a validation step to
match what compute_range_stats() expects.

This issue would be unlikely hit in practice, so no backpatch is done.

Author: Ewan Young <[email protected]>
Discussion: https://postgr.es/m/CAON2xHNM809WLR_g0ymKgU-tWxtbyH1Xvh4fqzRqy9YP2A59pg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/df293aed46e3133df3b5b337f095e3ebed69fd79

Modified Files
--------------
src/backend/statistics/attribute_stats.c      |  3 +-
src/backend/statistics/extended_stats_funcs.c |  2 +-
src/backend/statistics/stat_utils.c           | 77 +++++++++++++++++++++++++++
src/include/statistics/stat_utils.h           |  2 +
src/test/regress/expected/stats_import.out    | 56 +++++++++++++++++++
src/test/regress/sql/stats_import.sql         | 34 ++++++++++++
6 files changed, 172 insertions(+), 2 deletions(-)



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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgsql: Reject incorrect range_bounds_histograms in stats import functio
  In-Reply-To: <[email protected]>

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

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