Add pg_statistic_ext_data.stxdinherit flag, so that for each extended statistics definition we can store two versions of data - one for the relation alone, one for the whole inheritance tree. This is analogous to pg_statistic.stainherit, but we failed to include such flag in catalogs for extended statistics, and we had to work around it (see commits 859b3003de, 36c4bc6e72 and 20b9fa308e).
This changes the relationship between the two catalogs storing extended statistics objects (pg_statistic_ext and pg_statistic_ext_data). Until now, there was a simple 1:1 mapping - for each definition there was one pg_statistic_ext_data row, and this row was inserted while creating the statistics (and then updated during ANALYZE). With the stxdinherit flag, we don't know how many rows there will be (child relations may be added after the statistics object is defined), so there may be up to two rows.
We could make CREATE STATISTICS to always create both rows, but that seems wasteful - without partitioning we only need stxdinherit=false rows, and declaratively partitioned tables need only stxdinherit=true. So we no longer initialize pg_statistic_ext_data in CREATE STATISTICS, and instead make that a responsibility of ANALYZE. Which is what we do for regular statistics too.
Patch by me, with extensive improvements and fixes by Justin Pryzby.
Author: Tomas Vondra, Justin Pryzby
269b532aef Add stxdinherit flag to pg_statistic_ext_data
doc/src/sgml/catalogs.sgml | 23 +++++
src/backend/catalog/system_views.sql | 2 +
src/backend/commands/analyze.c | 28 +-----
src/backend/commands/statscmds.c | 72 +++++++-------
src/backend/optimizer/util/plancat.c | 146 +++++++++++++++++-----------
src/backend/statistics/dependencies.c | 22 ++---
src/backend/statistics/extended_stats.c | 75 +++++++-------
src/backend/statistics/mcv.c | 8 +-
src/backend/statistics/mvdistinct.c | 5 +-
src/backend/utils/adt/selfuncs.c | 37 +------
src/backend/utils/cache/syscache.c | 6 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_statistic_ext_data.h | 4 +-
src/include/commands/defrem.h | 1 +
src/include/nodes/pathnodes.h | 1 +
src/include/statistics/statistics.h | 11 ++-
src/test/regress/expected/rules.out | 2 +
src/test/regress/expected/stats_ext.out | 31 ++++--
src/test/regress/sql/stats_ext.sql | 13 +--
19 files changed, 252 insertions(+), 237 deletions(-)