Add support for "mcv" in pg_restore_extended_stats() This commit adds support for the restore of extended statistics of the kind "mcv", aka most-common values.
This format is different from n_distinct and dependencies stat types in that it is the combination of three of the four different arrays from the pg_stats_ext view which in turn require three different input parameters on pg_restore_extended_statistics(). These are translated into three input arguments for the function: - "most_common_vals", acting as a leader of the others. It is a 2-dimension array, that includes the common values. - "most_common_freqs", 1-dimension array of float8[], with a number of elements that has to match with "most_common_vals". - "most_common_base_freqs", 1-dimension array of float8[], with a number of elements that has to match with "most_common_vals". All three arrays are required to achieve the restore of this type of extended statistics (if "most_common_vals" happens to be NULL in the catalogs, the rest is NULL by design). Note that "most_common_val_nulls" is not required in input, its data is rebuilt from the decomposition of the "most_common_vals" array based on its text[] representation. The initial versions of the patch provided this option in input, but we do not require it and it simplifies a lot the result. Support in pg_dump is added down to v13 which is where the support for this type of extended statistics has been added, when --statistics is used. This means that upgrade and dumps can restore extended statistics data transparently, like "dependencies", "ndistinct", attribute and relation statistics. For MCV, the values are directly queried from the relevant catalogs. Author: Corey Huinker <[email protected]> Co-authored-by: Chao Li <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qn3kx...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/efbebb4e85872b1c4d6bc19c4550e67850b83aab Modified Files -------------- doc/src/sgml/func/func-admin.sgml | 6 +- src/backend/statistics/extended_stats_funcs.c | 285 ++++++++++++++++++++++- src/backend/statistics/mcv.c | 145 ++++++++++++ src/bin/pg_dump/pg_dump.c | 29 ++- src/include/statistics/extended_stats_internal.h | 5 + src/test/regress/expected/stats_import.out | 210 +++++++++++++++++ src/test/regress/sql/stats_import.sql | 148 ++++++++++++ 7 files changed, 823 insertions(+), 5 deletions(-)
