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

Function ATExecAttachPartition

src/backend/commands/tablecmds.c:21451–21804  ·  view source on GitHub ↗

* ALTER TABLE ATTACH PARTITION FOR VALUES * * Return the address of the newly attached partition. */

Source from the content-addressed store, hash-verified

21449 * Return the address of the newly attached partition.
21450 */
21451static ObjectAddress
21452ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd,
21453 AlterTableUtilityContext *context)
21454{
21455 Relation attachrel,
21456 catalog;
21457 List *attachrel_children;
21458 List *partConstraint;
21459 SysScanDesc scan;
21460 ScanKeyData skey;
21461 AttrNumber attno;
21462 int natts;
21463 TupleDesc tupleDesc;
21464 ObjectAddress address;
21465 const char *trigger_name;
21466 Oid defaultPartOid;
21467 List *partBoundConstraint;
21468 ParseState *pstate = make_parsestate(NULL);
21469
21470 pstate->p_sourcetext = context->queryString;
21471
21472 /*
21473 * We must lock the default partition if one exists, because attaching a
21474 * new partition will change its partition constraint.
21475 */
21476 defaultPartOid =
21477 get_default_oid_from_partdesc(RelationGetPartitionDesc(rel, true));
21478 if (OidIsValid(defaultPartOid))
21479 LockRelationOid(defaultPartOid, AccessExclusiveLock);
21480
21481 attachrel = table_openrv(cmd->name, AccessExclusiveLock);
21482
21483 /*
21484 * XXX I think it'd be a good idea to grab locks on all tables referenced
21485 * by FKs at this point also.
21486 */
21487
21488 /*
21489 * Must be owner of both parent and source table -- parent was checked by
21490 * ATSimplePermissions call in ATPrepCmd
21491 */
21492 ATSimplePermissions(attachrel, ATT_TABLE | ATT_FOREIGN_TABLE);
21493
21494 /* A partition can only have one parent */
21495 if (attachrel->rd_rel->relispartition)
21496 ereport(ERROR,
21497 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
21498 errmsg("\"%s\" is already a partition",
21499 RelationGetRelationName(attachrel))));
21500
21501 if (OidIsValid(attachrel->rd_rel->reloftype))
21502 ereport(ERROR,
21503 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
21504 errmsg("cannot attach a typed table as partition")));
21505
21506 /*
21507 * Table being attached should not already be part of inheritance; either
21508 * as a child table...

Callers 1

ATExecCmdFunction · 0.85

Calls 15

make_parsestateFunction · 0.85
RelationGetPartitionDescFunction · 0.85
LockRelationOidFunction · 0.85
table_openrvFunction · 0.85
ATSimplePermissionsFunction · 0.85
table_openFunction · 0.85
ScanKeyInitFunction · 0.85
ObjectIdGetDatumFunction · 0.85
systable_beginscanFunction · 0.85
systable_getnextFunction · 0.85
systable_endscanFunction · 0.85

Tested by

no test coverage detected