Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0853630

Browse files
committed
Fix lost persistence setting during REINDEX INDEX
ReindexIndex() trusts a parser-built RangeVar with the persistence touse for the new copy of the index; but the parser naturally does notknow what's the persistence of the original index. To find out thecorrect persistence, grab it from relcache.This bug was introduced by commit85b506b, and therefore nobackpatch is necessary.Bug reported by Thom Brown, analysis and patch by Michael Paquier; testcase provided by Fabrízio de Royes Mello.
1 parent542320c commit0853630

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,14 +1685,28 @@ ReindexIndex(RangeVar *indexRelation)
16851685
{
16861686
OidindOid;
16871687
OidheapOid=InvalidOid;
1688+
Relationirel;
1689+
charpersistence;
16881690

1689-
/* lock level used here should match index lock reindex_index() */
1691+
/*
1692+
* Find and lock index, and check permissions on table; use callback to
1693+
* obtain lock on table first, to avoid deadlock hazard. The lock level
1694+
* used here must match the index lock obtained in reindex_index().
1695+
*/
16901696
indOid=RangeVarGetRelidExtended(indexRelation,AccessExclusiveLock,
16911697
false, false,
16921698
RangeVarCallbackForReindexIndex,
16931699
(void*)&heapOid);
16941700

1695-
reindex_index(indOid, false,indexRelation->relpersistence);
1701+
/*
1702+
* Obtain the current persistence of the existing index. We already hold
1703+
* lock on the index.
1704+
*/
1705+
irel=index_open(indOid,NoLock);
1706+
persistence=irel->rd_rel->relpersistence;
1707+
index_close(irel,NoLock);
1708+
1709+
reindex_index(indOid, false,persistence);
16961710

16971711
returnindOid;
16981712
}

‎src/test/regress/expected/create_table.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,28 @@ CREATE TABLE IF NOT EXISTS test_tsvector(
208208
);
209209
NOTICE: relation "test_tsvector" already exists, skipping
210210
CREATE UNLOGGED TABLE unlogged1 (a int primary key);-- OK
211+
CREATE TEMPORARY TABLE unlogged2 (a int primary key);-- OK
212+
SELECT relname, relkind, relpersistence FROM pg_class WHERE relname ~ '^unlogged\d' ORDER BY relname;
213+
relname | relkind | relpersistence
214+
----------------+---------+----------------
215+
unlogged1 | r | u
216+
unlogged1_pkey | i | u
217+
unlogged2 | r | t
218+
unlogged2_pkey | i | t
219+
(4 rows)
220+
221+
REINDEX INDEX unlogged1_pkey;
222+
REINDEX INDEX unlogged2_pkey;
223+
SELECT relname, relkind, relpersistence FROM pg_class WHERE relname ~ '^unlogged\d' ORDER BY relname;
224+
relname | relkind | relpersistence
225+
----------------+---------+----------------
226+
unlogged1 | r | u
227+
unlogged1_pkey | i | u
228+
unlogged2 | r | t
229+
unlogged2_pkey | i | t
230+
(4 rows)
231+
232+
DROP TABLE unlogged2;
211233
INSERT INTO unlogged1 VALUES (42);
212234
CREATE UNLOGGED TABLE public.unlogged2 (a int primary key);-- also OK
213235
CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int primary key);-- not OK

‎src/test/regress/sql/create_table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ CREATE TABLE IF NOT EXISTS test_tsvector(
246246
);
247247

248248
CREATE UNLOGGED TABLE unlogged1 (aintprimary key);-- OK
249+
CREATE TEMPORARY TABLE unlogged2 (aintprimary key);-- OK
250+
SELECT relname, relkind, relpersistenceFROM pg_classWHERE relname ~'^unlogged\d'ORDER BY relname;
251+
REINDEX INDEX unlogged1_pkey;
252+
REINDEX INDEX unlogged2_pkey;
253+
SELECT relname, relkind, relpersistenceFROM pg_classWHERE relname ~'^unlogged\d'ORDER BY relname;
254+
DROPTABLE unlogged2;
249255
INSERT INTO unlogged1VALUES (42);
250256
CREATE UNLOGGED TABLEpublic.unlogged2 (aintprimary key);-- also OK
251257
CREATE UNLOGGED TABLEpg_temp.unlogged3 (aintprimary key);-- not OK

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp