Skip to content

Commit ef387be

Browse files
committed
Fix bogus collation-version-recording logic.
recordMultipleDependencies had the wrong scope for its "version" variable, allowing a version label to leak from the collation entry it was meant for to subsequent non-collation entries. This is relatively hard to trigger because of the OID-descending order that the inputs will normally arrive in: subsequent non-collation items will tend to be pinned. But it can be exhibited easily with a custom collation. Also, don't special-case the default collation, but instead ignore pinned-ness of a collation when we've found a version for it. This avoids creating useless pg_depend entries, and removes a not-very- future-proof assumption that C, POSIX, and DEFAULT are the only pinned collations. A small problem is that, because the default collation may or may not have a version, the regression tests can't assume anything about whether dependency entries will be made for it. This seems OK though since it's now handled just the same as other collations, and we have test cases for both versioned and unversioned collations. Fixes oversights in commit 257836a. Thanks to Julien Rouhaud for review. Discussion: https://postgr.es/m/[email protected]
1 parent f90c708 commit ef387be

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

src/backend/catalog/pg_depend.c

+3-13
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ recordMultipleDependencies(const ObjectAddress *depender,
7373
max_slots,
7474
slot_init_count,
7575
slot_stored_count;
76-
char *version = NULL;
7776

7877
if (nreferenced <= 0)
7978
return; /* nothing to do */
@@ -104,39 +103,30 @@ recordMultipleDependencies(const ObjectAddress *depender,
104103
slot_init_count = 0;
105104
for (i = 0; i < nreferenced; i++, referenced++)
106105
{
107-
bool ignore_systempin = false;
106+
char *version = NULL;
108107

109108
if (record_version)
110109
{
111110
/* For now we only know how to deal with collations. */
112111
if (referenced->classId == CollationRelationId)
113112
{
114-
/* C and POSIX don't need version tracking. */
113+
/* These are unversioned, so don't waste cycles on them. */
115114
if (referenced->objectId == C_COLLATION_OID ||
116115
referenced->objectId == POSIX_COLLATION_OID)
117116
continue;
118117

119118
version = get_collation_version_for_oid(referenced->objectId,
120119
false);
121-
122-
/*
123-
* Default collation is pinned, so we need to force recording
124-
* the dependency to store the version.
125-
*/
126-
if (referenced->objectId == DEFAULT_COLLATION_OID)
127-
ignore_systempin = true;
128120
}
129121
}
130-
else
131-
Assert(!version);
132122

133123
/*
134124
* If the referenced object is pinned by the system, there's no real
135125
* need to record dependencies on it, unless we need to record a
136126
* version. This saves lots of space in pg_depend, so it's worth the
137127
* time taken to check.
138128
*/
139-
if (!ignore_systempin && isObjectPinned(referenced, dependDesc))
129+
if (version == NULL && isObjectPinned(referenced, dependDesc))
140130
continue;
141131

142132
if (slot_init_count < max_slots)

src/test/regress/expected/create_index.out

+5-9
Original file line numberDiff line numberDiff line change
@@ -2026,10 +2026,10 @@ REINDEX TABLE concur_reindex_tab; -- notice
20262026
NOTICE: table "concur_reindex_tab" has no indexes to reindex
20272027
REINDEX (CONCURRENTLY) TABLE concur_reindex_tab; -- notice
20282028
NOTICE: table "concur_reindex_tab" has no indexes that can be reindexed concurrently
2029-
ALTER TABLE concur_reindex_tab ADD COLUMN c2 text; -- add toast index
2029+
ALTER TABLE concur_reindex_tab ADD COLUMN c2 text COLLATE "C"; -- add toast index
20302030
-- Normal index with integer column
20312031
CREATE UNIQUE INDEX concur_reindex_ind1 ON concur_reindex_tab(c1);
2032-
-- Normal index with text column
2032+
-- Normal index with text column (with unversioned collation)
20332033
CREATE INDEX concur_reindex_ind2 ON concur_reindex_tab(c2);
20342034
-- UNIQUE index with expression
20352035
CREATE UNIQUE INDEX concur_reindex_ind3 ON concur_reindex_tab(abs(c1));
@@ -2069,16 +2069,14 @@ WHERE classid = 'pg_class'::regclass AND
20692069
obj | objref | deptype
20702070
------------------------------------------+------------------------------------------------------------+---------
20712071
index concur_reindex_ind1 | constraint concur_reindex_ind1 on table concur_reindex_tab | i
2072-
index concur_reindex_ind2 | collation "default" | n
20732072
index concur_reindex_ind2 | column c2 of table concur_reindex_tab | a
20742073
index concur_reindex_ind3 | column c1 of table concur_reindex_tab | a
20752074
index concur_reindex_ind3 | table concur_reindex_tab | a
2076-
index concur_reindex_ind4 | collation "default" | n
20772075
index concur_reindex_ind4 | column c1 of table concur_reindex_tab | a
20782076
index concur_reindex_ind4 | column c2 of table concur_reindex_tab | a
20792077
materialized view concur_reindex_matview | schema public | n
20802078
table concur_reindex_tab | schema public | n
2081-
(10 rows)
2079+
(8 rows)
20822080

20832081
REINDEX INDEX CONCURRENTLY concur_reindex_ind1;
20842082
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
@@ -2098,16 +2096,14 @@ WHERE classid = 'pg_class'::regclass AND
20982096
obj | objref | deptype
20992097
------------------------------------------+------------------------------------------------------------+---------
21002098
index concur_reindex_ind1 | constraint concur_reindex_ind1 on table concur_reindex_tab | i
2101-
index concur_reindex_ind2 | collation "default" | n
21022099
index concur_reindex_ind2 | column c2 of table concur_reindex_tab | a
21032100
index concur_reindex_ind3 | column c1 of table concur_reindex_tab | a
21042101
index concur_reindex_ind3 | table concur_reindex_tab | a
2105-
index concur_reindex_ind4 | collation "default" | n
21062102
index concur_reindex_ind4 | column c1 of table concur_reindex_tab | a
21072103
index concur_reindex_ind4 | column c2 of table concur_reindex_tab | a
21082104
materialized view concur_reindex_matview | schema public | n
21092105
table concur_reindex_tab | schema public | n
2110-
(10 rows)
2106+
(8 rows)
21112107

21122108
-- Check that comments are preserved
21132109
CREATE TABLE testcomment (i int);
@@ -2487,7 +2483,7 @@ WARNING: cannot reindex system catalogs concurrently, skipping all
24872483
Column | Type | Collation | Nullable | Default
24882484
--------+---------+-----------+----------+---------
24892485
c1 | integer | | not null |
2490-
c2 | text | | |
2486+
c2 | text | C | |
24912487
Indexes:
24922488
"concur_reindex_ind1" PRIMARY KEY, btree (c1)
24932489
"concur_reindex_ind2" btree (c2)

src/test/regress/sql/create_index.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,10 @@ CREATE TABLE concur_reindex_tab (c1 int);
797797
-- REINDEX
798798
REINDEX TABLE concur_reindex_tab; -- notice
799799
REINDEX (CONCURRENTLY) TABLE concur_reindex_tab; -- notice
800-
ALTER TABLE concur_reindex_tab ADD COLUMN c2 text; -- add toast index
800+
ALTER TABLE concur_reindex_tab ADD COLUMN c2 text COLLATE "C"; -- add toast index
801801
-- Normal index with integer column
802802
CREATE UNIQUE INDEX concur_reindex_ind1 ON concur_reindex_tab(c1);
803-
-- Normal index with text column
803+
-- Normal index with text column (with unversioned collation)
804804
CREATE INDEX concur_reindex_ind2 ON concur_reindex_tab(c2);
805805
-- UNIQUE index with expression
806806
CREATE UNIQUE INDEX concur_reindex_ind3 ON concur_reindex_tab(abs(c1));

0 commit comments

Comments
 (0)