Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83158f7

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-placeupdate. SnapshotNow has been removed in813fb03, so there is no actualreasons to not make this operation transactional.Note that while making the operation more robust, using a transactionaloperation in this routine was not strictly necessary as there was no usecase for it yet. However, some future features are going to need atransactional behavior, like support for CREATE/DROP INDEX CONCURRENTLYwith partitioned tables, where indexes in a partition tree need to haveall their pg_index.indis* flags updated in the same transaction to makethe operation stable to the end-user by keeping partition treesconsistent, even with a failure mid-flight.REINDEX CONCURRENTLY uses already transactional updates when swappingthe old and new indexes, making this change more consistent with theindex-swapping logic.Author: Michael PaquierReviewed-by: Anastasia LubennikovaDiscussion:https://postgr.es/m/20200903080440.GA8559@paquier.xyz
1 parent3e0242b commit83158f7

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
@@ -3311,18 +3311,10 @@ validate_index_callback(ItemPointer itemptr, void *opaque)
33113311
* index_set_state_flags - adjust pg_index state flags
33123312
*
33133313
* This is used during CREATE/DROP INDEX CONCURRENTLY to adjust the pg_index
3314-
* flags that denote the index's state. Because the update is not
3315-
* transactional and will not roll back on error, this must only be used as
3316-
* the last step in a transaction that has not made any transactional catalog
3317-
* updates!
3314+
* flags that denote the index's state.
33183315
*
3319-
* Note thatheap_inplace_update does senda cacheinval message for the
3316+
* Note thatCatalogTupleUpdate() sendsa cacheinvalidation message for the
33203317
* tuple, so other sessions will hear about the update as soon as we commit.
3321-
*
3322-
* NB: In releases prior to PostgreSQL 9.4, the use of a non-transactional
3323-
* update here would have been unsafe; now that MVCC rules apply even for
3324-
* system catalog scans, we could potentially use a transactional update here
3325-
* instead.
33263318
*/
33273319
void
33283320
index_set_state_flags(OidindexId,IndexStateFlagsActionaction)
@@ -3331,9 +3323,6 @@ index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
33313323
HeapTupleindexTuple;
33323324
Form_pg_indexindexForm;
33333325

3334-
/* Assert that current xact hasn't done any transactional updates */
3335-
Assert(GetTopTransactionIdIfAny()==InvalidTransactionId);
3336-
33373326
/* Open pg_index and fetch a writable copy of the index's tuple */
33383327
pg_index=table_open(IndexRelationId,RowExclusiveLock);
33393328

@@ -3397,8 +3386,8 @@ index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
33973386
break;
33983387
}
33993388

3400-
/* ... andwrite it back in-place */
3401-
heap_inplace_update(pg_index,indexTuple);
3389+
/* ... andupdate it */
3390+
CatalogTupleUpdate(pg_index,&indexTuple->t_self,indexTuple);
34023391

34033392
table_close(pg_index,RowExclusiveLock);
34043393
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp