@@ -142,20 +142,24 @@ static List *on_commits = NIL;
142
142
* a pass determined by subcommand type.
143
143
*/
144
144
145
- #define AT_PASS_UNSET -1 /* UNSET will cause ERROR */
146
- #define AT_PASS_DROP 0 /* DROP (all flavors) */
147
- #define AT_PASS_ALTER_TYPE 1 /* ALTER COLUMN TYPE */
148
- #define AT_PASS_OLD_INDEX 2 /* re-add existing indexes */
149
- #define AT_PASS_OLD_CONSTR 3 /* re-add existing constraints */
150
- /* We could support a RENAME COLUMN pass here, but not currently used */
151
- #define AT_PASS_ADD_COL 4 /* ADD COLUMN */
152
- #define AT_PASS_ADD_CONSTR 5 /* ADD constraints (initial examination) */
153
- #define AT_PASS_COL_ATTRS 6 /* set column attributes, eg NOT NULL */
154
- #define AT_PASS_ADD_INDEXCONSTR 7 /* ADD index-based constraints */
155
- #define AT_PASS_ADD_INDEX 8 /* ADD indexes */
156
- #define AT_PASS_ADD_OTHERCONSTR 9 /* ADD other constraints, defaults */
157
- #define AT_PASS_MISC 10 /* other stuff */
158
- #define AT_NUM_PASSES 11
145
+ typedef enum AlterTablePass
146
+ {
147
+ AT_PASS_UNSET = -1, /* UNSET will cause ERROR */
148
+ AT_PASS_DROP, /* DROP (all flavors) */
149
+ AT_PASS_ALTER_TYPE, /* ALTER COLUMN TYPE */
150
+ AT_PASS_OLD_INDEX, /* re-add existing indexes */
151
+ AT_PASS_OLD_CONSTR, /* re-add existing constraints */
152
+ /* We could support a RENAME COLUMN pass here, but not currently used */
153
+ AT_PASS_ADD_COL, /* ADD COLUMN */
154
+ AT_PASS_ADD_CONSTR, /* ADD constraints (initial examination) */
155
+ AT_PASS_COL_ATTRS, /* set column attributes, eg NOT NULL */
156
+ AT_PASS_ADD_INDEXCONSTR, /* ADD index-based constraints */
157
+ AT_PASS_ADD_INDEX, /* ADD indexes */
158
+ AT_PASS_ADD_OTHERCONSTR, /* ADD other constraints, defaults */
159
+ AT_PASS_MISC, /* other stuff */
160
+ } AlterTablePass;
161
+
162
+ #define AT_NUM_PASSES (AT_PASS_MISC + 1)
159
163
160
164
typedef struct AlteredTableInfo
161
165
{
@@ -399,12 +403,12 @@ static void ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
399
403
static void ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
400
404
AlterTableUtilityContext *context);
401
405
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab,
402
- AlterTableCmd *cmd, LOCKMODE lockmode, int cur_pass,
406
+ AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass,
403
407
AlterTableUtilityContext *context);
404
408
static AlterTableCmd *ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab,
405
409
Relation rel, AlterTableCmd *cmd,
406
410
bool recurse, LOCKMODE lockmode,
407
- int cur_pass,
411
+ AlterTablePass cur_pass,
408
412
AlterTableUtilityContext *context);
409
413
static void ATRewriteTables(AlterTableStmt *parsetree,
410
414
List **wqueue, LOCKMODE lockmode,
@@ -427,7 +431,7 @@ static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recu
427
431
static ObjectAddress ATExecAddColumn(List **wqueue, AlteredTableInfo *tab,
428
432
Relation rel, AlterTableCmd **cmd,
429
433
bool recurse, bool recursing,
430
- LOCKMODE lockmode, int cur_pass,
434
+ LOCKMODE lockmode, AlterTablePass cur_pass,
431
435
AlterTableUtilityContext *context);
432
436
static bool check_for_column_name_collision(Relation rel, const char *colname,
433
437
bool if_not_exists);
@@ -565,7 +569,7 @@ static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab,
565
569
static void ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId,
566
570
char *cmd, List **wqueue, LOCKMODE lockmode,
567
571
bool rewrite);
568
- static void RebuildConstraintComment(AlteredTableInfo *tab, int pass,
572
+ static void RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass,
569
573
Oid objid, Relation rel, List *domname,
570
574
const char *conname);
571
575
static void TryReuseIndex(Oid oldId, IndexStmt *stmt);
@@ -4739,7 +4743,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
4739
4743
AlterTableUtilityContext *context)
4740
4744
{
4741
4745
AlteredTableInfo *tab;
4742
- int pass = AT_PASS_UNSET;
4746
+ AlterTablePass pass = AT_PASS_UNSET;
4743
4747
4744
4748
/* Find or create work queue entry for this table */
4745
4749
tab = ATGetQueueEntry(wqueue, rel);
@@ -5113,7 +5117,6 @@ static void
5113
5117
ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
5114
5118
AlterTableUtilityContext *context)
5115
5119
{
5116
- int pass;
5117
5120
ListCell *ltab;
5118
5121
5119
5122
/*
@@ -5123,7 +5126,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
5123
5126
* re-adding of the foreign key constraint to the other table). Work can
5124
5127
* only be propagated into later passes, however.
5125
5128
*/
5126
- for (pass = 0; pass < AT_NUM_PASSES; pass++)
5129
+ for (AlterTablePass pass = 0; pass < AT_NUM_PASSES; pass++)
5127
5130
{
5128
5131
/* Go through each table that needs to be processed */
5129
5132
foreach(ltab, *wqueue)
@@ -5186,7 +5189,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
5186
5189
*/
5187
5190
static void
5188
5191
ATExecCmd(List **wqueue, AlteredTableInfo *tab,
5189
- AlterTableCmd *cmd, LOCKMODE lockmode, int cur_pass,
5192
+ AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass,
5190
5193
AlterTableUtilityContext *context)
5191
5194
{
5192
5195
ObjectAddress address = InvalidObjectAddress;
@@ -5513,7 +5516,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,
5513
5516
static AlterTableCmd *
5514
5517
ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
5515
5518
AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode,
5516
- int cur_pass, AlterTableUtilityContext *context)
5519
+ AlterTablePass cur_pass, AlterTableUtilityContext *context)
5517
5520
{
5518
5521
AlterTableCmd *newcmd = NULL;
5519
5522
AlterTableStmt *atstmt = makeNode(AlterTableStmt);
@@ -5551,7 +5554,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
5551
5554
foreach(lc, atstmt->cmds)
5552
5555
{
5553
5556
AlterTableCmd *cmd2 = lfirst_node(AlterTableCmd, lc);
5554
- int pass;
5557
+ AlterTablePass pass;
5555
5558
5556
5559
/*
5557
5560
* This switch need only cover the subcommand types that can be added
@@ -6956,7 +6959,7 @@ ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
6956
6959
static ObjectAddress
6957
6960
ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
6958
6961
AlterTableCmd **cmd, bool recurse, bool recursing,
6959
- LOCKMODE lockmode, int cur_pass,
6962
+ LOCKMODE lockmode, AlterTablePass cur_pass,
6960
6963
AlterTableUtilityContext *context)
6961
6964
{
6962
6965
Oid myrelid = RelationGetRelid(rel);
@@ -14232,7 +14235,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
14232
14235
* entry; but callers already have them so might as well pass them.)
14233
14236
*/
14234
14237
static void
14235
- RebuildConstraintComment(AlteredTableInfo *tab, int pass, Oid objid,
14238
+ RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass, Oid objid,
14236
14239
Relation rel, List *domname,
14237
14240
const char *conname)
14238
14241
{
0 commit comments