]> granicus.if.org Git - postgresql/commitdiff
Reformat code in ATPostAlterTypeParse.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 14 Jul 2015 08:38:08 +0000 (11:38 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 14 Jul 2015 08:38:08 +0000 (11:38 +0300)
The code in ATPostAlterTypeParse was very deeply indented, mostly because
there were two nested switch-case statements, which add a lot of
indentation. Use if-else blocks instead, to make the code less indented
and more readable.

This is in preparation for next patch that makes some actualy changes to
the function. These cosmetic parts have been separated to make it easier
to see the real changes in the other patch.

src/backend/commands/tablecmds.c

index d3947139c07d58276176ea421ca3e8ac3e8a764c..e7b23f1621cd3a901b3b8209ec1ea10ac0a00485 100644 (file)
@@ -8645,69 +8645,67 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
                Node       *stm = (Node *) lfirst(list_item);
                AlteredTableInfo *tab;
 
-               switch (nodeTag(stm))
+               tab = ATGetQueueEntry(wqueue, rel);
+
+               if (IsA(stm, IndexStmt))
+               {
+                       IndexStmt  *stmt = (IndexStmt *) stm;
+                       AlterTableCmd *newcmd;
+
+                       if (!rewrite)
+                               TryReuseIndex(oldId, stmt);
+
+                       newcmd = makeNode(AlterTableCmd);
+                       newcmd->subtype = AT_ReAddIndex;
+                       newcmd->def = (Node *) stmt;
+                       tab->subcmds[AT_PASS_OLD_INDEX] =
+                               lappend(tab->subcmds[AT_PASS_OLD_INDEX], newcmd);
+               }
+               else if (IsA(stm, AlterTableStmt))
                {
-                       case T_IndexStmt:
+                       AlterTableStmt *stmt = (AlterTableStmt *) stm;
+                       ListCell   *lcmd;
+
+                       foreach(lcmd, stmt->cmds)
+                       {
+                               AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
+
+                               if (cmd->subtype == AT_AddIndex)
                                {
-                                       IndexStmt  *stmt = (IndexStmt *) stm;
-                                       AlterTableCmd *newcmd;
+                                       Assert(IsA(cmd->def, IndexStmt));
 
                                        if (!rewrite)
-                                               TryReuseIndex(oldId, stmt);
+                                               TryReuseIndex(get_constraint_index(oldId),
+                                                                         (IndexStmt *) cmd->def);
 
-                                       tab = ATGetQueueEntry(wqueue, rel);
-                                       newcmd = makeNode(AlterTableCmd);
-                                       newcmd->subtype = AT_ReAddIndex;
-                                       newcmd->def = (Node *) stmt;
+                                       cmd->subtype = AT_ReAddIndex;
                                        tab->subcmds[AT_PASS_OLD_INDEX] =
-                                               lappend(tab->subcmds[AT_PASS_OLD_INDEX], newcmd);
-                                       break;
+                                               lappend(tab->subcmds[AT_PASS_OLD_INDEX], cmd);
                                }
-                       case T_AlterTableStmt:
+                               else if (cmd->subtype == AT_AddConstraint)
                                {
-                                       AlterTableStmt *stmt = (AlterTableStmt *) stm;
-                                       ListCell   *lcmd;
-
-                                       tab = ATGetQueueEntry(wqueue, rel);
-                                       foreach(lcmd, stmt->cmds)
-                                       {
-                                               AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
-                                               Constraint *con;
-
-                                               switch (cmd->subtype)
-                                               {
-                                                       case AT_AddIndex:
-                                                               Assert(IsA(cmd->def, IndexStmt));
-                                                               if (!rewrite)
-                                                                       TryReuseIndex(get_constraint_index(oldId),
-                                                                                                 (IndexStmt *) cmd->def);
-                                                               cmd->subtype = AT_ReAddIndex;
-                                                               tab->subcmds[AT_PASS_OLD_INDEX] =
-                                                                       lappend(tab->subcmds[AT_PASS_OLD_INDEX], cmd);
-                                                               break;
-                                                       case AT_AddConstraint:
-                                                               Assert(IsA(cmd->def, Constraint));
-                                                               con = (Constraint *) cmd->def;
-                                                               con->old_pktable_oid = refRelId;
-                                                               /* rewriting neither side of a FK */
-                                                               if (con->contype == CONSTR_FOREIGN &&
-                                                                       !rewrite && tab->rewrite == 0)
-                                                                       TryReuseForeignKey(oldId, con);
-                                                               cmd->subtype = AT_ReAddConstraint;
-                                                               tab->subcmds[AT_PASS_OLD_CONSTR] =
-                                                                       lappend(tab->subcmds[AT_PASS_OLD_CONSTR], cmd);
-                                                               break;
-                                                       default:
-                                                               elog(ERROR, "unexpected statement type: %d",
-                                                                        (int) cmd->subtype);
-                                               }
-                                       }
-                                       break;
+                                       Constraint *con;
+
+                                       Assert(IsA(cmd->def, Constraint));
+
+                                       con = (Constraint *) cmd->def;
+                                       con->old_pktable_oid = refRelId;
+                                       /* rewriting neither side of a FK */
+                                       if (con->contype == CONSTR_FOREIGN &&
+                                               !rewrite && tab->rewrite == 0)
+                                               TryReuseForeignKey(oldId, con);
+                                       cmd->subtype = AT_ReAddConstraint;
+                                       tab->subcmds[AT_PASS_OLD_CONSTR] =
+                                               lappend(tab->subcmds[AT_PASS_OLD_CONSTR], cmd);
                                }
-                       default:
-                               elog(ERROR, "unexpected statement type: %d",
-                                        (int) nodeTag(stm));
+                               else
+                                       elog(ERROR, "unexpected statement type: %d",
+                                                (int) cmd->subtype);
+                       }
                }
+               else
+                       elog(ERROR, "unexpected statement type: %d",
+                                (int) nodeTag(stm));
        }
 
        relation_close(rel, NoLock);