1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-24 10:47:04 +03:00

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
This commit is contained in:
Peter Eisentraut 2024-01-01 19:17:18 +01:00
parent 1141e29b61
commit cea89c93a1
2 changed files with 30 additions and 26 deletions

View File

@ -142,20 +142,24 @@ static List *on_commits = NIL;
* a pass determined by subcommand type. * a pass determined by subcommand type.
*/ */
#define AT_PASS_UNSET -1 /* UNSET will cause ERROR */ typedef enum AlterTablePass
#define AT_PASS_DROP 0 /* DROP (all flavors) */ {
#define AT_PASS_ALTER_TYPE 1 /* ALTER COLUMN TYPE */ AT_PASS_UNSET = -1, /* UNSET will cause ERROR */
#define AT_PASS_OLD_INDEX 2 /* re-add existing indexes */ AT_PASS_DROP, /* DROP (all flavors) */
#define AT_PASS_OLD_CONSTR 3 /* re-add existing constraints */ AT_PASS_ALTER_TYPE, /* ALTER COLUMN TYPE */
/* We could support a RENAME COLUMN pass here, but not currently used */ AT_PASS_OLD_INDEX, /* re-add existing indexes */
#define AT_PASS_ADD_COL 4 /* ADD COLUMN */ AT_PASS_OLD_CONSTR, /* re-add existing constraints */
#define AT_PASS_ADD_CONSTR 5 /* ADD constraints (initial examination) */ /* We could support a RENAME COLUMN pass here, but not currently used */
#define AT_PASS_COL_ATTRS 6 /* set column attributes, eg NOT NULL */ AT_PASS_ADD_COL, /* ADD COLUMN */
#define AT_PASS_ADD_INDEXCONSTR 7 /* ADD index-based constraints */ AT_PASS_ADD_CONSTR, /* ADD constraints (initial examination) */
#define AT_PASS_ADD_INDEX 8 /* ADD indexes */ AT_PASS_COL_ATTRS, /* set column attributes, eg NOT NULL */
#define AT_PASS_ADD_OTHERCONSTR 9 /* ADD other constraints, defaults */ AT_PASS_ADD_INDEXCONSTR, /* ADD index-based constraints */
#define AT_PASS_MISC 10 /* other stuff */ AT_PASS_ADD_INDEX, /* ADD indexes */
#define AT_NUM_PASSES 11 AT_PASS_ADD_OTHERCONSTR, /* ADD other constraints, defaults */
AT_PASS_MISC, /* other stuff */
} AlterTablePass;
#define AT_NUM_PASSES (AT_PASS_MISC + 1)
typedef struct AlteredTableInfo typedef struct AlteredTableInfo
{ {
@ -399,12 +403,12 @@ static void ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
static void ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode, static void ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
AlterTableUtilityContext *context); AlterTableUtilityContext *context);
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab, static void ATExecCmd(List **wqueue, AlteredTableInfo *tab,
AlterTableCmd *cmd, LOCKMODE lockmode, int cur_pass, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass,
AlterTableUtilityContext *context); AlterTableUtilityContext *context);
static AlterTableCmd *ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, static AlterTableCmd *ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab,
Relation rel, AlterTableCmd *cmd, Relation rel, AlterTableCmd *cmd,
bool recurse, LOCKMODE lockmode, bool recurse, LOCKMODE lockmode,
int cur_pass, AlterTablePass cur_pass,
AlterTableUtilityContext *context); AlterTableUtilityContext *context);
static void ATRewriteTables(AlterTableStmt *parsetree, static void ATRewriteTables(AlterTableStmt *parsetree,
List **wqueue, LOCKMODE lockmode, List **wqueue, LOCKMODE lockmode,
@ -427,7 +431,7 @@ static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recu
static ObjectAddress ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, static ObjectAddress ATExecAddColumn(List **wqueue, AlteredTableInfo *tab,
Relation rel, AlterTableCmd **cmd, Relation rel, AlterTableCmd **cmd,
bool recurse, bool recursing, bool recurse, bool recursing,
LOCKMODE lockmode, int cur_pass, LOCKMODE lockmode, AlterTablePass cur_pass,
AlterTableUtilityContext *context); AlterTableUtilityContext *context);
static bool check_for_column_name_collision(Relation rel, const char *colname, static bool check_for_column_name_collision(Relation rel, const char *colname,
bool if_not_exists); bool if_not_exists);
@ -565,7 +569,7 @@ static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab,
static void ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, static void ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId,
char *cmd, List **wqueue, LOCKMODE lockmode, char *cmd, List **wqueue, LOCKMODE lockmode,
bool rewrite); bool rewrite);
static void RebuildConstraintComment(AlteredTableInfo *tab, int pass, static void RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass,
Oid objid, Relation rel, List *domname, Oid objid, Relation rel, List *domname,
const char *conname); const char *conname);
static void TryReuseIndex(Oid oldId, IndexStmt *stmt); static void TryReuseIndex(Oid oldId, IndexStmt *stmt);
@ -4739,7 +4743,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
AlterTableUtilityContext *context) AlterTableUtilityContext *context)
{ {
AlteredTableInfo *tab; AlteredTableInfo *tab;
int pass = AT_PASS_UNSET; AlterTablePass pass = AT_PASS_UNSET;
/* Find or create work queue entry for this table */ /* Find or create work queue entry for this table */
tab = ATGetQueueEntry(wqueue, rel); tab = ATGetQueueEntry(wqueue, rel);
@ -5113,7 +5117,6 @@ static void
ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode, ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
AlterTableUtilityContext *context) AlterTableUtilityContext *context)
{ {
int pass;
ListCell *ltab; ListCell *ltab;
/* /*
@ -5123,7 +5126,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
* re-adding of the foreign key constraint to the other table). Work can * re-adding of the foreign key constraint to the other table). Work can
* only be propagated into later passes, however. * only be propagated into later passes, however.
*/ */
for (pass = 0; pass < AT_NUM_PASSES; pass++) for (AlterTablePass pass = 0; pass < AT_NUM_PASSES; pass++)
{ {
/* Go through each table that needs to be processed */ /* Go through each table that needs to be processed */
foreach(ltab, *wqueue) foreach(ltab, *wqueue)
@ -5186,7 +5189,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
*/ */
static void static void
ATExecCmd(List **wqueue, AlteredTableInfo *tab, ATExecCmd(List **wqueue, AlteredTableInfo *tab,
AlterTableCmd *cmd, LOCKMODE lockmode, int cur_pass, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass,
AlterTableUtilityContext *context) AlterTableUtilityContext *context)
{ {
ObjectAddress address = InvalidObjectAddress; ObjectAddress address = InvalidObjectAddress;
@ -5513,7 +5516,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,
static AlterTableCmd * static AlterTableCmd *
ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode,
int cur_pass, AlterTableUtilityContext *context) AlterTablePass cur_pass, AlterTableUtilityContext *context)
{ {
AlterTableCmd *newcmd = NULL; AlterTableCmd *newcmd = NULL;
AlterTableStmt *atstmt = makeNode(AlterTableStmt); AlterTableStmt *atstmt = makeNode(AlterTableStmt);
@ -5551,7 +5554,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
foreach(lc, atstmt->cmds) foreach(lc, atstmt->cmds)
{ {
AlterTableCmd *cmd2 = lfirst_node(AlterTableCmd, lc); AlterTableCmd *cmd2 = lfirst_node(AlterTableCmd, lc);
int pass; AlterTablePass pass;
/* /*
* This switch need only cover the subcommand types that can be added * 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,
static ObjectAddress static ObjectAddress
ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
AlterTableCmd **cmd, bool recurse, bool recursing, AlterTableCmd **cmd, bool recurse, bool recursing,
LOCKMODE lockmode, int cur_pass, LOCKMODE lockmode, AlterTablePass cur_pass,
AlterTableUtilityContext *context) AlterTableUtilityContext *context)
{ {
Oid myrelid = RelationGetRelid(rel); Oid myrelid = RelationGetRelid(rel);
@ -14232,7 +14235,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
* entry; but callers already have them so might as well pass them.) * entry; but callers already have them so might as well pass them.)
*/ */
static void static void
RebuildConstraintComment(AlteredTableInfo *tab, int pass, Oid objid, RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass, Oid objid,
Relation rel, List *domname, Relation rel, List *domname,
const char *conname) const char *conname)
{ {

View File

@ -97,6 +97,7 @@ AlterTSConfigurationStmt
AlterTSDictionaryStmt AlterTSDictionaryStmt
AlterTableCmd AlterTableCmd
AlterTableMoveAllStmt AlterTableMoveAllStmt
AlterTablePass
AlterTableSpaceOptionsStmt AlterTableSpaceOptionsStmt
AlterTableStmt AlterTableStmt
AlterTableType AlterTableType