Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 257836a

Browse files
committed
Track collation versions for indexes.
Record the current version of dependent collations in pg_depend when creating or rebuilding an index. When accessing the index later, warn that the index may be corrupted if the current version doesn't match. Thanks to Douglas Doole, Peter Eisentraut, Christoph Berg, Laurenz Albe, Michael Paquier, Robert Haas, Tom Lane and others for very helpful discussion. Author: Thomas Munro <thomas.munro@gmail.com> Author: Julien Rouhaud <rjuju123@gmail.com> Reviewed-by: Peter Eisentraut <peter.eisentraut@2ndquadrant.com> (earlier versions) Discussion: https://postgr.es/m/CAEepm%3D0uEQCpfq_%2BLYFBdArCe4Ot98t1aR4eYiYTe%3DyavQygiQ%40mail.gmail.com
1 parent cd6f479 commit 257836a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1287
-94
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3308,7 +3308,8 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
33083308
<structfield>refobjversion</structfield> <type>text</type>
33093309
</para>
33103310
<para>
3311-
An optional version for the referenced object.
3311+
An optional version for the referenced object. Currently used for
3312+
indexes' collations (see <xref linkend="collation-versions"/>).
33123313
</para>
33133314
</entry>
33143315
</row>

doc/src/sgml/charset.sgml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,44 @@ CREATE COLLATION ignore_accents (provider = icu, locale = 'und-u-ks-level1-kc-tr
948948
</tip>
949949
</sect3>
950950
</sect2>
951+
952+
<sect2 id="collation-versions">
953+
<title>Collation Versions</title>
954+
955+
<para>
956+
The sort order defined by a collation is not necessarily fixed over time.
957+
<productname>PostgreSQL</productname> relies on external libraries that
958+
are subject to operating system upgrades, and can also differ between
959+
servers involved in binary replication and file-system-level migration.
960+
Persistent data structures such as B-trees that depend on sort order might
961+
be corrupted by any resulting change.
962+
<productname>PostgreSQL</productname> defends against this by recording the
963+
current version of each referenced collation for any index that depends on
964+
it in the
965+
<link linkend="catalog-pg-depend"><structname>pg_depend</structname></link>
966+
catalog, if the collation provider makes that information available. If the
967+
provider later begins to report a different version, a warning will be
968+
issued when the index is accessed, until either the
969+
<xref linkend="sql-reindex"/> command or the
970+
<xref linkend="sql-alterindex"/> command is used to update the version.
971+
</para>
972+
<para>
973+
Version information is available from the
974+
<literal>icu</literal> provider on all operating systems. For the
975+
<literal>libc</literal> provider, versions are currently only available
976+
on systems using the GNU C library (most Linux systems) and Windows.
977+
</para>
978+
979+
<note>
980+
<para>
981+
When using the GNU C library for collations, the C library's version
982+
is used as a proxy for the collation version. Many Linux distributions
983+
change collation definitions only when upgrading the C library, but this
984+
approach is imperfect as maintainers are free to back-port newer
985+
collation definitions to older C library releases.
986+
</para>
987+
</note>
988+
</sect2>
951989
</sect1>
952990

953991
<sect1 id="multibyte">

doc/src/sgml/func.sgml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25444,7 +25444,9 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup());
2544425444
</para>
2544525445
<para>
2544625446
Returns the actual version of the collation object as it is currently
25447-
installed in the operating system.
25447+
installed in the operating system. <literal>null</literal> is returned
25448+
on operating systems where <productname>PostgreSQL</productname>
25449+
doesn't have support for versions.
2544825450
</para></entry>
2544925451
</row>
2545025452

doc/src/sgml/ref/alter_index.sgml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RENA
2525
ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET TABLESPACE <replaceable class="parameter">tablespace_name</replaceable>
2626
ALTER INDEX <replaceable class="parameter">name</replaceable> ATTACH PARTITION <replaceable class="parameter">index_name</replaceable>
2727
ALTER INDEX <replaceable class="parameter">name</replaceable> DEPENDS ON EXTENSION <replaceable class="parameter">extension_name</replaceable>
28+
ALTER INDEX <replaceable class="parameter">name</replaceable> ALTER COLLATION <replaceable class="parameter">collation_name</replaceable> REFRESH VERSION
2829
ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">storage_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] )
2930
ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RESET ( <replaceable class="parameter">storage_parameter</replaceable> [, ... ] )
3031
ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="parameter">column_number</replaceable>
@@ -112,6 +113,20 @@ ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable>
112113
</listitem>
113114
</varlistentry>
114115

116+
<varlistentry>
117+
<term><literal>ALTER COLLATION <replaceable class="parameter">collation_name</replaceable> REFRESH VERSION</literal></term>
118+
<listitem>
119+
<para>
120+
Silences warnings about mismatched collation versions, by declaring
121+
that the index is compatible with the current collation definition.
122+
Be aware that incorrect use of this command can hide index corruption.
123+
If you don't know whether a collation's definition has changed
124+
incompatibly, <xref linkend="sql-reindex"/> is a safe alternative.
125+
See <xref linkend="collation-versions"/> for more information.
126+
</para>
127+
</listitem>
128+
</varlistentry>
129+
115130
<varlistentry>
116131
<term><literal>SET ( <replaceable class="parameter">storage_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] )</literal></term>
117132
<listitem>

doc/src/sgml/ref/pgupgrade.sgml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ PostgreSQL documentation
215215
</listitem>
216216
</varlistentry>
217217

218+
<varlistentry>
219+
<term><option>--index-collation-versions-unknown</option></term>
220+
<listitem>
221+
<para>
222+
When upgrading indexes from releases before 14 that didn't track
223+
collation versions, <application>pg_upgrade</application>
224+
assumes by default that the upgraded indexes are compatible with the
225+
currently installed versions of relevant collations (see
226+
<xref linkend="collation-versions"/>). Specify
227+
<option>--index-collation-versions-unknown</option> to mark
228+
them as needing to be rebuilt instead.
229+
</para>
230+
</listitem>
231+
</varlistentry>
232+
218233
<varlistentry>
219234
<term><option>-?</option></term>
220235
<term><option>--help</option></term>

doc/src/sgml/ref/reindex.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] { IN
3838
several scenarios in which to use <command>REINDEX</command>:
3939

4040
<itemizedlist>
41+
<listitem>
42+
<para>
43+
The index depends on the sort order of a collation, and the definition
44+
of the collation has changed. This can cause index scans to fail to
45+
find keys that are present. See <xref linkend="collation-versions"/> for
46+
more information.
47+
</para>
48+
</listitem>
49+
4150
<listitem>
4251
<para>
4352
An index has become corrupted, and no longer contains valid

0 commit comments

Comments
 (0)