partitioned-reltuples.patch
text/x-diff
Filename: partitioned-reltuples.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/commands/analyze.c | 11 | 0 |
| src/backend/postmaster/autovacuum.c | 1 | 38 |
commit 5ddb7c00e5f1d63eb251d334afce738919a772c0
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
AuthorDate: Wed Apr 7 23:52:33 2021 -0400
CommitDate: Wed Apr 7 23:52:33 2021 -0400
set pg_class.reltuples for partitioned tables
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 0789117bb8..36e35722bc 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -656,6 +656,17 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
in_outer_xact);
}
}
+ else if (onerel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
+ {
+ /*
+ * Partitioned tables don't have storage, so we don't set any of these
+ * value in their pg_class entries. However, reltuples is necessary
+ * in order for auto-analyze to work properly, so update that.
+ */
+ vac_update_relstats(onerel, 0, totalrows,
+ 0, false, InvalidTransactionId, InvalidMultiXactId,
+ in_outer_xact);
+ }
/*
* Now report ANALYZE to the stats collector. For regular tables, we do
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 5517836be6..48c1bf048f 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -3208,44 +3208,7 @@ relation_needs_vacanalyze(Oid relid,
*/
if (PointerIsValid(tabentry) && AutoVacuumingActive())
{
- if (classForm->relkind != RELKIND_PARTITIONED_TABLE)
- {
- reltuples = classForm->reltuples;
- }
- else
- {
- /*
- * If the relation is a partitioned table, we must add up
- * children's reltuples.
- */
- List *children;
- ListCell *lc;
-
- reltuples = 0;
-
- /* Find all members of inheritance set taking AccessShareLock */
- children = find_all_inheritors(relid, AccessShareLock, NULL);
-
- foreach(lc, children)
- {
- Oid childOID = lfirst_oid(lc);
- HeapTuple childtuple;
- Form_pg_class childclass;
-
- childtuple = SearchSysCache1(RELOID, ObjectIdGetDatum(childOID));
- childclass = (Form_pg_class) GETSTRUCT(childtuple);
-
- /* Skip a partitioned table and foreign partitions */
- if (RELKIND_HAS_STORAGE(childclass->relkind))
- {
- /* Sum up the child's reltuples for its parent table */
- reltuples += childclass->reltuples;
- }
- ReleaseSysCache(childtuple);
- }
-
- list_free(children);
- }
+ reltuples = classForm->reltuples;
vactuples = tabentry->n_dead_tuples;
instuples = tabentry->inserts_since_vacuum;
anltuples = tabentry->changes_since_analyze;