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