* AlterTable * Execute ALTER TABLE, which can be a list of subcommands * * ALTER TABLE is performed in three phases: * 1. Examine subcommands and perform pre-transformation checking. * 2. Validate and transform subcommands, and update system catalogs. * 3. Scan table(s) to check new constraints, and optionally recopy * the data into new table(s). * Phase 3 is not performed unless o
| 4800 | * Some of the fields therein, such as the relid, are used here as well. |
| 4801 | */ |
| 4802 | void |
| 4803 | AlterTable(AlterTableStmt *stmt, LOCKMODE lockmode, |
| 4804 | AlterTableUtilityContext *context) |
| 4805 | { |
| 4806 | Relation rel; |
| 4807 | |
| 4808 | /* Caller is required to provide an adequate lock. */ |
| 4809 | rel = relation_open(context->relid, NoLock); |
| 4810 | |
| 4811 | /* |
| 4812 | * GPDB creates ALTER stmts and executes them internally as part of some |
| 4813 | * partition related ALTER stmts, hence for such internal ALTER stmts |
| 4814 | * can't meet this requirement. |
| 4815 | */ |
| 4816 | if (!stmt->is_internal) |
| 4817 | CheckTableNotInUse(rel, "ALTER TABLE"); |
| 4818 | |
| 4819 | ATController(stmt, rel, stmt->cmds, stmt->relation->inh, lockmode, context); |
| 4820 | |
| 4821 | if (Gp_role == GP_ROLE_DISPATCH) |
| 4822 | { |
| 4823 | /* |
| 4824 | * If a transaction is in progress, kill any idle QE backends. They |
| 4825 | * might be running with obsolete information in their relcaches. Any |
| 4826 | * relcache invalidation events sent by the ALTER TABLE subcommands |
| 4827 | * won't be sent to the other backend until the end of transaction, and |
| 4828 | * we don't have any better way of invalidating them. The primary |
| 4829 | * writer backends should be up-to-date, because we have used that to |
| 4830 | * execute all the subcommands, so they should've created local |
| 4831 | * invalidation events for themselves. |
| 4832 | */ |
| 4833 | if (IsTransactionBlock()) |
| 4834 | DisconnectAndDestroyUnusedQEs(); |
| 4835 | |
| 4836 | if (stmt->cmds && ENABLE_DISPATCH()) |
| 4837 | CdbDispatchUtilityStatement((Node *) stmt, |
| 4838 | DF_CANCEL_ON_ERROR | |
| 4839 | DF_WITH_SNAPSHOT | |
| 4840 | DF_NEED_TWO_PHASE, |
| 4841 | GetAssignedOidsForDispatch(), |
| 4842 | NULL); |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | /* |
| 4847 | * Populate the column encoding option for each column in the relation. |
no test coverage detected