* ATPrepCmd * * Traffic cop for ALTER TABLE Phase 1 operations, including simple * recursion and permission checks. * * Caller must have acquired appropriate lock type on relation already. * This lock should be held until commit. */
| 5360 | * This lock should be held until commit. |
| 5361 | */ |
| 5362 | static void |
| 5363 | ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, |
| 5364 | bool recurse, bool recursing, LOCKMODE lockmode, |
| 5365 | AlterTableUtilityContext *context) |
| 5366 | { |
| 5367 | AlteredTableInfo *tab; |
| 5368 | int pass = AT_PASS_UNSET; |
| 5369 | |
| 5370 | /* Find or create work queue entry for this table */ |
| 5371 | tab = ATGetQueueEntry(wqueue, rel); |
| 5372 | |
| 5373 | /* |
| 5374 | * Disallow any ALTER TABLE other than ALTER TABLE DETACH FINALIZE on |
| 5375 | * partitions that are pending detach. |
| 5376 | */ |
| 5377 | if (rel->rd_rel->relispartition && |
| 5378 | cmd->subtype != AT_DetachPartitionFinalize && |
| 5379 | PartitionHasPendingDetach(RelationGetRelid(rel))) |
| 5380 | ereport(ERROR, |
| 5381 | errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), |
| 5382 | errmsg("cannot alter partition \"%s\" with an incomplete detach", |
| 5383 | RelationGetRelationName(rel)), |
| 5384 | errhint("Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation.")); |
| 5385 | |
| 5386 | /* |
| 5387 | * Copy the original subcommand for each table. This avoids conflicts |
| 5388 | * when different child tables need to make different parse |
| 5389 | * transformations (for example, the same column may have different column |
| 5390 | * numbers in different children). |
| 5391 | */ |
| 5392 | cmd = copyObject(cmd); |
| 5393 | |
| 5394 | /* |
| 5395 | * Do permissions and relkind checking, recursion to child tables if |
| 5396 | * needed, and any additional phase-1 processing needed. (But beware of |
| 5397 | * adding any processing that looks at table details that another |
| 5398 | * subcommand could change. In some cases we reject multiple subcommands |
| 5399 | * that could try to change the same state in contrary ways.) |
| 5400 | */ |
| 5401 | switch (cmd->subtype) |
| 5402 | { |
| 5403 | case AT_AddColumn: /* ADD COLUMN */ |
| 5404 | ATSimplePermissions(rel, |
| 5405 | ATT_TABLE | ATT_COMPOSITE_TYPE | ATT_FOREIGN_TABLE); |
| 5406 | ATPrepAddColumn(wqueue, rel, recurse, recursing, false, cmd, |
| 5407 | lockmode, context); |
| 5408 | /* Recursion occurs during execution phase */ |
| 5409 | pass = AT_PASS_ADD_COL; |
| 5410 | break; |
| 5411 | case AT_AddColumnToView: /* add column via CREATE OR REPLACE VIEW */ |
| 5412 | ATSimplePermissions(rel, ATT_VIEW); |
| 5413 | ATPrepAddColumn(wqueue, rel, recurse, recursing, true, cmd, |
| 5414 | lockmode, context); |
| 5415 | /* Recursion occurs during execution phase */ |
| 5416 | pass = AT_PASS_ADD_COL; |
| 5417 | break; |
| 5418 | case AT_ColumnDefault: /* ALTER COLUMN DEFAULT */ |
| 5419 |
no test coverage detected