Skip to content

Commit acb60ed

Browse files
committed
Make index_set_state_flags() transactional
3c84046 is the original commit that introduced index_set_state_flags(), where the presence of SnapshotNow made necessary the use of an in-place update. SnapshotNow has been removed in 813fb03, so there is no actual reasons to not make this operation transactional. As reported by Andrey, it is possible to trigger the assertion of this routine expecting no transactional updates when switching the pg_index state flags, using a predicate mark as immutable but calling stable or volatile functions. 83158f7 has been around for a couple of months on HEAD now with no issues found related to it, so it looks safe enough for a backpatch. Reported-by: Andrey Lepikhov Author: Michael Paquier Reviewed-by: Anastasia Lubennikova Discussion: https://postgr.es/m/20200903080440.GA8559@paquier.xyz Discussion: https://postgr.es/m/9b905019-5297-7372-0ad2-e1a4bb66a719@postgrespro.ru Backpatch-through: 9.6
1 parent 2d09448 commit acb60ed

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/backend/catalog/index.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,18 +3375,10 @@ validate_index_callback(ItemPointer itemptr, void *opaque)
33753375
* index_set_state_flags - adjust pg_index state flags
33763376
*
33773377
* This is used during CREATE/DROP INDEX CONCURRENTLY to adjust the pg_index
3378-
* flags that denote the index's state. Because the update is not
3379-
* transactional and will not roll back on error, this must only be used as
3380-
* the last step in a transaction that has not made any transactional catalog
3381-
* updates!
3378+
* flags that denote the index's state.
33823379
*
3383-
* Note that heap_inplace_update does send a cache inval message for the
3380+
* Note that CatalogTupleUpdate() sends a cache invalidation message for the
33843381
* tuple, so other sessions will hear about the update as soon as we commit.
3385-
*
3386-
* NB: In releases prior to PostgreSQL 9.4, the use of a non-transactional
3387-
* update here would have been unsafe; now that MVCC rules apply even for
3388-
* system catalog scans, we could potentially use a transactional update here
3389-
* instead.
33903382
*/
33913383
void
33923384
index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
@@ -3395,9 +3387,6 @@ index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
33953387
HeapTuple indexTuple;
33963388
Form_pg_index indexForm;
33973389

3398-
/* Assert that current xact hasn't done any transactional updates */
3399-
Assert(GetTopTransactionIdIfAny() == InvalidTransactionId);
3400-
34013390
/* Open pg_index and fetch a writable copy of the index's tuple */
34023391
pg_index = table_open(IndexRelationId, RowExclusiveLock);
34033392

@@ -3456,8 +3445,8 @@ index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
34563445
break;
34573446
}
34583447

3459-
/* ... and write it back in-place */
3460-
heap_inplace_update(pg_index, indexTuple);
3448+
/* ... and update it */
3449+
CatalogTupleUpdate(pg_index, &indexTuple->t_self, indexTuple);
34613450

34623451
table_close(pg_index, RowExclusiveLock);
34633452
}

0 commit comments

Comments
 (0)