Skip to content

Commit 08acba5

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 1acab12 commit 08acba5

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
@@ -3632,18 +3632,10 @@ validate_index_heapscan(Relation heapRelation,
36323632
* index_set_state_flags - adjust pg_index state flags
36333633
*
36343634
* This is used during CREATE/DROP INDEX CONCURRENTLY to adjust the pg_index
3635-
* flags that denote the index's state. Because the update is not
3636-
* transactional and will not roll back on error, this must only be used as
3637-
* the last step in a transaction that has not made any transactional catalog
3638-
* updates!
3635+
* flags that denote the index's state.
36393636
*
3640-
* Note that heap_inplace_update does send a cache inval message for the
3637+
* Note that CatalogTupleUpdate() sends a cache invalidation message for the
36413638
* tuple, so other sessions will hear about the update as soon as we commit.
3642-
*
3643-
* NB: In releases prior to PostgreSQL 9.4, the use of a non-transactional
3644-
* update here would have been unsafe; now that MVCC rules apply even for
3645-
* system catalog scans, we could potentially use a transactional update here
3646-
* instead.
36473639
*/
36483640
void
36493641
index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
@@ -3652,9 +3644,6 @@ index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
36523644
HeapTuple indexTuple;
36533645
Form_pg_index indexForm;
36543646

3655-
/* Assert that current xact hasn't done any transactional updates */
3656-
Assert(GetTopTransactionIdIfAny() == InvalidTransactionId);
3657-
36583647
/* Open pg_index and fetch a writable copy of the index's tuple */
36593648
pg_index = heap_open(IndexRelationId, RowExclusiveLock);
36603649

@@ -3713,8 +3702,8 @@ index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
37133702
break;
37143703
}
37153704

3716-
/* ... and write it back in-place */
3717-
heap_inplace_update(pg_index, indexTuple);
3705+
/* ... and update it */
3706+
CatalogTupleUpdate(pg_index, &indexTuple->t_self, indexTuple);
37183707

37193708
heap_close(pg_index, RowExclusiveLock);
37203709
}

0 commit comments

Comments
 (0)