v46-0005-Skip-ALTER-TABLE-subcommands-generated-for.patch

application/octet-stream

Filename: v46-0005-Skip-ALTER-TABLE-subcommands-generated-for.patch
Type: application/octet-stream
Part: 4
Message: Re: Support logical replication of DDLs

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 v46-0005
Subject: Skip ALTER TABLE subcommands generated for TableLikeClause in the DDL deparser to avoid duplicated subcommands.
File+
src/backend/commands/ddl_deparse.c 10 0
src/backend/parser/parse_utilcmd.c 1 0
src/include/nodes/parsenodes.h 1 0
From 8b0b6e77443178784ade76fefbeca81cb0f56f4e Mon Sep 17 00:00:00 2001
From: Ajin Cherian <ajinc@fast.au.fujitsu.com>
Date: Mon, 12 Dec 2022 04:29:37 -0500
Subject: [PATCH v46 5/6] Skip ALTER TABLE subcommands generated for 
 TableLikeClause in the DDL deparser to avoid duplicated subcommands.

---
 src/backend/commands/ddl_deparse.c | 10 ++++++++++
 src/backend/parser/parse_utilcmd.c |  1 +
 src/include/nodes/parsenodes.h     |  1 +
 3 files changed, 12 insertions(+)

diff --git a/src/backend/commands/ddl_deparse.c b/src/backend/commands/ddl_deparse.c
index 74630a4..0c6c7d9 100755
--- a/src/backend/commands/ddl_deparse.c
+++ b/src/backend/commands/ddl_deparse.c
@@ -3387,8 +3387,18 @@ deparse_AlterRelation(CollectedCommand *cmd)
 	bool		istable = false;
 	List	   *exprs = NIL;
 	Oid			relId = cmd->d.alterTable.objectId;
+	AlterTableStmt *stmt = NULL;
 
 	Assert(cmd->type == SCT_AlterTable);
+	stmt = (AlterTableStmt *) cmd->parsetree;
+	Assert(IsA(stmt, AlterTableStmt));
+
+	/*
+	 * ALTER TABLE subcommands generated for TableLikeClause is processed in
+	 * the top level CREATE TABLE command; return empty here.
+	 */
+	if (stmt->table_like)
+		return NULL;
 
 	rel = relation_open(relId, AccessShareLock);
 	dpcontext = deparse_context_for(RelationGetRelationName(rel),
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 342a179..ec54cb5 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -1397,6 +1397,7 @@ expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
 		atcmd->cmds = atsubcmds;
 		atcmd->objtype = OBJECT_TABLE;
 		atcmd->missing_ok = false;
+		atcmd->table_like = true;
 		result = lcons(atcmd, result);
 	}
 
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 8fe9b2f..0aece9f 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -1974,6 +1974,7 @@ typedef struct AlterTableStmt
 	List	   *cmds;			/* list of subcommands */
 	ObjectType	objtype;		/* type of object */
 	bool		missing_ok;		/* skip error if table missing */
+	bool        table_like;		/* internally generated for TableLikeClause */
 } AlterTableStmt;
 
 typedef enum AlterTableType
-- 
1.8.3.1