MCPcopy Create free account
hub / github.com/apache/cloudberry / DetachPartitionFinalize

Function DetachPartitionFinalize

src/backend/commands/tablecmds.c:22351–22552  ·  view source on GitHub ↗

* Second part of ALTER TABLE .. DETACH. * * This is separate so that it can be run independently when the second * transaction of the concurrent algorithm fails (crash or abort). */

Source from the content-addressed store, hash-verified

22349 * transaction of the concurrent algorithm fails (crash or abort).
22350 */
22351static void
22352DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent,
22353 Oid defaultPartOid)
22354{
22355 Relation classRel;
22356 List *fks;
22357 ListCell *cell;
22358 List *indexes;
22359 Datum new_val[Natts_pg_class];
22360 bool new_null[Natts_pg_class],
22361 new_repl[Natts_pg_class];
22362 HeapTuple tuple,
22363 newtuple;
22364
22365 if (concurrent)
22366 {
22367 /*
22368 * Update status of parent relative views.
22369 * We must do this before RemoveInheritance.
22370 * Detach a partition means delete data from parent.
22371 */
22372 if (IS_QD_OR_SINGLENODE())
22373 SetRelativeMatviewAuxStatus(RelationGetRelid(rel),
22374 MV_DATA_STATUS_EXPIRED,
22375 MV_DATA_STATUS_TRANSFER_DIRECTION_UP);
22376
22377 /*
22378 * We can remove the pg_inherits row now. (In the non-concurrent case,
22379 * this was already done).
22380 */
22381 RemoveInheritance(partRel, rel, true);
22382 }
22383
22384 /* Drop any triggers that were cloned on creation/attach. */
22385 DropClonedTriggersFromPartition(RelationGetRelid(partRel));
22386
22387 /*
22388 * Detach any foreign keys that are inherited. This includes creating
22389 * additional action triggers.
22390 */
22391 fks = copyObject(RelationGetFKeyList(partRel));
22392 foreach(cell, fks)
22393 {
22394 ForeignKeyCacheInfo *fk = lfirst(cell);
22395 HeapTuple contup;
22396 Form_pg_constraint conform;
22397 Constraint *fkconstraint;
22398
22399 contup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fk->conoid));
22400 if (!HeapTupleIsValid(contup))
22401 elog(ERROR, "cache lookup failed for constraint %u", fk->conoid);
22402 conform = (Form_pg_constraint) GETSTRUCT(contup);
22403
22404 /* consider only the inherited foreign keys */
22405 if (conform->contype != CONSTRAINT_FOREIGN ||
22406 !OidIsValid(conform->conparentid))
22407 {
22408 ReleaseSysCache(contup);

Callers 2

ATExecDetachPartitionFunction · 0.85

Calls 15

RemoveInheritanceFunction · 0.85
RelationGetFKeyListFunction · 0.85
SearchSysCache1Function · 0.85
ObjectIdGetDatumFunction · 0.85
ReleaseSysCacheFunction · 0.85
list_free_deepFunction · 0.85

Tested by

no test coverage detected