pgsql: Allow empty arrays of values in pg_restore_attribute_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_attribute_stats()
Date: 2026-11-12 00:54:22
Message-ID: E1xRJ54-00000000NPX-0pTZ@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Allow empty arrays of values in pg_restore_attribute_stats()

ANALYZE can store an empty array of values for range_length_histogram
and most_common_elems, which pg_dump emits as '{}', since 261f89a976b.
These were rejected by pg_restore_attribute_stats(), as an empty array
has no dimensions, and the statistics 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. Arrays stored
as stanumbers are still required to be non-empty, as ANALYZE never
generates them. get_attstatsslot() fails on them.

Some tests are added to cover both the authorized and non-authorized
patterns, in case somebody has a change of mind in the future regarding
one or more of them.

Reported-by: Atish Prakash <125atishprak(at)gmail(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/19857-6e808a09ff4b75d2@postgresql.org
Backpatch-through: 19

Branch
------
REL_19_STABLE

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

Modified Files
--------------
src/backend/statistics/attribute_stats.c | 10 ++--
src/backend/statistics/stat_utils.c | 24 ++++++---
src/include/statistics/stat_utils.h | 3 +-
src/test/regress/expected/stats_import.out | 81 ++++++++++++++++++++++++++++++
src/test/regress/sql/stats_import.sql | 48 ++++++++++++++++++
5 files changed, 154 insertions(+), 12 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Previous Message David Rowley 2026-11-12 00:45:44 pgsql: Fix possible bogus cache miss bug in Memoize nodes