]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
pg_dump: scope indAttNames per index in getIndexes()
authorAlexander Korotkov <akorotkov@postgresql.org>
Wed, 3 Jun 2026 08:33:35 +0000 (11:33 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Wed, 3 Jun 2026 10:01:21 +0000 (13:01 +0300)
getIndexes() declared indAttNames and nindAttNames in the outer
per-table loop, so the names collected for an index on expressions
were carried over to the next plain index in the same table.

This is an internal inconsistency rather than a user-facing bug.
dumpRelationStats_dumper() only walks indexes that have pg_statistic
rows, and ANALYZE only creates those for indexes with expressions,
so the second index in the affected pair is not visited and the stale
array is never consulted.

Fix by moving the two variables into the inner per-index loop so each
iteration starts with a clean slate.

Author: Maksim Melnikov <m.melnikov@postgrespro.ru>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Discussion: https://postgr.es/m/be5fc489-587e-421f-bbb8-adb43cfd50f4@postgrespro.ru
Backpatch-through: 17

src/bin/pg_dump/pg_dump.c

index 8f6332d731f643b91b47f101e706c4fcddbb1bb8..3ad7ec2ec482394d11734b4e7d4d6b1bfe9ddb40 100644 (file)
@@ -7908,8 +7908,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
        {
                Oid                     indrelid = atooid(PQgetvalue(res, j, i_indrelid));
                TableInfo  *tbinfo = NULL;
-               char      **indAttNames = NULL;
-               int                     nindAttNames = 0;
                int                     numinds;
 
                /* Count rows for this table */
@@ -7943,6 +7941,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
                {
                        char            contype;
                        char            indexkind;
+                       char      **indAttNames = NULL;
+                       int                     nindAttNames = 0;
                        RelStatsInfo *relstats;
                        int32           relpages = atoi(PQgetvalue(res, j, i_relpages));
                        int32           relallvisible = atoi(PQgetvalue(res, j, i_relallvisible));