aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/analyze.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2024-07-13 08:09:33 -0700
committerNoah Misch <noah@leadboat.com>2024-07-13 08:09:37 -0700
commite81deeefcac2a0de06f51e82405f63935f00e2bc (patch)
tree402bb3afb178820a0fcf6adbc1f88a95ae882fa2 /src/backend/commands/analyze.c
parent75f4ae2b8065ca7d29bec55f261828f794fbba1e (diff)
downloadpostgresql-e81deeefcac2a0de06f51e82405f63935f00e2bc.tar.gz
postgresql-e81deeefcac2a0de06f51e82405f63935f00e2bc.zip
Don't lose partitioned table reltuples=0 after relhassubclass=f.
ANALYZE sets relhassubclass=f when a partitioned table no longer has partitions. An ANALYZE doing that proceeded to apply the inplace update of pg_class.reltuples to the old pg_class tuple instead of the new tuple, losing that reltuples=0 change if the ANALYZE committed. Non-partitioning inheritance trees were unaffected. Back-patch to v14, where commit 375aed36ad83f0e021e9bdd3a0034c0c992c66dc introduced maintenance of partitioned table pg_class.reltuples. Reported by Alexander Lakhin. Discussion: https://postgr.es/m/a295b499-dcab-6a99-c06e-01cf60593344@gmail.com
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r--src/backend/commands/analyze.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index fb5a47daf37..bda364552ca 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -636,7 +636,11 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
visibilitymap_count(onerel, &relallvisible, NULL);
- /* Update pg_class for table relation */
+ /*
+ * Update pg_class for table relation. CCI first, in case acquirefunc
+ * updated pg_class.
+ */
+ CommandCounterIncrement();
vac_update_relstats(onerel,
relpages,
totalrows,
@@ -671,6 +675,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
* Partitioned tables don't have storage, so we don't set any fields
* in their pg_class entries except for reltuples and relhasindex.
*/
+ CommandCounterIncrement();
vac_update_relstats(onerel, -1, totalrows,
0, hasindex, InvalidTransactionId,
InvalidMultiXactId,