aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/analyze.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r--src/backend/commands/analyze.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 0137c436931..a889e155f7b 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -533,6 +533,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
{
MemoryContext col_context,
old_context;
+ bool build_ext_stats;
pgstat_progress_update_param(PROGRESS_ANALYZE_PHASE,
PROGRESS_ANALYZE_PHASE_COMPUTE_STATS);
@@ -597,12 +598,27 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
}
/*
+ * Should we build extended statistics for this relation?
+ *
+ * The extended statistics catalog does not include an inheritance
+ * flag, so we can't store statistics built both with and without
+ * data from child relations. We can store just one set of statistics
+ * per relation. For plain relations that's fine, but for inheritance
+ * trees we have to pick whether to store statistics for just the
+ * one relation or the whole tree. For plain inheritance we store
+ * the (!inh) version, mostly for backwards compatibility reasons.
+ * For partitioned tables that's pointless (the non-leaf tables are
+ * always empty), so we store stats representing the whole tree.
+ */
+ build_ext_stats = (onerel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) ? inh : (!inh);
+
+ /*
* Build extended statistics (if there are any).
*
* For now we only build extended statistics on individual relations,
* not for relations representing inheritance trees.
*/
- if (!inh)
+ if (build_ext_stats)
BuildRelationExtStatistics(onerel, totalrows, numrows, rows,
attr_cnt, vacattrstats);
}