Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1odpPT-0005D5-Cr for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Sep 2022 09:00:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1odpPS-0002bS-9B for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Sep 2022 09:00:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1odpPR-0002bJ-50 for pgsql-hackers@lists.postgresql.org; Thu, 29 Sep 2022 09:00:45 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1odpPN-0001jx-60 for pgsql-hackers@lists.postgresql.org; Thu, 29 Sep 2022 09:00:44 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 2597A5C00B6 for ; Thu, 29 Sep 2022 05:00:37 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 29 Sep 2022 05:00:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1664442037; x=1664528437; bh=/k8PBi1swh4c0VtLssHEkhp8JFRz fKIjgfFFD/cbsSI=; b=D0m98TIRy6ucm7v3djHcP5pVyDTWsfrNj6K5bCq3s2yT Ak6RCKh5fRJNCcLOiz1qZ/5bO5CrLq/s29hbc43WdPwxjFBHWKpDVF67Tq2WKSQw EUN7GSoLUq6+7/tWdjefgJciWJ6CRQWOfq6qEEdmiQaKQ+dANfbvSJ826mhnG6+3 4PVPCaTqdjckyEkwklDWjDB+R5oTdlXCcNF7x+KJu2mrOVoFBosdYDDtwG6XeNEI +RzlVf072Og4yJOETedRdGbqIpfe5E8BPGLbr1ICL6dexmNGCn65Vng/6tEx5FXA nfAHlmsE+ACqAhbw388fGokfYxbIRaa7C2aYZzBEIQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeehtddguddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfesmhekreertddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepteelfeejkeethfffgeeiuddtvdfhfefgveehudehleefhefg veelgeeggeethfelnecuffhomhgrihhnpehpohhsthhgrhdrvghspdgvnhhtvghrphhrih hsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 29 Sep 2022 05:00:36 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 9C5485E; Thu, 29 Sep 2022 11:00:33 +0200 (CEST) Date: Thu, 29 Sep 2022 11:00:33 +0200 From: Alvaro Herrera To: Pg Hackers Subject: do away with ALTER TABLE "Recurse" subcmd types Message-ID: <20220929090033.zxuaezcdwh2fgfjb@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="rd5zzqce5m4nys5h" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --rd5zzqce5m4nys5h Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit I already mentioned this in [1]: we can remove a few subcmd types that were added to support exec-time recursion, by keeping a separate flag for it. We're already doing that for alter trigger operations, so this patch just extends that to the other subcommand types that need it. There's no visible change, just some code simplification. [1] https://postgr.es/m/20220729184452.2i4xcru3lzey76m6@alvherre.pgsql -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "All rings of power are equal, But some rings of power are more equal than others." (George Orwell's The Lord of the Rings) --rd5zzqce5m4nys5h Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-do-away-with-AT_AddColumnRecurse.patch" From 8c36176feeb47f4a4889b0af0800fcf316a58408 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 3 Aug 2022 19:53:12 +0200 Subject: [PATCH] do away with AT_AddColumnRecurse --- src/backend/commands/tablecmds.c | 67 ++++--------------- src/backend/parser/parse_utilcmd.c | 2 - src/include/nodes/parsenodes.h | 5 -- .../test_ddl_deparse/test_ddl_deparse.c | 20 ++---- 4 files changed, 17 insertions(+), 77 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7d8a75d23c..60a4663fd1 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -4069,8 +4069,7 @@ AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode) * For most subcommand types, phases 2 and 3 do no explicit recursion, * since phase 1 already does it. However, for certain subcommand types * it is only possible to determine how to recurse at phase 2 time; for - * those cases, phase 1 sets the cmd->recurse flag (or, in some older coding, - * changes the command subtype of a "Recurse" variant XXX to be cleaned up.) + * those cases, phase 1 sets the cmd->recurse flag. * * Thanks to the magic of MVCC, an error anywhere along the way rolls back * the whole operation; we don't have to do anything special to clean up. @@ -4275,7 +4274,6 @@ AlterTableGetLockLevel(List *cmds) break; case AT_AddConstraint: - case AT_AddConstraintRecurse: /* becomes AT_AddConstraint */ case AT_ReAddConstraint: /* becomes AT_AddConstraint */ case AT_ReAddDomainConstraint: /* becomes AT_AddConstraint */ if (IsA(cmd->def, Constraint)) @@ -4627,7 +4625,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, /* Recursion occurs during execution phase */ /* No command-specific prep needed except saving recurse flag */ if (recurse) - cmd->subtype = AT_AddConstraintRecurse; + cmd->recurse = true; pass = AT_PASS_ADD_CONSTR; break; case AT_AddIndexConstraint: /* ADD CONSTRAINT USING INDEX */ @@ -4642,7 +4640,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, /* Other recursion occurs during execution phase */ /* No command-specific prep needed except saving recurse flag */ if (recurse) - cmd->subtype = AT_DropConstraintRecurse; + cmd->recurse = true; pass = AT_PASS_DROP; break; case AT_AlterColumnType: /* ALTER COLUMN TYPE */ @@ -4764,7 +4762,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, /* Recursion occurs during execution phase */ /* No command-specific prep needed except saving recurse flag */ if (recurse) - cmd->subtype = AT_ValidateConstraintRecurse; + cmd->recurse = true; pass = AT_PASS_MISC; break; case AT_ReplicaIdentity: /* REPLICA IDENTITY ... */ @@ -4929,12 +4927,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, case AT_AddColumn: /* ADD COLUMN */ case AT_AddColumnToView: /* add column via CREATE OR REPLACE VIEW */ address = ATExecAddColumn(wqueue, tab, rel, &cmd, - false, false, - lockmode, cur_pass, context); - break; - case AT_AddColumnRecurse: - address = ATExecAddColumn(wqueue, tab, rel, &cmd, - true, false, + cmd->recurse, false, lockmode, cur_pass, context); break; case AT_ColumnDefault: /* ALTER COLUMN DEFAULT */ @@ -4988,13 +4981,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, break; case AT_DropColumn: /* DROP COLUMN */ address = ATExecDropColumn(wqueue, rel, cmd->name, - cmd->behavior, false, false, - cmd->missing_ok, lockmode, - NULL); - break; - case AT_DropColumnRecurse: /* DROP COLUMN with recursion */ - address = ATExecDropColumn(wqueue, rel, cmd->name, - cmd->behavior, true, false, + cmd->behavior, cmd->recurse, false, cmd->missing_ok, lockmode, NULL); break; @@ -5014,27 +5001,14 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, /* Transform the command only during initial examination */ if (cur_pass == AT_PASS_ADD_CONSTR) cmd = ATParseTransformCmd(wqueue, tab, rel, cmd, - false, lockmode, + cmd->recurse, lockmode, cur_pass, context); /* Depending on constraint type, might be no more work to do now */ if (cmd != NULL) address = ATExecAddConstraint(wqueue, tab, rel, (Constraint *) cmd->def, - false, false, lockmode); - break; - case AT_AddConstraintRecurse: /* ADD CONSTRAINT with recursion */ - /* Transform the command only during initial examination */ - if (cur_pass == AT_PASS_ADD_CONSTR) - cmd = ATParseTransformCmd(wqueue, tab, rel, cmd, - true, lockmode, - cur_pass, context); - /* Depending on constraint type, might be no more work to do now */ - if (cmd != NULL) - address = - ATExecAddConstraint(wqueue, tab, rel, - (Constraint *) cmd->def, - true, false, lockmode); + cmd->recurse, false, lockmode); break; case AT_ReAddConstraint: /* Re-add pre-existing check constraint */ address = @@ -5059,22 +5033,12 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, address = ATExecAlterConstraint(rel, cmd, false, false, lockmode); break; case AT_ValidateConstraint: /* VALIDATE CONSTRAINT */ - address = ATExecValidateConstraint(wqueue, rel, cmd->name, false, - false, lockmode); - break; - case AT_ValidateConstraintRecurse: /* VALIDATE CONSTRAINT with - * recursion */ - address = ATExecValidateConstraint(wqueue, rel, cmd->name, true, + address = ATExecValidateConstraint(wqueue, rel, cmd->name, cmd->recurse, false, lockmode); break; case AT_DropConstraint: /* DROP CONSTRAINT */ ATExecDropConstraint(rel, cmd->name, cmd->behavior, - false, false, - cmd->missing_ok, lockmode); - break; - case AT_DropConstraintRecurse: /* DROP CONSTRAINT with recursion */ - ATExecDropConstraint(rel, cmd->name, cmd->behavior, - true, false, + cmd->recurse, false, cmd->missing_ok, lockmode); break; case AT_AlterColumnType: /* ALTER COLUMN TYPE */ @@ -5350,7 +5314,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, case AT_AddConstraint: /* Recursion occurs during execution phase */ if (recurse) - cmd2->subtype = AT_AddConstraintRecurse; + cmd2->recurse = true; switch (castNode(Constraint, cmd2->def)->contype) { case CONSTR_PRIMARY: @@ -6109,7 +6073,6 @@ alter_table_type_to_string(AlterTableType cmdtype) switch (cmdtype) { case AT_AddColumn: - case AT_AddColumnRecurse: case AT_AddColumnToView: return "ADD COLUMN"; case AT_ColumnDefault: @@ -6134,13 +6097,11 @@ alter_table_type_to_string(AlterTableType cmdtype) case AT_SetCompression: return "ALTER COLUMN ... SET COMPRESSION"; case AT_DropColumn: - case AT_DropColumnRecurse: return "DROP COLUMN"; case AT_AddIndex: case AT_ReAddIndex: return NULL; /* not real grammar */ case AT_AddConstraint: - case AT_AddConstraintRecurse: case AT_ReAddConstraint: case AT_ReAddDomainConstraint: case AT_AddIndexConstraint: @@ -6148,10 +6109,8 @@ alter_table_type_to_string(AlterTableType cmdtype) case AT_AlterConstraint: return "ALTER CONSTRAINT"; case AT_ValidateConstraint: - case AT_ValidateConstraintRecurse: return "VALIDATE CONSTRAINT"; case AT_DropConstraint: - case AT_DropConstraintRecurse: return "DROP CONSTRAINT"; case AT_ReAddComment: return NULL; /* not real grammar */ @@ -6670,7 +6629,7 @@ ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing, ATTypedTableRecursion(wqueue, rel, cmd, lockmode, context); if (recurse && !is_view) - cmd->subtype = AT_AddColumnRecurse; + cmd->recurse = true; } /* @@ -8375,7 +8334,7 @@ ATPrepDropColumn(List **wqueue, Relation rel, bool recurse, bool recursing, ATTypedTableRecursion(wqueue, rel, cmd, lockmode, context); if (recurse) - cmd->subtype = AT_DropColumnRecurse; + cmd->recurse = true; } /* diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index bd068bba05..073dc55370 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3365,7 +3365,6 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, switch (cmd->subtype) { case AT_AddColumn: - case AT_AddColumnRecurse: { ColumnDef *def = castNode(ColumnDef, cmd->def); @@ -3389,7 +3388,6 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, } case AT_AddConstraint: - case AT_AddConstraintRecurse: /* * The original AddConstraint cmd node doesn't go to newcmds diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 633e7671b3..c025597273 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1950,7 +1950,6 @@ typedef struct AlterTableStmt typedef enum AlterTableType { AT_AddColumn, /* add column */ - AT_AddColumnRecurse, /* internal to commands/tablecmds.c */ AT_AddColumnToView, /* implicitly via CREATE OR REPLACE VIEW */ AT_ColumnDefault, /* alter column default */ AT_CookedColumnDefault, /* add a pre-cooked column default */ @@ -1964,19 +1963,15 @@ typedef enum AlterTableType AT_SetStorage, /* alter column set storage */ AT_SetCompression, /* alter column set compression */ AT_DropColumn, /* drop column */ - AT_DropColumnRecurse, /* internal to commands/tablecmds.c */ AT_AddIndex, /* add index */ AT_ReAddIndex, /* internal to commands/tablecmds.c */ AT_AddConstraint, /* add constraint */ - AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */ AT_ReAddConstraint, /* internal to commands/tablecmds.c */ AT_ReAddDomainConstraint, /* internal to commands/tablecmds.c */ AT_AlterConstraint, /* alter constraint */ AT_ValidateConstraint, /* validate constraint */ - AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */ AT_AddIndexConstraint, /* add constraint using existing index */ AT_DropConstraint, /* drop constraint */ - AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */ AT_ReAddComment, /* internal to commands/tablecmds.c */ AT_AlterColumnType, /* alter column type */ AT_AlterColumnGenericOptions, /* alter column OPTIONS (...) */ diff --git a/src/test/modules/test_ddl_deparse/test_ddl_deparse.c b/src/test/modules/test_ddl_deparse/test_ddl_deparse.c index 133594999b..52546bca28 100644 --- a/src/test/modules/test_ddl_deparse/test_ddl_deparse.c +++ b/src/test/modules/test_ddl_deparse/test_ddl_deparse.c @@ -114,9 +114,6 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_AddColumn: strtype = "ADD COLUMN"; break; - case AT_AddColumnRecurse: - strtype = "ADD COLUMN (and recurse)"; - break; case AT_AddColumnToView: strtype = "ADD COLUMN TO VIEW"; break; @@ -156,9 +153,6 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_DropColumn: strtype = "DROP COLUMN"; break; - case AT_DropColumnRecurse: - strtype = "DROP COLUMN (and recurse)"; - break; case AT_AddIndex: strtype = "ADD INDEX"; break; @@ -168,9 +162,6 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_AddConstraint: strtype = "ADD CONSTRAINT"; break; - case AT_AddConstraintRecurse: - strtype = "ADD CONSTRAINT (and recurse)"; - break; case AT_ReAddConstraint: strtype = "(re) ADD CONSTRAINT"; break; @@ -183,18 +174,12 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_ValidateConstraint: strtype = "VALIDATE CONSTRAINT"; break; - case AT_ValidateConstraintRecurse: - strtype = "VALIDATE CONSTRAINT (and recurse)"; - break; case AT_AddIndexConstraint: strtype = "ADD CONSTRAINT (using index)"; break; case AT_DropConstraint: strtype = "DROP CONSTRAINT"; break; - case AT_DropConstraintRecurse: - strtype = "DROP CONSTRAINT (and recurse)"; - break; case AT_ReAddComment: strtype = "(re) ADD COMMENT"; break; @@ -326,7 +311,10 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) break; } - values[0] = CStringGetTextDatum(strtype); + if (subcmd->recurse) + values[0] = CStringGetTextDatum(psprintf("%s (and recurse)", strtype)); + else + values[0] = CStringGetTextDatum(strtype); if (OidIsValid(sub->address.objectId)) { char *objdesc; -- 2.30.2 --rd5zzqce5m4nys5h--