mirror of
https://github.com/postgres/postgres.git
synced 2025-06-22 02:52:08 +03:00
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 85b506bbfc
, 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.
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user