Use attnum to identify index columns in pg_restore_attribute_stats().
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 26 Feb 2025 21:36:11 +0000 (16:36 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 26 Feb 2025 21:36:20 +0000 (16:36 -0500)
commit40e27d04b4f643cfb78af8db42a1f2e700ec9876
tree80c8df6b40ca3eaec64fcebfff9eb4c3cd2fd824
parentf734c9fc3a91959c2473a1e33fd9b60116902175
Use attnum to identify index columns in pg_restore_attribute_stats().

Previously we used attname for both table and index columns, but
that is problematic for indexes because their attnames are assigned
by internal rules that don't guarantee to preserve the names across
dump and reload.  (This is what's causing the remaining buildfarm
failures in cross-version-upgrade tests.)  Fortunately we can use
attnum instead, since there's no such thing as adding or dropping
columns in an existing index.  We met this same problem previously
with ALTER INDEX ... SET STATISTICS, and solved it the same way,
cf commit 5b6d13eec.

In pg_restore_attribute_stats() itself, we accept either attnum or
attname, but the policy used by pg_dump is to always use attname
for tables and attnum for indexes.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Author: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/1457469.1740419458@sss.pgh.pa.us
doc/src/sgml/func.sgml
src/backend/statistics/attribute_stats.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.h
src/bin/pg_dump/t/002_pg_dump.pl
src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
src/test/regress/expected/stats_import.out
src/test/regress/sql/stats_import.sql