* ATController provides top level control over the phases. * * parsetree is passed in to allow it to be passed to event triggers * when requested. */
| 5250 | * when requested. |
| 5251 | */ |
| 5252 | static void |
| 5253 | ATController(AlterTableStmt *parsetree, |
| 5254 | Relation rel, List *cmds, bool recurse, LOCKMODE lockmode, |
| 5255 | AlterTableUtilityContext *context) |
| 5256 | { |
| 5257 | List *wqueue = NIL; |
| 5258 | ListCell *lcmd; |
| 5259 | |
| 5260 | cdb_sync_oid_to_segments(); |
| 5261 | |
| 5262 | /* |
| 5263 | * If the parsetree is dispatched from QD, we use the wqueue generated in QD |
| 5264 | * and ignore all subcmds that will be generated in QEs. Because the parsetree |
| 5265 | * and its subcmds in `AlteredTableInfo` contain some info that must sync |
| 5266 | * between QD and QEs, e.g. index name, sequence name. It's not allowed to |
| 5267 | * choose the relation/index/sequence/etc. names on QEs |
| 5268 | * |
| 5269 | * The following phase 1 should also be executed in QEs, which is different to |
| 5270 | * the previous version. When ALTER a column type with IDENTITY, the generated |
| 5271 | * beforeStmts are also executed. In other words, the phase 1 does not only |
| 5272 | * preparation step, but also execute some utilities, which can't be omitted. |
| 5273 | * We only run the phase 1, but discard all generated subcmds by QE itself. |
| 5274 | * |
| 5275 | * GPDB_13_MERGE_FIXME: |
| 5276 | * ATController() is called in two different situations: |
| 5277 | * 1. By AlterTable(), parsetree and context are not NULL, and parsetree->wqueue |
| 5278 | * is dispatched from QD, we ignore all the subcmds generated in QE side. |
| 5279 | * 2. By AlterTableInternal(), which is used in internal utility commands. |
| 5280 | * The parsetree and context are NULL, so the QE needs to build their own |
| 5281 | * subcmds normally. |
| 5282 | * |
| 5283 | * However, some internal functions doesn't know the difference. Currently, |
| 5284 | * we assume that AlterTableInternal() always passes `context` as NULL, |
| 5285 | * and the cmd->subtype isn't complicated, i.e. it doesn't call |
| 5286 | * transformAlterTableStmt() internally, could not be AlterColumnType. |
| 5287 | * If any of the assumptions is broken, we must refactor the logic to |
| 5288 | * adapter GPDB. |
| 5289 | */ |
| 5290 | if (parsetree && parsetree->wqueue) |
| 5291 | { |
| 5292 | ListCell *lc; |
| 5293 | |
| 5294 | Assert(Gp_role == GP_ROLE_EXECUTE); |
| 5295 | wqueue = parsetree->wqueue; |
| 5296 | |
| 5297 | foreach (lc, wqueue) |
| 5298 | { |
| 5299 | /* |
| 5300 | * The old tuple descriptors are not dispatched, so fetch |
| 5301 | * them here. |
| 5302 | */ |
| 5303 | AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(lc); |
| 5304 | Relation rel; |
| 5305 | |
| 5306 | rel = relation_open(tab->relid, lockmode); |
| 5307 | tab->oldDesc = CreateTupleDescCopyConstr(RelationGetDescr(rel)); |
| 5308 | relation_close(rel, NoLock); |
| 5309 | } |
no test coverage detected