diff options
author | Noah Misch <noah@leadboat.com> | 2024-06-27 19:21:05 -0700 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2024-06-27 19:21:12 -0700 |
commit | 1a6d65b64e8495280862f5757062eb844d134488 (patch) | |
tree | 41179d764979e856b28b682eeaa0fdb3bdab8216 /src/include | |
parent | c3437fb7255b1ad7b19c9d6149919b60daa9bb1d (diff) |
Lock before setting relhassubclass on RELKIND_PARTITIONED_INDEX.
Commit 5b562644fec696977df4a82790064e8287927891 added a comment that
SetRelationHasSubclass() callers must hold this lock. When commit
17f206fbc824d2b4b14480199ca9ff7dea417eda extended use of this column to
partitioned indexes, it didn't take the lock. As the latter commit
message mentioned, we currently never reset a partitioned index to
relhassubclass=f. That largely avoids harm from the lock omission. The
cause for fixing this now is to unblock introducing a rule about locks
required to heap_update() a pg_class row. This might cause more
deadlocks. It gives minor user-visible benefits:
- If an ALTER INDEX SET TABLESPACE runs concurrently with ALTER TABLE
ATTACH PARTITION or CREATE PARTITION OF, one transaction blocks
instead of failing with "tuple concurrently updated". (Many cases of
DDL concurrency still fail that way.)
- Match ALTER INDEX ATTACH PARTITION in choosing to lock the index.
While not user-visible today, we'll need this if we ever make something
set the flag to false for a partitioned index, like ANALYZE does today
for tables. Back-patch to v12 (all supported versions), the plan for
the commit relying on the new rule. In back branches, add
LockOrStrongerHeldByMe() instead of adding a LockHeldByMe() parameter.
Reviewed (in an earlier version) by Robert Haas.
Discussion: https://postgr.es/m/20240611024525.9f.nmisch@google.com
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/storage/lmgr.h | 2 | ||||
-rw-r--r-- | src/include/storage/lock.h | 1 |
2 files changed, 3 insertions, 0 deletions
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h index ec5ef2b8788..7023d7fb782 100644 --- a/src/include/storage/lmgr.h +++ b/src/include/storage/lmgr.h @@ -47,6 +47,8 @@ extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode); extern void UnlockRelation(Relation relation, LOCKMODE lockmode); extern bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger); +extern bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, + bool orstronger); extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode); extern void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode); diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h index ab42f6b0802..6e10a6a4249 100644 --- a/src/include/storage/lock.h +++ b/src/include/storage/lock.h @@ -558,6 +558,7 @@ extern void LockReleaseSession(LOCKMETHODID lockmethodid); extern void LockReleaseCurrentOwner(LOCALLOCK **locallocks, int nlocks); extern void LockReassignCurrentOwner(LOCALLOCK **locallocks, int nlocks); extern bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode); +extern bool LockOrStrongerHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode); #ifdef USE_ASSERT_CHECKING extern HTAB *GetLockMethodLocalHash(void); #endif |