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 <[email protected]>
Author: Atish Prakash <[email protected]>
Co-authored-by: Shihao Zhong <[email protected]>
Co-authored-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 19

Branch
------
REL_19_STABLE

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

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(-)

Reply via email to