mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
autovacuum: handle analyze for partitioned tables
Previously, autovacuum would completely ignore partitioned tables, which is not good regarding analyze -- failing to analyze those tables means poor plans may be chosen. Make autovacuum aware of those tables by propagating "changes since analyze" counts from the leaf partitions up the partitioning hierarchy. This also introduces necessary reloptions support for partitioned tables (autovacuum_enabled, autovacuum_analyze_scale_factor, autovacuum_analyze_threshold). It's unclear how best to document this aspect. Author: Yuzuko Hosoya <yuzukohosoya@gmail.com> Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/CAKkQ508_PwVgwJyBY=0Lmkz90j8CmWNPUxgHvCUwGhMrouz6UA@mail.gmail.com
This commit is contained in:
@ -612,8 +612,8 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
|
||||
PROGRESS_ANALYZE_PHASE_FINALIZE_ANALYZE);
|
||||
|
||||
/*
|
||||
* Update pages/tuples stats in pg_class, and report ANALYZE to the stats
|
||||
* collector ... but not if we're doing inherited stats.
|
||||
* Update pages/tuples stats in pg_class ... but not if we're doing
|
||||
* inherited stats.
|
||||
*
|
||||
* We assume that VACUUM hasn't set pg_class.reltuples already, even
|
||||
* during a VACUUM ANALYZE. Although VACUUM often updates pg_class,
|
||||
@ -655,19 +655,35 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
|
||||
InvalidMultiXactId,
|
||||
in_outer_xact);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Now report ANALYZE to the stats collector.
|
||||
*
|
||||
* We deliberately don't report to the stats collector when doing
|
||||
* inherited stats, because the stats collector only tracks per-table
|
||||
* stats.
|
||||
*
|
||||
* Reset the changes_since_analyze counter only if we analyzed all
|
||||
* columns; otherwise, there is still work for auto-analyze to do.
|
||||
*/
|
||||
/*
|
||||
* Now report ANALYZE to the stats collector. For regular tables, we do
|
||||
* it only if not doing inherited stats. For partitioned tables, we only
|
||||
* do it for inherited stats. (We're never called for not-inherited stats
|
||||
* on partitioned tables anyway.)
|
||||
*
|
||||
* Reset the changes_since_analyze counter only if we analyzed all
|
||||
* columns; otherwise, there is still work for auto-analyze to do.
|
||||
*/
|
||||
if (!inh || onerel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
|
||||
pgstat_report_analyze(onerel, totalrows, totaldeadrows,
|
||||
(va_cols == NIL));
|
||||
|
||||
/*
|
||||
* If this is a manual analyze of all columns of a permanent leaf
|
||||
* partition, and not doing inherited stats, also let the collector know
|
||||
* about the ancestor tables of this partition. Autovacuum does the
|
||||
* equivalent of this at the start of its run, so there's no reason to do
|
||||
* it there.
|
||||
*/
|
||||
if (!inh && !IsAutoVacuumWorkerProcess() &&
|
||||
(va_cols == NIL) &&
|
||||
onerel->rd_rel->relispartition &&
|
||||
onerel->rd_rel->relkind == RELKIND_RELATION &&
|
||||
onerel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
|
||||
{
|
||||
pgstat_report_anl_ancestors(RelationGetRelid(onerel));
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user