Skip to content

Commit cea89c9

Browse files
committed
Turn AT_PASS_* macros into an enum
This make this code simpler and easier to follow. Also, patches that want to change the passes won't have to renumber the whole list. Reviewed-by: Amul Sul <sulamul@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CAAJ_b94yyJeGA-5M951_Lr+KfZokOp-2kXicpmEhi5FXhBeTog@mail.gmail.com
1 parent 1141e29 commit cea89c9

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

src/backend/commands/tablecmds.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,24 @@ static List *on_commits = NIL;
142142
* a pass determined by subcommand type.
143143
*/
144144

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)
159163

160164
typedef struct AlteredTableInfo
161165
{
@@ -399,12 +403,12 @@ static void ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
399403
static void ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
400404
AlterTableUtilityContext *context);
401405
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab,
402-
AlterTableCmd *cmd, LOCKMODE lockmode, int cur_pass,
406+
AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass,
403407
AlterTableUtilityContext *context);
404408
static AlterTableCmd *ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab,
405409
Relation rel, AlterTableCmd *cmd,
406410
bool recurse, LOCKMODE lockmode,
407-
int cur_pass,
411+
AlterTablePass cur_pass,
408412
AlterTableUtilityContext *context);
409413
static void ATRewriteTables(AlterTableStmt *parsetree,
410414
List **wqueue, LOCKMODE lockmode,
@@ -427,7 +431,7 @@ static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recu
427431
static ObjectAddress ATExecAddColumn(List **wqueue, AlteredTableInfo *tab,
428432
Relation rel, AlterTableCmd **cmd,
429433
bool recurse, bool recursing,
430-
LOCKMODE lockmode, int cur_pass,
434+
LOCKMODE lockmode, AlterTablePass cur_pass,
431435
AlterTableUtilityContext *context);
432436
static bool check_for_column_name_collision(Relation rel, const char *colname,
433437
bool if_not_exists);
@@ -565,7 +569,7 @@ static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab,
565569
static void ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId,
566570
char *cmd, List **wqueue, LOCKMODE lockmode,
567571
bool rewrite);
568-
static void RebuildConstraintComment(AlteredTableInfo *tab, int pass,
572+
static void RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass,
569573
Oid objid, Relation rel, List *domname,
570574
const char *conname);
571575
static void TryReuseIndex(Oid oldId, IndexStmt *stmt);
@@ -4739,7 +4743,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
47394743
AlterTableUtilityContext *context)
47404744
{
47414745
AlteredTableInfo *tab;
4742-
int pass = AT_PASS_UNSET;
4746+
AlterTablePass pass = AT_PASS_UNSET;
47434747

47444748
/* Find or create work queue entry for this table */
47454749
tab = ATGetQueueEntry(wqueue, rel);
@@ -5113,7 +5117,6 @@ static void
51135117
ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
51145118
AlterTableUtilityContext *context)
51155119
{
5116-
int pass;
51175120
ListCell *ltab;
51185121

51195122
/*
@@ -5123,7 +5126,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
51235126
* re-adding of the foreign key constraint to the other table). Work can
51245127
* only be propagated into later passes, however.
51255128
*/
5126-
for (pass = 0; pass < AT_NUM_PASSES; pass++)
5129+
for (AlterTablePass pass = 0; pass < AT_NUM_PASSES; pass++)
51275130
{
51285131
/* Go through each table that needs to be processed */
51295132
foreach(ltab, *wqueue)
@@ -5186,7 +5189,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
51865189
*/
51875190
static void
51885191
ATExecCmd(List **wqueue, AlteredTableInfo *tab,
5189-
AlterTableCmd *cmd, LOCKMODE lockmode, int cur_pass,
5192+
AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass,
51905193
AlterTableUtilityContext *context)
51915194
{
51925195
ObjectAddress address = InvalidObjectAddress;
@@ -5513,7 +5516,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,
55135516
static AlterTableCmd *
55145517
ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
55155518
AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode,
5516-
int cur_pass, AlterTableUtilityContext *context)
5519+
AlterTablePass cur_pass, AlterTableUtilityContext *context)
55175520
{
55185521
AlterTableCmd *newcmd = NULL;
55195522
AlterTableStmt *atstmt = makeNode(AlterTableStmt);
@@ -5551,7 +5554,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
55515554
foreach(lc, atstmt->cmds)
55525555
{
55535556
AlterTableCmd *cmd2 = lfirst_node(AlterTableCmd, lc);
5554-
int pass;
5557+
AlterTablePass pass;
55555558

55565559
/*
55575560
* 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,
69566959
static ObjectAddress
69576960
ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
69586961
AlterTableCmd **cmd, bool recurse, bool recursing,
6959-
LOCKMODE lockmode, int cur_pass,
6962+
LOCKMODE lockmode, AlterTablePass cur_pass,
69606963
AlterTableUtilityContext *context)
69616964
{
69626965
Oid myrelid = RelationGetRelid(rel);
@@ -14232,7 +14235,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
1423214235
* entry; but callers already have them so might as well pass them.)
1423314236
*/
1423414237
static void
14235-
RebuildConstraintComment(AlteredTableInfo *tab, int pass, Oid objid,
14238+
RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass, Oid objid,
1423614239
Relation rel, List *domname,
1423714240
const char *conname)
1423814241
{

src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ AlterTSConfigurationStmt
9797
AlterTSDictionaryStmt
9898
AlterTableCmd
9999
AlterTableMoveAllStmt
100+
AlterTablePass
100101
AlterTableSpaceOptionsStmt
101102
AlterTableStmt
102103
AlterTableType

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy