From 40e27d04b4f643cfb78af8db42a1f2e700ec9876 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 26 Feb 2025 16:36:11 -0500 Subject: 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 Author: Corey Huinker Discussion: https://postgr.es/m/1457469.1740419458@sss.pgh.pa.us --- doc/src/sgml/func.sgml | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 12206e0cfc6..0e6c5349652 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -30209,8 +30209,8 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset - For example, to set the relpages and - reltuples of the table + For example, to set the relpages and + reltuples values for the table mytable: SELECT pg_restore_relation_stats( @@ -30222,8 +30222,8 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset The argument relation with a value of type regclass is required, and specifies the table. Other - arguments are the names of statistics corresponding to certain - columns in pg_class. The currently-supported relation statistics are relpages with a value of type @@ -30232,16 +30232,16 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset value of type integer. - Additionally, this function supports argument name + Additionally, this function accepts argument name version of type integer, which - specifies the version from which the statistics originated, improving - interpretation of statistics from older versions of - PostgreSQL. + specifies the server version from which the statistics originated. + This is anticipated to be helpful in porting statistics from older + versions of PostgreSQL. Minor errors are reported as a WARNING and ignored, and remaining statistics will still be restored. If all - specified statistics are successfully restored, return + specified statistics are successfully restored, returns true, otherwise false. @@ -30281,7 +30281,7 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset boolean - Create or update column-level statistics. Ordinarily, these + Creates or updates column-level statistics. Ordinarily, these statistics are collected automatically or updated as a part of or , so it's not necessary to call this function. However, it is useful after a @@ -30300,9 +30300,9 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset - For example, to set the avg_width and - null_frac for the attribute - col1 of the table + For example, to set the avg_width and + null_frac values for the attribute + col1 of the table mytable: SELECT pg_restore_attribute_stats( @@ -30315,25 +30315,26 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset The required arguments are relation with a value - of type regclass, which specifies the table; - attname with a value of type name, + of type regclass, which specifies the table; either + attname with a value of type name or + attnum with a value of type smallint, which specifies the column; and inherited, which - specifies whether the statistics includes values from child tables. - Other arguments are the names of statistics corresponding to columns - in pg_stats. - Additionally, this function supports argument name + Additionally, this function accepts argument name version of type integer, which - specifies the version from which the statistics originated, improving - interpretation of statistics from older versions of - PostgreSQL. + specifies the server version from which the statistics originated. + This is anticipated to be helpful in porting statistics from older + versions of PostgreSQL. Minor errors are reported as a WARNING and ignored, and remaining statistics will still be restored. If all - specified statistics are successfully restored, return + specified statistics are successfully restored, returns true, otherwise false. -- cgit v1.2.3