Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Ensure acquire_inherited_sample_rows sets its output parameters.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 31 Mar 2023 14:08:40 +0000 (10:08 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 31 Mar 2023 14:08:40 +0000 (10:08 -0400)
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

index a889e155f7b5d21b96ed9f16eec05fd2a3d5aa43..39d0f1bd6227c2c7efb5dde25009c25ca79e7f5f 100644 (file)
@@ -1241,6 +1241,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.
@@ -1374,8 +1378,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];