mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Revert lowering of lock level for ATTACH PARTITION
I lowered the lock level for partitions being scanned from
AccessExclusive to ShareLock in the course of 72cf7f310c
, but that was
bogus, as pointed out by Robert Haas. Revert that bit. Doing this is
possible, but requires more work.
Discussion: https://postgr.es/m/CA+TgmobV7Nfmqv+TZXcdSsb9Bjc-OL-Anv6BNmCbfJVZLYPE4Q@mail.gmail.com
This commit is contained in:
@ -13997,10 +13997,9 @@ QueuePartitionConstraintValidation(List **wqueue, Relation scanrel,
|
|||||||
List *thisPartConstraint;
|
List *thisPartConstraint;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the minimum lock we need to prevent concurrent data
|
* This is the minimum lock we need to prevent deadlocks.
|
||||||
* additions.
|
|
||||||
*/
|
*/
|
||||||
part_rel = heap_open(partdesc->oids[i], ShareLock);
|
part_rel = heap_open(partdesc->oids[i], AccessExclusiveLock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adjust the constraint for scanrel so that it matches this
|
* Adjust the constraint for scanrel so that it matches this
|
||||||
@ -14113,17 +14112,17 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
|
|||||||
*
|
*
|
||||||
* We do that by checking if rel is a member of the list of attachrel's
|
* We do that by checking if rel is a member of the list of attachrel's
|
||||||
* partitions provided the latter is partitioned at all. We want to avoid
|
* partitions provided the latter is partitioned at all. We want to avoid
|
||||||
* having to construct this list again, so we request a lock on all
|
* having to construct this list again, so we request the strongest lock
|
||||||
* partitions. We need ShareLock, preventing data changes, because we
|
* on all partitions. We need the strongest lock, because we may decide
|
||||||
* may decide to scan them if we find out that the table being attached (or
|
* to scan them if we find out that the table being attached (or its leaf
|
||||||
* its leaf partitions) may contain rows that violate the partition
|
* partitions) may contain rows that violate the partition constraint. If
|
||||||
* constraint. If the table has a constraint that would prevent such rows,
|
* the table has a constraint that would prevent such rows, which by
|
||||||
* which by definition is present in all the partitions, we need not scan
|
* definition is present in all the partitions, we need not scan the
|
||||||
* the table, nor its partitions. But we cannot risk a deadlock by taking
|
* table, nor its partitions. But we cannot risk a deadlock by taking a
|
||||||
* a weaker lock now and the stronger one only when needed.
|
* weaker lock now and the stronger one only when needed.
|
||||||
*/
|
*/
|
||||||
attachrel_children = find_all_inheritors(RelationGetRelid(attachrel),
|
attachrel_children = find_all_inheritors(RelationGetRelid(attachrel),
|
||||||
ShareLock, NULL);
|
AccessExclusiveLock, NULL);
|
||||||
if (list_member_oid(attachrel_children, RelationGetRelid(rel)))
|
if (list_member_oid(attachrel_children, RelationGetRelid(rel)))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DUPLICATE_TABLE),
|
(errcode(ERRCODE_DUPLICATE_TABLE),
|
||||||
|
Reference in New Issue
Block a user