v7-0001-Code-refactor-convert-macro-listing-to-enum.patch
application/octet-stream
Filename: v7-0001-Code-refactor-convert-macro-listing-to-enum.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v7-0001
Subject: Code refactor: convert macro listing to enum
| File | + | − |
|---|---|---|
| src/backend/commands/tablecmds.c | 22 | 18 |
From fd5b4673fce7b57aace3e9436cb64e8b3201e306 Mon Sep 17 00:00:00 2001
From: Amul Sul <amul.sul@enterprisedb.com>
Date: Mon, 11 Dec 2023 16:24:29 +0530
Subject: [PATCH v7 1/3] Code refactor: convert macro listing to enum
Also, moved AT_PASS_ADD_COL upward near AT_PASS_ALTER_TYPE.
---
src/backend/commands/tablecmds.c | 40 ++++++++++++++++++--------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 6b0a20010e2..ce386199ac3 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -142,20 +142,24 @@ static List *on_commits = NIL;
* a pass determined by subcommand type.
*/
-#define AT_PASS_UNSET -1 /* UNSET will cause ERROR */
-#define AT_PASS_DROP 0 /* DROP (all flavors) */
-#define AT_PASS_ALTER_TYPE 1 /* ALTER COLUMN TYPE */
-#define AT_PASS_OLD_INDEX 2 /* re-add existing indexes */
-#define AT_PASS_OLD_CONSTR 3 /* re-add existing constraints */
-/* We could support a RENAME COLUMN pass here, but not currently used */
-#define AT_PASS_ADD_COL 4 /* ADD COLUMN */
-#define AT_PASS_ADD_CONSTR 5 /* ADD constraints (initial examination) */
-#define AT_PASS_COL_ATTRS 6 /* set column attributes, eg NOT NULL */
-#define AT_PASS_ADD_INDEXCONSTR 7 /* ADD index-based constraints */
-#define AT_PASS_ADD_INDEX 8 /* ADD indexes */
-#define AT_PASS_ADD_OTHERCONSTR 9 /* ADD other constraints, defaults */
-#define AT_PASS_MISC 10 /* other stuff */
-#define AT_NUM_PASSES 11
+typedef enum AlteredTablePass
+{
+ AT_PASS_UNSET = -1, /* UNSET will cause ERROR */
+ AT_PASS_DROP, /* DROP (all flavors) */
+ AT_PASS_ALTER_TYPE, /* ALTER COLUMN TYPE */
+ AT_PASS_ADD_COL, /* ADD COLUMN */
+ AT_PASS_OLD_INDEX, /* re-add existing indexes */
+ AT_PASS_OLD_CONSTR, /* re-add existing constraints */
+ /* We could support a RENAME COLUMN pass here, but not currently used */
+ AT_PASS_ADD_CONSTR, /* ADD constraints (initial examination) */
+ AT_PASS_COL_ATTRS, /* set column attributes, eg NOT NULL */
+ AT_PASS_ADD_INDEXCONSTR, /* ADD index-based constraints */
+ AT_PASS_ADD_INDEX, /* ADD indexes */
+ AT_PASS_ADD_OTHERCONSTR, /* ADD other constraints, defaults */
+ AT_PASS_MISC, /* other stuff */
+
+ AT_NUM_PASSES, /* must be last */
+} AlteredTablePass;
typedef struct AlteredTableInfo
{
@@ -404,7 +408,7 @@ static void ATExecCmd(List **wqueue, AlteredTableInfo *tab,
static AlterTableCmd *ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab,
Relation rel, AlterTableCmd *cmd,
bool recurse, LOCKMODE lockmode,
- int cur_pass,
+ AlteredTablePass cur_pass,
AlterTableUtilityContext *context);
static void ATRewriteTables(AlterTableStmt *parsetree,
List **wqueue, LOCKMODE lockmode,
@@ -4739,7 +4743,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
AlterTableUtilityContext *context)
{
AlteredTableInfo *tab;
- int pass = AT_PASS_UNSET;
+ AlteredTablePass pass = AT_PASS_UNSET;
/* Find or create work queue entry for this table */
tab = ATGetQueueEntry(wqueue, rel);
@@ -5513,7 +5517,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,
static AlterTableCmd *
ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode,
- int cur_pass, AlterTableUtilityContext *context)
+ AlteredTablePass cur_pass, AlterTableUtilityContext *context)
{
AlterTableCmd *newcmd = NULL;
AlterTableStmt *atstmt = makeNode(AlterTableStmt);
@@ -5551,7 +5555,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
foreach(lc, atstmt->cmds)
{
AlterTableCmd *cmd2 = lfirst_node(AlterTableCmd, lc);
- int pass;
+ AlteredTablePass pass;
/*
* This switch need only cover the subcommand types that can be added
--
2.18.0