1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-24 14:22:24 +03:00

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
This commit is contained in:
Tom Lane
2025-02-26 16:36:11 -05:00
parent f734c9fc3a
commit 40e27d04b4
8 changed files with 392 additions and 158 deletions

View File

@ -30209,8 +30209,8 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
</programlisting>
</para>
<para>
For example, to set the <structname>relpages</structname> and
<structname>reltuples</structname> of the table
For example, to set the <structfield>relpages</structfield> and
<structfield>reltuples</structfield> values for the table
<structname>mytable</structname>:
<programlisting>
SELECT pg_restore_relation_stats(
@ -30222,8 +30222,8 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
<para>
The argument <literal>relation</literal> with a value of type
<type>regclass</type> is required, and specifies the table. Other
arguments are the names of statistics corresponding to certain
columns in <link
arguments are the names and values of statistics corresponding to
certain columns in <link
linkend="catalog-pg-class"><structname>pg_class</structname></link>.
The currently-supported relation statistics are
<literal>relpages</literal> 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 <type>integer</type>.
</para>
<para>
Additionally, this function supports argument name
Additionally, this function accepts argument name
<literal>version</literal> of type <type>integer</type>, which
specifies the version from which the statistics originated, improving
interpretation of statistics from older versions of
<productname>PostgreSQL</productname>.
specifies the server version from which the statistics originated.
This is anticipated to be helpful in porting statistics from older
versions of <productname>PostgreSQL</productname>.
</para>
<para>
Minor errors are reported as a <literal>WARNING</literal> and
ignored, and remaining statistics will still be restored. If all
specified statistics are successfully restored, return
specified statistics are successfully restored, returns
<literal>true</literal>, otherwise <literal>false</literal>.
</para>
<para>
@ -30281,7 +30281,7 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
<returnvalue>boolean</returnvalue>
</para>
<para>
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 <xref
linkend="sql-vacuum"/> or <xref linkend="sql-analyze"/>, 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
</programlisting>
</para>
<para>
For example, to set the <structname>avg_width</structname> and
<structname>null_frac</structname> for the attribute
<structname>col1</structname> of the table
For example, to set the <structfield>avg_width</structfield> and
<structfield>null_frac</structfield> values for the attribute
<structfield>col1</structfield> of the table
<structname>mytable</structname>:
<programlisting>
SELECT pg_restore_attribute_stats(
@ -30315,25 +30315,26 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
</para>
<para>
The required arguments are <literal>relation</literal> with a value
of type <type>regclass</type>, which specifies the table;
<literal>attname</literal> with a value of type <type>name</type>,
of type <type>regclass</type>, which specifies the table; either
<literal>attname</literal> with a value of type <type>name</type> or
<literal>attnum</literal> with a value of type <type>smallint</type>,
which specifies the column; and <literal>inherited</literal>, which
specifies whether the statistics includes values from child tables.
Other arguments are the names of statistics corresponding to columns
in <link
specifies whether the statistics include values from child tables.
Other arguments are the names and values of statistics corresponding
to columns in <link
linkend="view-pg-stats"><structname>pg_stats</structname></link>.
</para>
<para>
Additionally, this function supports argument name
Additionally, this function accepts argument name
<literal>version</literal> of type <type>integer</type>, which
specifies the version from which the statistics originated, improving
interpretation of statistics from older versions of
<productname>PostgreSQL</productname>.
specifies the server version from which the statistics originated.
This is anticipated to be helpful in porting statistics from older
versions of <productname>PostgreSQL</productname>.
</para>
<para>
Minor errors are reported as a <literal>WARNING</literal> and
ignored, and remaining statistics will still be restored. If all
specified statistics are successfully restored, return
specified statistics are successfully restored, returns
<literal>true</literal>, otherwise <literal>false</literal>.
</para>
<para>