Reject incorrect range_bounds_histograms in stats import functions pg_restore_attribute_stats() and pg_restore_extended_stats() (expressions) can handle a STATISTIC_KIND_BOUNDS_HISTOGRAM value, but did not check its shape when importing, especially regarding: - Empty ranges. - Unsorted elements.
These properties are respected by ANALYZE in compute_range_stats(), when computing a histogram for a [multi]range, and by the planner when reading the data from the stats catalogs. The effects of importing data with these properties depend on the compilation options: - A assertion would be hit, if enabled. - A non-sensical value that would make the load of the stats fail. - A failure is hit if an empty range is loaded. While the owner of the table or the one with MAINTAIN rights is responsible for the stats data inserted, buggy data makes little sense if their load is going to fail. This commit adds a validation step to match what compute_range_stats() expects. This issue would be unlikely hit in practice, so no backpatch is done. Author: Ewan Young <[email protected]> Discussion: https://postgr.es/m/caon2xhnm809wlr_g0ymkgu-twxtbyh1xvh4fqzrqy9yp2a5...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/df293aed46e3133df3b5b337f095e3ebed69fd79 Modified Files -------------- src/backend/statistics/attribute_stats.c | 3 +- src/backend/statistics/extended_stats_funcs.c | 2 +- src/backend/statistics/stat_utils.c | 77 +++++++++++++++++++++++++++ src/include/statistics/stat_utils.h | 2 + src/test/regress/expected/stats_import.out | 56 +++++++++++++++++++ src/test/regress/sql/stats_import.sql | 34 ++++++++++++ 6 files changed, 172 insertions(+), 2 deletions(-)
