postgres.git / summary / log / commit / refs
commit d0d92fe3d49934042f64539ccf2bb33c5f82158a
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri Mar 31 14:08:40 2023 +0000
First released in: 16.0, 11.20, 12.15, 13.11, 14.8, 15.3
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/17880-9282037c923d856e@postgresql.org
src/backend/commands/analyze.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index ce29bf59095..7c126010aaa 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -1206,6 +1206,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.
@@ -1337,8 +1341,6 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
* clear that it's worth working harder.)
*/
numrows = 0;
- *totalrows = 0;
- *totaldeadrows = 0;
for (i = 0; i < nrels; i++)
{
Relation childrel = rels[i];
[parent: 33510bc64919]