mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Get rid of SET LOGGED indexes persistence kludge
This removes ATChangeIndexesPersistence() introduced by f41872d0c1
which was too ugly to live for long. Instead, the correct persistence
marking is passed all the way down to reindex_index, so that the
transient relation built to contain the index relfilenode can
get marked correctly right from the start.
Author: Fabrízio de Royes Mello
Review and editorialization by Michael Paquier
and Álvaro Herrera
This commit is contained in:
@@ -1980,7 +1980,7 @@ index_build(Relation heapRelation,
|
||||
* created it, or truncated twice in a subsequent transaction, the
|
||||
* relfilenode won't change, and nothing needs to be done here.
|
||||
*/
|
||||
if (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
|
||||
if (indexRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
|
||||
!smgrexists(indexRelation->rd_smgr, INIT_FORKNUM))
|
||||
{
|
||||
RegProcedure ambuildempty = indexRelation->rd_am->ambuildempty;
|
||||
@@ -3130,7 +3130,7 @@ IndexGetRelation(Oid indexId, bool missing_ok)
|
||||
* reindex_index - This routine is used to recreate a single index
|
||||
*/
|
||||
void
|
||||
reindex_index(Oid indexId, bool skip_constraint_checks)
|
||||
reindex_index(Oid indexId, bool skip_constraint_checks, char persistence)
|
||||
{
|
||||
Relation iRel,
|
||||
heapRelation;
|
||||
@@ -3191,6 +3191,9 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
|
||||
indexInfo->ii_ExclusionStrats = NULL;
|
||||
}
|
||||
|
||||
/* Set the relpersistence of the new index */
|
||||
iRel->rd_rel->relpersistence = persistence;
|
||||
|
||||
/* We'll build a new physical relation for the index */
|
||||
RelationSetNewRelfilenode(iRel, InvalidTransactionId,
|
||||
InvalidMultiXactId);
|
||||
@@ -3310,6 +3313,12 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
|
||||
* performance, other callers should include the flag only after transforming
|
||||
* the data in a manner that risks a change in constraint validity.
|
||||
*
|
||||
* REINDEX_REL_FORCE_INDEXES_UNLOGGED: if true, set the persistence of the
|
||||
* rebuilt indexes to unlogged.
|
||||
*
|
||||
* REINDEX_REL_FORCE_INDEXES_LOGGED: if true, set the persistence of the
|
||||
* rebuilt indexes to permanent.
|
||||
*
|
||||
* Returns true if any indexes were rebuilt (including toast table's index
|
||||
* when relevant). Note that a CommandCounterIncrement will occur after each
|
||||
* index rebuild.
|
||||
@@ -3371,6 +3380,7 @@ reindex_relation(Oid relid, int flags)
|
||||
{
|
||||
List *doneIndexes;
|
||||
ListCell *indexId;
|
||||
char persistence;
|
||||
|
||||
if (flags & REINDEX_REL_SUPPRESS_INDEX_USE)
|
||||
{
|
||||
@@ -3384,6 +3394,17 @@ reindex_relation(Oid relid, int flags)
|
||||
CommandCounterIncrement();
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute persistence of indexes: same as that of owning rel, unless
|
||||
* caller specified otherwise.
|
||||
*/
|
||||
if (flags & REINDEX_REL_FORCE_INDEXES_UNLOGGED)
|
||||
persistence = RELPERSISTENCE_UNLOGGED;
|
||||
else if (flags & REINDEX_REL_FORCE_INDEXES_PERMANENT)
|
||||
persistence = RELPERSISTENCE_PERMANENT;
|
||||
else
|
||||
persistence = rel->rd_rel->relpersistence;
|
||||
|
||||
/* Reindex all the indexes. */
|
||||
doneIndexes = NIL;
|
||||
foreach(indexId, indexIds)
|
||||
@@ -3393,7 +3414,8 @@ reindex_relation(Oid relid, int flags)
|
||||
if (is_pg_class)
|
||||
RelationSetIndexList(rel, doneIndexes, InvalidOid);
|
||||
|
||||
reindex_index(indexOid, !(flags & REINDEX_REL_CHECK_CONSTRAINTS));
|
||||
reindex_index(indexOid, !(flags & REINDEX_REL_CHECK_CONSTRAINTS),
|
||||
persistence);
|
||||
|
||||
CommandCounterIncrement();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user