Fix import of statistics for domains over [multi]range types and tsvector

pg_restore_attribute_stats() rejected range_length_histogram,
range_empty_frac and range_bounds_histogram for a column whose type is a
domain over a range or a multirange type.  The same issue existed for
most_common_elems and elem_count_histogram for a domain over tsvector.
pg_restore_extended_stats() had the same set of problems for expressions
whose type is a domain over a range, a multirange type, or tsvector.

ANALYZE is able to generate such stats, incorporating the knowledge to
handle domains in the in-core typanalyze callbacks.

This problem is resolved by being more aggressive with the fetch of the
base type of a domain in the early phases of restore for attribute and
extended stats (special tip to Jian He for pointing out the unnecessary
typcache lookups), reflecting on the surrounding helper routines shared
by both code paths.  The fix for v18 is local to attribute_stats.c, as
only attribute stats need to be touched.

Tests are included in a fashion consistent with the surroundings.  The
consequence of this issue was the rejection of stats that ANALYZE was
able to build, which was not critical but annoying as it would lead to a
gap in the stats restored.

Reported-by: Qifan Liu <[email protected]>
Author: Michael Paquier <[email protected]>
Reviewed-by: Jian He <[email protected]>
Reviewed-by: Corey Huinker <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 18

Branch
------
REL_19_STABLE

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

Modified Files
--------------
src/backend/statistics/attribute_stats.c      |  21 +-
src/backend/statistics/extended_stats_funcs.c |  33 ++-
src/backend/statistics/stat_utils.c           |  64 +++--
src/include/statistics/stat_utils.h           |   9 +-
src/test/regress/expected/stats_import.out    | 332 +++++++++++++++++++++++++-
src/test/regress/sql/stats_import.sql         | 251 +++++++++++++++++++
6 files changed, 663 insertions(+), 47 deletions(-)

Reply via email to