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

Function MarkInheritDetached

src/backend/commands/tablecmds.c:17489–17552  ·  view source on GitHub ↗

* MarkInheritDetached * * Set inhdetachpending for a partition, for ATExecDetachPartition * in concurrent mode. While at it, verify that no other partition is * already pending detach. */

Source from the content-addressed store, hash-verified

17487 * already pending detach.
17488 */
17489static void
17490MarkInheritDetached(Relation child_rel, Relation parent_rel)
17491{
17492 Relation catalogRelation;
17493 SysScanDesc scan;
17494 ScanKeyData key;
17495 HeapTuple inheritsTuple;
17496 bool found = false;
17497
17498 Assert(parent_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
17499
17500 /*
17501 * Find pg_inherits entries by inhparent. (We need to scan them all in
17502 * order to verify that no other partition is pending detach.)
17503 */
17504 catalogRelation = table_open(InheritsRelationId, RowExclusiveLock);
17505 ScanKeyInit(&key,
17506 Anum_pg_inherits_inhparent,
17507 BTEqualStrategyNumber, F_OIDEQ,
17508 ObjectIdGetDatum(RelationGetRelid(parent_rel)));
17509 scan = systable_beginscan(catalogRelation, InheritsParentIndexId,
17510 true, NULL, 1, &key);
17511
17512 while (HeapTupleIsValid(inheritsTuple = systable_getnext(scan)))
17513 {
17514 Form_pg_inherits inhForm;
17515
17516 inhForm = (Form_pg_inherits) GETSTRUCT(inheritsTuple);
17517 if (inhForm->inhdetachpending)
17518 ereport(ERROR,
17519 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
17520 errmsg("partition \"%s\" already pending detach in partitioned table \"%s.%s\"",
17521 get_rel_name(inhForm->inhrelid),
17522 get_namespace_name(parent_rel->rd_rel->relnamespace),
17523 RelationGetRelationName(parent_rel)),
17524 errhint("Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
17525
17526 if (inhForm->inhrelid == RelationGetRelid(child_rel))
17527 {
17528 HeapTuple newtup;
17529
17530 newtup = heap_copytuple(inheritsTuple);
17531 ((Form_pg_inherits) GETSTRUCT(newtup))->inhdetachpending = true;
17532
17533 CatalogTupleUpdate(catalogRelation,
17534 &inheritsTuple->t_self,
17535 newtup);
17536 found = true;
17537 heap_freetuple(newtup);
17538 /* keep looking, to ensure we catch others pending detach */
17539 }
17540 }
17541
17542 /* Done */
17543 systable_endscan(scan);
17544 table_close(catalogRelation, RowExclusiveLock);
17545
17546 if (!found)

Callers 1

ATExecDetachPartitionFunction · 0.85

Calls 15

table_openFunction · 0.85
ScanKeyInitFunction · 0.85
ObjectIdGetDatumFunction · 0.85
systable_beginscanFunction · 0.85
systable_getnextFunction · 0.85
get_rel_nameFunction · 0.85
get_namespace_nameFunction · 0.85
heap_copytupleFunction · 0.85
CatalogTupleUpdateFunction · 0.85
heap_freetupleFunction · 0.85
systable_endscanFunction · 0.85
table_closeFunction · 0.85

Tested by

no test coverage detected