@ -1980,7 +1980,7 @@ index_build(Relation heapRelation,
* created it , or truncated twice in a subsequent transaction , the
* created it , or truncated twice in a subsequent transaction , the
* relfilenode won ' t change , and nothing needs to be done here .
* relfilenode won ' t change , and nothing needs to be done here .
*/
*/
if ( heap Relation- > rd_rel - > relpersistence = = RELPERSISTENCE_UNLOGGED & &
if ( index Relation- > rd_rel - > relpersistence = = RELPERSISTENCE_UNLOGGED & &
! smgrexists ( indexRelation - > rd_smgr , INIT_FORKNUM ) )
! smgrexists ( indexRelation - > rd_smgr , INIT_FORKNUM ) )
{
{
RegProcedure ambuildempty = indexRelation - > rd_am - > ambuildempty ;
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
* reindex_index - This routine is used to recreate a single index
*/
*/
void
void
reindex_index ( Oid indexId , bool skip_constraint_checks )
reindex_index ( Oid indexId , bool skip_constraint_checks , char persistence )
{
{
Relation iRel ,
Relation iRel ,
heapRelation ;
heapRelation ;
@ -3191,6 +3191,9 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
indexInfo - > ii_ExclusionStrats = NULL ;
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 */
/* We'll build a new physical relation for the index */
RelationSetNewRelfilenode ( iRel , InvalidTransactionId ,
RelationSetNewRelfilenode ( iRel , InvalidTransactionId ,
InvalidMultiXactId ) ;
InvalidMultiXactId ) ;
@ -3310,6 +3313,12 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
* performance , other callers should include the flag only after transforming
* performance , other callers should include the flag only after transforming
* the data in a manner that risks a change in constraint validity .
* 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
* Returns true if any indexes were rebuilt ( including toast table ' s index
* when relevant ) . Note that a CommandCounterIncrement will occur after each
* when relevant ) . Note that a CommandCounterIncrement will occur after each
* index rebuild .
* index rebuild .
@ -3371,6 +3380,7 @@ reindex_relation(Oid relid, int flags)
{
{
List * doneIndexes ;
List * doneIndexes ;
ListCell * indexId ;
ListCell * indexId ;
char persistence ;
if ( flags & REINDEX_REL_SUPPRESS_INDEX_USE )
if ( flags & REINDEX_REL_SUPPRESS_INDEX_USE )
{
{
@ -3384,6 +3394,17 @@ reindex_relation(Oid relid, int flags)
CommandCounterIncrement ( ) ;
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. */
/* Reindex all the indexes. */
doneIndexes = NIL ;
doneIndexes = NIL ;
foreach ( indexId , indexIds )
foreach ( indexId , indexIds )
@ -3393,7 +3414,8 @@ reindex_relation(Oid relid, int flags)
if ( is_pg_class )
if ( is_pg_class )
RelationSetIndexList ( rel , doneIndexes , InvalidOid ) ;
RelationSetIndexList ( rel , doneIndexes , InvalidOid ) ;
reindex_index ( indexOid , ! ( flags & REINDEX_REL_CHECK_CONSTRAINTS ) ) ;
reindex_index ( indexOid , ! ( flags & REINDEX_REL_CHECK_CONSTRAINTS ) ,
persistence ) ;
CommandCounterIncrement ( ) ;
CommandCounterIncrement ( ) ;