* ALTER TABLE ... DETACH PARTITION ... FINALIZE * * To use when a DETACH PARTITION command previously did not run to * completion; this completes the detaching process. */
| 22558 | * completion; this completes the detaching process. |
| 22559 | */ |
| 22560 | static ObjectAddress |
| 22561 | ATExecDetachPartitionFinalize(Relation rel, RangeVar *name) |
| 22562 | { |
| 22563 | Relation partRel; |
| 22564 | ObjectAddress address; |
| 22565 | Snapshot snap = GetActiveSnapshot(); |
| 22566 | |
| 22567 | partRel = table_openrv(name, AccessExclusiveLock); |
| 22568 | |
| 22569 | /* |
| 22570 | * Wait until existing snapshots are gone. This is important if the |
| 22571 | * second transaction of DETACH PARTITION CONCURRENTLY is canceled: the |
| 22572 | * user could immediately run DETACH FINALIZE without actually waiting for |
| 22573 | * existing transactions. We must not complete the detach action until |
| 22574 | * all such queries are complete (otherwise we would present them with an |
| 22575 | * inconsistent view of catalogs). |
| 22576 | */ |
| 22577 | WaitForOlderSnapshots(snap->xmin, false); |
| 22578 | |
| 22579 | DetachPartitionFinalize(rel, partRel, true, InvalidOid); |
| 22580 | |
| 22581 | ObjectAddressSet(address, RelationRelationId, RelationGetRelid(partRel)); |
| 22582 | |
| 22583 | table_close(partRel, NoLock); |
| 22584 | |
| 22585 | return address; |
| 22586 | } |
| 22587 | |
| 22588 | /* |
| 22589 | * DetachAddConstraintIfNeeded |
no test coverage detected