Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1ab9faa

Browse files
committed
Reformat code in ATPostAlterTypeParse.
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.
1 parent 716f97f commit 1ab9faa

File tree

1 file changed

+51
-53
lines changed

1 file changed

+51
-53
lines changed

src/backend/commands/tablecmds.c

+51-53
Original file line numberDiff line numberDiff line change
@@ -8645,69 +8645,67 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
86458645
Node *stm = (Node *) lfirst(list_item);
86468646
AlteredTableInfo *tab;
86478647

8648-
switch (nodeTag(stm))
8648+
tab = ATGetQueueEntry(wqueue, rel);
8649+
8650+
if (IsA(stm, IndexStmt))
8651+
{
8652+
IndexStmt *stmt = (IndexStmt *) stm;
8653+
AlterTableCmd *newcmd;
8654+
8655+
if (!rewrite)
8656+
TryReuseIndex(oldId, stmt);
8657+
8658+
newcmd = makeNode(AlterTableCmd);
8659+
newcmd->subtype = AT_ReAddIndex;
8660+
newcmd->def = (Node *) stmt;
8661+
tab->subcmds[AT_PASS_OLD_INDEX] =
8662+
lappend(tab->subcmds[AT_PASS_OLD_INDEX], newcmd);
8663+
}
8664+
else if (IsA(stm, AlterTableStmt))
86498665
{
8650-
case T_IndexStmt:
8666+
AlterTableStmt *stmt = (AlterTableStmt *) stm;
8667+
ListCell *lcmd;
8668+
8669+
foreach(lcmd, stmt->cmds)
8670+
{
8671+
AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
8672+
8673+
if (cmd->subtype == AT_AddIndex)
86518674
{
8652-
IndexStmt *stmt = (IndexStmt *) stm;
8653-
AlterTableCmd *newcmd;
8675+
Assert(IsA(cmd->def, IndexStmt));
86548676

86558677
if (!rewrite)
8656-
TryReuseIndex(oldId, stmt);
8678+
TryReuseIndex(get_constraint_index(oldId),
8679+
(IndexStmt *) cmd->def);
86578680

8658-
tab = ATGetQueueEntry(wqueue, rel);
8659-
newcmd = makeNode(AlterTableCmd);
8660-
newcmd->subtype = AT_ReAddIndex;
8661-
newcmd->def = (Node *) stmt;
8681+
cmd->subtype = AT_ReAddIndex;
86628682
tab->subcmds[AT_PASS_OLD_INDEX] =
8663-
lappend(tab->subcmds[AT_PASS_OLD_INDEX], newcmd);
8664-
break;
8683+
lappend(tab->subcmds[AT_PASS_OLD_INDEX], cmd);
86658684
}
8666-
case T_AlterTableStmt:
8685+
else if (cmd->subtype == AT_AddConstraint)
86678686
{
8668-
AlterTableStmt *stmt = (AlterTableStmt *) stm;
8669-
ListCell *lcmd;
8670-
8671-
tab = ATGetQueueEntry(wqueue, rel);
8672-
foreach(lcmd, stmt->cmds)
8673-
{
8674-
AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
8675-
Constraint *con;
8676-
8677-
switch (cmd->subtype)
8678-
{
8679-
case AT_AddIndex:
8680-
Assert(IsA(cmd->def, IndexStmt));
8681-
if (!rewrite)
8682-
TryReuseIndex(get_constraint_index(oldId),
8683-
(IndexStmt *) cmd->def);
8684-
cmd->subtype = AT_ReAddIndex;
8685-
tab->subcmds[AT_PASS_OLD_INDEX] =
8686-
lappend(tab->subcmds[AT_PASS_OLD_INDEX], cmd);
8687-
break;
8688-
case AT_AddConstraint:
8689-
Assert(IsA(cmd->def, Constraint));
8690-
con = (Constraint *) cmd->def;
8691-
con->old_pktable_oid = refRelId;
8692-
/* rewriting neither side of a FK */
8693-
if (con->contype == CONSTR_FOREIGN &&
8694-
!rewrite && tab->rewrite == 0)
8695-
TryReuseForeignKey(oldId, con);
8696-
cmd->subtype = AT_ReAddConstraint;
8697-
tab->subcmds[AT_PASS_OLD_CONSTR] =
8698-
lappend(tab->subcmds[AT_PASS_OLD_CONSTR], cmd);
8699-
break;
8700-
default:
8701-
elog(ERROR, "unexpected statement type: %d",
8702-
(int) cmd->subtype);
8703-
}
8704-
}
8705-
break;
8687+
Constraint *con;
8688+
8689+
Assert(IsA(cmd->def, Constraint));
8690+
8691+
con = (Constraint *) cmd->def;
8692+
con->old_pktable_oid = refRelId;
8693+
/* rewriting neither side of a FK */
8694+
if (con->contype == CONSTR_FOREIGN &&
8695+
!rewrite && tab->rewrite == 0)
8696+
TryReuseForeignKey(oldId, con);
8697+
cmd->subtype = AT_ReAddConstraint;
8698+
tab->subcmds[AT_PASS_OLD_CONSTR] =
8699+
lappend(tab->subcmds[AT_PASS_OLD_CONSTR], cmd);
87068700
}
8707-
default:
8708-
elog(ERROR, "unexpected statement type: %d",
8709-
(int) nodeTag(stm));
8701+
else
8702+
elog(ERROR, "unexpected statement type: %d",
8703+
(int) cmd->subtype);
8704+
}
87108705
}
8706+
else
8707+
elog(ERROR, "unexpected statement type: %d",
8708+
(int) nodeTag(stm));
87118709
}
87128710

87138711
relation_close(rel, NoLock);

0 commit comments

Comments
 (0)