pgsql: Allow empty arrays of values in pg_restore_extended_stats()

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Allow empty arrays of values in pg_restore_extended_stats()
Date: 2026-11-13 04:26:00
Message-ID: E1xRirQ-00000000WBG-1uS7@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Allow empty arrays of values in pg_restore_extended_stats()

ANALYZE can store an empty array of values for range_length_histogram
and most_common_elems in the statistics of an expression, which pg_dump
emits as '{}', since 261f89a976b. These were rejected by
pg_restore_extended_stats(), as an empty array has no dimensions, and
the statistics of the expression were lost after a dump/restore or an
upgrade *from* v19 or HEAD. Empty arrays are not possible for these two
properties in v18 and older versions.

This commit allows empty arrays for these two cases only, like
2656f664616d did for pg_restore_attribute_stats(). Arrays stored as
stanumbers are still required to be non-empty, as ANALYZE never
generates them. In terms of range_length_histogram, this commit
completes 13eb56409f5b, as ANALYZE never generates a bounds histogram
when the length histogram is empty.

Some tests are added to cover all the new patterns involving empty
arrays.

Reported-by: Chunling Qin <303677365(at)qq(dot)com>
Author: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Author: Michael Paquier <michael(at)paquier(dot)xyz>
Discussion: https://postgr.es/m/19842-ca042326dd2430a4@postgresql.org
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/87524d0dd8470819ce8aa3708a9bf3fa3f1d34fd

Modified Files
--------------
src/backend/statistics/extended_stats_funcs.c | 42 +++++++++-----
src/test/regress/expected/stats_import.out | 82 +++++++++++++++++++++++++++
src/test/regress/sql/stats_import.sql | 54 ++++++++++++++++++
3 files changed, 163 insertions(+), 15 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2026-11-13 06:46:36 pgsql: Doc: Clarify ONLY and * on partitioned tables in publications.
Previous Message Michael Paquier 2026-11-13 02:38:56 pgsql: Lift range_bounds_histogram requirement in pg_restore_extended_s