pgsql: Store empty stavalues when needed for expression statistics.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Store empty stavalues when needed for expression statistics.
Date: 2026-11-11 16:04:19
Message-ID: E1xRAo7-00000000KfC-2j40@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Store empty stavalues when needed for expression statistics.

Commit 261f89a97 changed the API contract for update_attstats()
to store an empty array, not a NULL, if it's passed a nonnull
stavalues pointer along with a zero values count. We missed
that serialize_expr_stats() needs to be kept in sync with that,
so that now we get "unexpected null value" errors if statistics
on an expression hit one of the cases where the statistics
collection code requests that.

Rather than just adjusting serialize_expr_stats() to match, let's
avoid having duplicated code at all, by factoring out a routine
to build a pg_statistic tuple from a VacAttrStats structure.

Bug: #19849
Reported-by: Atish Prakash <125atishprak(at)gmail(dot)com>
Author: Atish Prakash <125atishprak(at)gmail(dot)com>
Co-authored-by: Shihao Zhong <zhong950419(at)gmail(dot)com>
Co-authored-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/19849-38b8bd2fea807154@postgresql.org
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/44cf2892bbfa2fe7ece791adb072edecf56af365

Modified Files
--------------
src/backend/commands/analyze.c | 201 ++++++++++++++++++--------------
src/backend/statistics/extended_stats.c | 85 +-------------
src/include/commands/vacuum.h | 4 +
src/test/regress/expected/stats_ext.out | 18 +++
src/test/regress/sql/stats_ext.sql | 10 ++
5 files changed, 151 insertions(+), 167 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2026-11-11 16:19:37 pgsql: Have the REPACK decoding worker use temp_file_limit from the ste
Previous Message Álvaro Herrera 2026-11-11 15:52:38 pgsql: REPACK: Reword complaint about shared relations