* ATRewriteCatalogs * * Traffic cop for ALTER TABLE Phase 2 operations. Subcommands are * dispatched in a "safe" execution order (designed to avoid unnecessary * conflicts). */
| 5967 | * conflicts). |
| 5968 | */ |
| 5969 | static void |
| 5970 | ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode, |
| 5971 | AlterTableUtilityContext *context) |
| 5972 | { |
| 5973 | int pass; |
| 5974 | ListCell *ltab; |
| 5975 | |
| 5976 | /* |
| 5977 | * We process all the tables "in parallel", one pass at a time. This is |
| 5978 | * needed because we may have to propagate work from one table to another |
| 5979 | * (specifically, ALTER TYPE on a foreign key's PK has to dispatch the |
| 5980 | * re-adding of the foreign key constraint to the other table). Work can |
| 5981 | * only be propagated into later passes, however. |
| 5982 | */ |
| 5983 | for (pass = 0; pass < AT_NUM_PASSES; pass++) |
| 5984 | { |
| 5985 | /* Go through each table that needs to be processed */ |
| 5986 | foreach(ltab, *wqueue) |
| 5987 | { |
| 5988 | AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab); |
| 5989 | List *subcmds = tab->subcmds[pass]; |
| 5990 | ListCell *lcmd; |
| 5991 | |
| 5992 | if (subcmds == NIL) |
| 5993 | continue; |
| 5994 | |
| 5995 | /* |
| 5996 | * Open the relation and store it in tab. This allows subroutines |
| 5997 | * close and reopen, if necessary. Appropriate lock was obtained |
| 5998 | * by phase 1, needn't get it again. |
| 5999 | */ |
| 6000 | tab->rel = relation_open(tab->relid, NoLock); |
| 6001 | |
| 6002 | foreach(lcmd, subcmds) |
| 6003 | ATExecCmd(wqueue, tab, |
| 6004 | castNode(AlterTableCmd, lfirst(lcmd)), |
| 6005 | lockmode, pass, context); |
| 6006 | |
| 6007 | /* |
| 6008 | * After the ALTER TYPE pass, do cleanup work (this is not done in |
| 6009 | * ATExecAlterColumnType since it should be done only once if |
| 6010 | * multiple columns of a table are altered). |
| 6011 | */ |
| 6012 | if (pass == AT_PASS_ALTER_TYPE) |
| 6013 | ATPostAlterTypeCleanup(wqueue, tab, lockmode, context); |
| 6014 | |
| 6015 | if (tab->rel) |
| 6016 | { |
| 6017 | relation_close(tab->rel, NoLock); |
| 6018 | tab->rel = NULL; |
| 6019 | } |
| 6020 | } |
| 6021 | } |
| 6022 | |
| 6023 | /* Check to see if a toast table must be added. */ |
| 6024 | foreach(ltab, *wqueue) |
| 6025 | { |
| 6026 | AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab); |
no test coverage detected