diff options
author | Alvaro Herrera | 2015-03-30 19:01:44 +0000 |
---|---|---|
committer | Alvaro Herrera | 2015-03-30 19:01:44 +0000 |
commit | 0853630159944bb3652336602ff5f7f62cd27a5a (patch) | |
tree | 681c237f0aaf19c867cb61ad5861785a3c86a144 /src/backend/commands | |
parent | 542320c2bd0b3796a8a9a4617cdb23fbad473390 (diff) |
Fix lost persistence setting during REINDEX INDEX
ReindexIndex() trusts a parser-built RangeVar with the persistence to
use for the new copy of the index; but the parser naturally does not
know what's the persistence of the original index. To find out the
correct persistence, grab it from relcache.
This bug was introduced by commit 85b506bbfc2937c9, and therefore no
backpatch is necessary.
Bug reported by Thom Brown, analysis and patch by Michael Paquier; test
case provided by FabrÃzio de Royes Mello.
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/indexcmds.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 1c1d0da448d..99acd4a6a2c 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1685,14 +1685,28 @@ ReindexIndex(RangeVar *indexRelation) { Oid indOid; Oid heapOid = InvalidOid; + Relation irel; + char persistence; - /* lock level used here should match index lock reindex_index() */ + /* + * Find and lock index, and check permissions on table; use callback to + * obtain lock on table first, to avoid deadlock hazard. The lock level + * used here must match the index lock obtained in reindex_index(). + */ indOid = RangeVarGetRelidExtended(indexRelation, AccessExclusiveLock, false, false, RangeVarCallbackForReindexIndex, (void *) &heapOid); - reindex_index(indOid, false, indexRelation->relpersistence); + /* + * Obtain the current persistence of the existing index. We already hold + * lock on the index. + */ + irel = index_open(indOid, NoLock); + persistence = irel->rd_rel->relpersistence; + index_close(irel, NoLock); + + reindex_index(indOid, false, persistence); return indOid; } |