refactor-without-flag_patch

application/octet-stream

Filename: refactor-without-flag_patch
Type: application/octet-stream
Part: 0
Message: RE: Added schema level support for publication.
From 4cf251ee52ee61019fbdf34d968c6bc6405936ec Mon Sep 17 00:00:00 2001
From: "houzj.fnst" <houzj.fnst@cn.fujitsu.com>
Date: Fri, 10 Sep 2021 13:35:17 +0800
Subject: [PATCH] refactor-without-flag

---
 src/backend/commands/publicationcmds.c | 38 ++++++++++++-------
 src/backend/parser/gram.y              | 67 ++++++++++++++--------------------
 src/include/nodes/parsenodes.h         |  8 ++--
 3 files changed, 55 insertions(+), 58 deletions(-)

diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index c3f0a0d..9458b2c 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -165,7 +165,10 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
 
 	foreach(cell, pubobjspec_list)
 	{
+		Node *node;
+
 		pubobj = (PublicationObjSpec *) lfirst(cell);
+		node = (Node *) pubobj->object;
 
 		if (pubobj->pubobjtype == PUBLICATIONOBJ_UNKNOWN)
 			pubobj->pubobjtype = prevobjtype;
@@ -174,32 +177,39 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
 
 		if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
 		{
-			RangeVar   *rel;
+			if (IsA(node, RangeVar))
+				*rels = lappend(*rels, (RangeVar *) node);
+			else if (IsA(node, List))
+			{
+				RangeVar   *rel;
 
-			rel = makeRangeVarFromNameList(pubobj->name);
-			rel->inh = pubobj->inh;
-			rel->location = pubobj->location;
-			*rels = lappend(*rels, rel);
+				rel = makeRangeVarFromNameList((List *) node);
+				rel->inh = true;
+				rel->location = pubobj->location;
+				*rels = lappend(*rels, rel);
+			}
 		}
 		else if (pubobj->pubobjtype == PUBLICATIONOBJ_REL_IN_SCHEMA)
 		{
 			Oid			schemaid;
+			List	   *name;
 			char	   *schemaname;
 
-			if (list_length(pubobj->name) > 1)
-				ereport(ERROR,
-						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("improper qualified name (too many dotted names): %s",
-								NameListToString(pubobj->name)),
-						 parser_errposition(pstate, pubobj->location)));
-
-			if (pubobj->spl_rel_type_syn)
+			if (!IsA(node, List))
 				ereport(ERROR,
 						errcode(ERRCODE_SYNTAX_ERROR),
 						errmsg("invalid schema name at or near"),
 						parser_errposition(pstate, pubobj->location));
 
-			schemaname = strVal(linitial(pubobj->name));
+			name = (List *) node;
+			if (list_length(name) > 1)
+				ereport(ERROR,
+						(errcode(ERRCODE_SYNTAX_ERROR),
+						 errmsg("improper qualified name (too many dotted names): %s",
+								NameListToString(name)),
+						 parser_errposition(pstate, pubobj->location)));
+
+			schemaname = strVal(linitial(name));
 			if (strcmp(schemaname, "CURRENT_SCHEMA") == 0)
 			{
 				List	   *search_path;
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index fb5129a..56c3e56 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -427,7 +427,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 				transform_element_list transform_type_list
 				TriggerTransitions TriggerReferencing
 				vacuum_relation_list opt_vacuum_relation_list
-				drop_option_list pub_obj_list
+				drop_option_list pub_obj_list pubobj_name
 
 %type <node>	opt_routine_body
 %type <groupclause> group_clause
@@ -518,6 +518,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %type <node>	table_ref
 %type <jexpr>	joined_table
 %type <range>	relation_expr
+%type <range>	special_relation_expr
 %type <range>	relation_expr_opt_alias
 %type <node>	tablesample_clause opt_repeatable_clause
 %type <target>	target_el set_target insert_column_item
@@ -9629,52 +9630,34 @@ CreatePublicationStmt:
 		;
 
 pubobj_expr:
-			any_name
+			pubobj_name
 				{
 					/* inheritance query, implicitly */
-					PublicationObjSpec *n = makeNode(PublicationObjSpec);
-					n->name = $1;
-					n->inh = true;
-					n->spl_rel_type_syn = false;
-					$$ = n;
-				}
-			| any_name '*'
-				{
-					/* inheritance query, explicitly */
-					PublicationObjSpec *n = makeNode(PublicationObjSpec);
-					n->name = $1;
-					n->inh = true;
-					n->spl_rel_type_syn = true;
-					$$ = n;
+					$$ = makeNode(PublicationObjSpec);
+					$$->object = $1;
 				}
-			| ONLY any_name
+			| special_relation_expr
 				{
-					/* no inheritance */
-					PublicationObjSpec *n = makeNode(PublicationObjSpec);
-					n->name = $2;
-					n->inh = false;
-					n->spl_rel_type_syn = true;
-					$$ = n;
-				}
-			| ONLY '(' any_name ')'
-				{
-					/* no inheritance, SQL99-style syntax */
-					PublicationObjSpec *n = makeNode(PublicationObjSpec);
-					n->name = $3;
-					n->inh = false;
-					n->spl_rel_type_syn = true;
-					$$ = n;
+					$$ = makeNode(PublicationObjSpec);
+					$$->object = $1;
 				}
 			| CURRENT_SCHEMA
 				{
-					PublicationObjSpec *n = makeNode(PublicationObjSpec);
-					n->name = list_make1(makeString("CURRENT_SCHEMA"));
-					n->inh = false;
-					n->spl_rel_type_syn = false;
-					$$ = n;
+					$$ = makeNode(PublicationObjSpec);
+					$$->object = list_make1(makeString("CURRENT_SCHEMA"));
 				}
 		;
 
+/*
+ * We cannot use any_name in pubobj_expr, because the dot('.') in rule attr
+ * would have a shift/reduce conflict with the dot('.') in rule indirection_el
+ * which also used in pubobj_expr. To resolve the conflicts, declare a new rule
+ * pubobj_name which directly use indirection_el.
+ */
+pubobj_name:	ColId						{ $$ = list_make1(makeString($1)); }
+			| ColId indirection				{ $$ = lcons(makeString($1), $2); }
+		;
+
 /* FOR TABLE and FOR ALL TABLES IN SCHEMA specifications */
 PublicationObjSpec:	TABLE pubobj_expr
 					{
@@ -12493,7 +12476,14 @@ relation_expr:
 					$$->inh = true;
 					$$->alias = NULL;
 				}
-			| qualified_name '*'
+			| special_relation_expr
+				{
+					$$ = $1;
+				}
+		;
+
+special_relation_expr:
+			qualified_name '*'
 				{
 					/* inheritance query, explicitly */
 					$$ = $1;
@@ -12516,7 +12506,6 @@ relation_expr:
 				}
 		;
 
-
 relation_expr_list:
 			relation_expr							{ $$ = list_make1($1); }
 			| relation_expr_list ',' relation_expr	{ $$ = lappend($1, $3); }
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 6380fa4..5ad0c31 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -355,11 +355,9 @@ typedef struct PublicationObjSpec
 {
 	NodeTag		type;
 	PublicationObjSpecType pubobjtype;	/* type of this publication object */
-	List	   *name;			/* publication object name */
-	bool		inh;			/* expand rel by inheritance? recursively act
-								 * on children? */
-	bool		spl_rel_type_syn;	/* true if it is special relation type
-									 * syntax */
+	void	   *object;			/* publication object could be:
+								   RangeVar - table object
+								   List		- tablename or schemaname */
 	int			location;		/* token location, or -1 if unknown */
 } PublicationObjSpec;
 
-- 
2.7.2.windows.1