summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2023-03-31 14:08:40 +0000
committerTom Lane2023-03-31 14:08:40 +0000
commitc2d7d679c1220af77023413b031902afe4d2fdd1 (patch)
treeee646d5fb29e4dd4230cd91cded56b4edb5c7ed4
parent558fff0adfa02b6db6b003c64cca75e55f5187e2 (diff)
Ensure acquire_inherited_sample_rows sets its output parameters.
The totalrows/totaldeadrows outputs were left uninitialized in cases where we find no analyzable child tables of a partitioned table. This could lead to setting the partitioned table's pg_class.reltuples value to garbage. It's not clear that that would have any very bad effects in practice, but fix it anyway because it's making valgrind unhappy. Reported and diagnosed by Alexander Lakhin (bug #17880). Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/backend/commands/analyze.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 65750958bb..bec9c8b427 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -1389,6 +1389,10 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
ListCell *lc;
bool has_child;
+ /* Initialize output parameters to zero now, in case we exit early */
+ *totalrows = 0;
+ *totaldeadrows = 0;
+
/*
* Find all members of inheritance set. We only need AccessShareLock on
* the children.
@@ -1522,8 +1526,6 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
pgstat_progress_update_param(PROGRESS_ANALYZE_CHILD_TABLES_TOTAL,
nrels);
numrows = 0;
- *totalrows = 0;
- *totaldeadrows = 0;
for (i = 0; i < nrels; i++)
{
Relation childrel = rels[i];