pgsql: Use attnum to identify index columns in pg_restore_attribute_sta

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use attnum to identify index columns in pg_restore_attribute_sta
Date: 2025-02-26 21:36:35
Message-ID: E1tnP4z-000F4W-2a@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)sss(dot)pgh(dot)pa(dot)us>
Author: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Discussion: https://postgr.es/m/1457469.1740419458@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/40e27d04b4f643cfb78af8db42a1f2e700ec9876

Modified Files
--------------
doc/src/sgml/func.sgml | 47 ++---
src/backend/statistics/attribute_stats.c | 116 +++++++++--
src/bin/pg_dump/pg_dump.c | 273 ++++++++++++++++---------
src/bin/pg_dump/pg_dump.h | 7 +
src/bin/pg_dump/t/002_pg_dump.pl | 31 ++-
src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm | 4 +-
src/test/regress/expected/stats_import.out | 40 +++-
src/test/regress/sql/stats_import.sql | 30 ++-
8 files changed, 391 insertions(+), 157 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2025-02-26 21:38:54 pgsql: Remove stray diff introduced by a5cbdeb98a.
Previous Message Peter Eisentraut 2025-02-26 21:35:36 Re: pgsql: Prepare for Python "Limited API" in PL/Python