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

Function ATExecDropColumn

src/backend/commands/tablecmds.c:10312–10504  ·  view source on GitHub ↗

* Drops column 'colName' from relation 'rel' and returns the address of the * dropped column. The column is also dropped (or marked as no longer * inherited from relation) from the relation's inheritance children, if any. * * In the recursive invocations for inheritance child relations, instead of * dropping the column directly (if to be dropped at all), its object address * is added to 'ad

Source from the content-addressed store, hash-verified

10310 * checked recursively.
10311 */
10312static ObjectAddress
10313ATExecDropColumn(List **wqueue, Relation rel, const char *colName,
10314 DropBehavior behavior,
10315 bool recurse, bool recursing,
10316 bool missing_ok, LOCKMODE lockmode,
10317 ObjectAddresses *addrs)
10318{
10319 HeapTuple tuple;
10320 Form_pg_attribute targetatt;
10321 AttrNumber attnum;
10322 List *children;
10323 ObjectAddress object;
10324 bool is_expr;
10325
10326 /* At top level, permission check was done in ATPrepCmd, else do it */
10327 if (recursing)
10328 ATSimplePermissions(rel, ATT_TABLE | ATT_FOREIGN_TABLE);
10329
10330 /* Initialize addrs on the first invocation */
10331 Assert(!recursing || addrs != NULL);
10332 if (!recursing)
10333 addrs = new_object_addresses();
10334
10335 /*
10336 * get the number of the attribute
10337 */
10338 tuple = SearchSysCacheAttName(RelationGetRelid(rel), colName);
10339 if (!HeapTupleIsValid(tuple))
10340 {
10341 if (!missing_ok)
10342 {
10343 ereport(ERROR,
10344 (errcode(ERRCODE_UNDEFINED_COLUMN),
10345 errmsg("column \"%s\" of relation \"%s\" does not exist",
10346 colName, RelationGetRelationName(rel))));
10347 }
10348 else
10349 {
10350 ereport((Gp_role == GP_ROLE_EXECUTE) ? DEBUG1 : NOTICE,
10351 (errmsg("column \"%s\" of relation \"%s\" does not exist, skipping",
10352 colName, RelationGetRelationName(rel))));
10353 return InvalidObjectAddress;
10354 }
10355 }
10356 targetatt = (Form_pg_attribute) GETSTRUCT(tuple);
10357
10358 attnum = targetatt->attnum;
10359
10360 /* Can't drop a system attribute */
10361 if (attnum <= 0)
10362 ereport(ERROR,
10363 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10364 errmsg("cannot drop system column \"%s\"",
10365 colName)));
10366
10367 /*
10368 * Don't drop inherited columns, unless recursing (presumably from a drop
10369 * of the parent column)

Callers 1

ATExecCmdFunction · 0.85

Calls 15

ATSimplePermissionsFunction · 0.85
new_object_addressesFunction · 0.85
SearchSysCacheAttNameFunction · 0.85
has_partition_attrsFunction · 0.85
bms_make_singletonFunction · 0.85
ReleaseSysCacheFunction · 0.85
table_openFunction · 0.85
CheckTableNotInUseFunction · 0.85
CatalogTupleUpdateFunction · 0.85
CommandCounterIncrementFunction · 0.85

Tested by

no test coverage detected