From 55b95be987d0969c7346f23afa0d1b7ad290140e Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Mon, 19 Jan 2026 14:55:16 +0800
Subject: [PATCH v1 2/2] tablecmds: simplify propagation of no_only flag

Several ALTER TABLE preparation paths conditionally copied the no_only
flag using:

    if (no_only)
        cmd->no_only = true;

This pattern is redundant and obscures the fact that cmd->no_only is
meant to directly reflect the parsed ONLY semantics.

Assign cmd->no_only unconditionally instead:

    cmd->no_only = no_only;

This is a mechanical cleanup with no behavior change.

Author: Chao Li <lic@highgo.com>
---
 src/backend/commands/tablecmds.c | 33 +++++++++++---------------------
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 4000fd0c923..11f292a8c36 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -4990,8 +4990,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
 								ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_VIEW |
 								ATT_FOREIGN_TABLE);
 			/* Set up recursion for phase 2; no other prep needed */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			pass = AT_PASS_ADD_OTHERCONSTR;
 			break;
 		case AT_SetIdentity:
@@ -4999,8 +4998,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
 								ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_VIEW |
 								ATT_FOREIGN_TABLE);
 			/* Set up recursion for phase 2; no other prep needed */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			/* This should run after AddIdentity, so do it in MISC pass */
 			pass = AT_PASS_MISC;
 			break;
@@ -5009,24 +5007,21 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
 								ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_VIEW |
 								ATT_FOREIGN_TABLE);
 			/* Set up recursion for phase 2; no other prep needed */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			pass = AT_PASS_DROP;
 			break;
 		case AT_DropNotNull:	/* ALTER COLUMN DROP NOT NULL */
 			ATSimplePermissions(cmd->subtype, rel,
 								ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_FOREIGN_TABLE);
 			/* Set up recursion for phase 2; no other prep needed */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			pass = AT_PASS_DROP;
 			break;
 		case AT_SetNotNull:		/* ALTER COLUMN SET NOT NULL */
 			ATSimplePermissions(cmd->subtype, rel,
 								ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_FOREIGN_TABLE);
 			/* Set up recursion for phase 2; no other prep needed */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			pass = AT_PASS_COL_ATTRS;
 			break;
 		case AT_SetExpression:	/* ALTER COLUMN SET EXPRESSION */
@@ -5112,8 +5107,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
 			ATCheckPartitionsNotInUse(rel, lockmode);
 			/* Other recursion occurs during execution phase */
 			/* No command-specific prep needed except saving recurse flag */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			pass = AT_PASS_DROP;
 			break;
 		case AT_AlterColumnType:	/* ALTER COLUMN TYPE */
@@ -5211,8 +5205,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
 			ATSimplePermissions(cmd->subtype, rel,
 								ATT_TABLE | ATT_PARTITIONED_TABLE);
 			/* Recursion occurs during execution phase */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			pass = AT_PASS_MISC;
 			break;
 		case AT_ValidateConstraint: /* VALIDATE CONSTRAINT */
@@ -5220,8 +5213,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
 								ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_FOREIGN_TABLE);
 			/* Recursion occurs during execution phase */
 			/* No command-specific prep needed except saving recurse flag */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			pass = AT_PASS_MISC;
 			break;
 		case AT_ReplicaIdentity:	/* REPLICA IDENTITY ... */
@@ -5242,8 +5234,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
 			ATSimplePermissions(cmd->subtype, rel,
 								ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_FOREIGN_TABLE);
 			/* Set up recursion for phase 2; no other prep needed */
-			if (no_only)
-				cmd->no_only = true;
+			cmd->no_only = no_only;
 			pass = AT_PASS_MISC;
 			break;
 		case AT_EnableRule:		/* ENABLE/DISABLE RULE variants */
@@ -5796,8 +5787,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
 				break;
 			case AT_AddConstraint:
 				/* Recursion occurs during execution phase */
-				if (no_only)
-					cmd2->no_only = true;
+				cmd2->no_only = no_only;
 				switch (castNode(Constraint, cmd2->def)->contype)
 				{
 					case CONSTR_NOTNULL:
@@ -9295,8 +9285,7 @@ ATPrepDropColumn(List **wqueue, Relation rel, bool no_only, bool recursing,
 	if (rel->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
 		ATTypedTableRecursion(wqueue, rel, cmd, lockmode, context);
 
-	if (no_only)
-		cmd->no_only = true;
+	cmd->no_only = no_only;
 }
 
 /*
-- 
2.39.5 (Apple Git-154)

