Commit 0c237715 authored by Alvaro Herrera's avatar Alvaro Herrera

DETACH PARTITION: hold locks on indexes until end of transaction

When a partition is detached from its parent, we acquire locks on all
attached indexes to also detach them ... but we release those locks
immediately.  This is a violation of the policy of keeping locks on user
objects to the end of the transaction.  Bug introduced in 8b08f7d4.

It's unclear that there are any ill effects possible, but it's clearly
wrong nonetheless.  It's likely that bad behavior *is* possible, but
mostly because the relation that the index is for is only locked with
AccessShareLock, which is an older bug that shall be fixed separately.

While touching that line of code, close the index opened with
index_open() using index_close() instead of relation_close().
No difference in practice, but let's be consistent.

Unearthed by Robert Haas.

Discussion: https://postgr.es/m/CA+TgmoYruJQ+2qnFLtF1xQtr71pdwgfxy3Ziy-TxV28M6pEmyA@mail.gmail.com
parent 4cba9c2a
...@@ -14648,7 +14648,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name) ...@@ -14648,7 +14648,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
idx = index_open(idxid, AccessExclusiveLock); idx = index_open(idxid, AccessExclusiveLock);
IndexSetParentIndex(idx, InvalidOid); IndexSetParentIndex(idx, InvalidOid);
update_relispartition(classRel, idxid, false); update_relispartition(classRel, idxid, false);
relation_close(idx, AccessExclusiveLock); index_close(idx, NoLock);
} }
heap_close(classRel, RowExclusiveLock); heap_close(classRel, RowExclusiveLock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment