refactor-with-flag_patch
application/octet-stream
Filename: refactor-with-flag_patch
Type: application/octet-stream
Part: 0
From 3ba0b5633f283b69d43846fba814c922df3ba16d Mon Sep 17 00:00:00 2001
From: "houzj.fnst" <houzj.fnst@fujitsu.com>
Date: Fri, 10 Sep 2021 10:10:19 +0800
Subject: [PATCH] refactor
---
src/backend/commands/publicationcmds.c | 41 +++++++++------
src/backend/parser/gram.y | 69 +++++++++++---------------
src/include/nodes/parsenodes.h | 20 +++++---
3 files changed, 65 insertions(+), 65 deletions(-)
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index c3f0a0d9bb..81c7aaeee8 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -172,34 +172,43 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
else
prevobjtype = pubobj->pubobjtype;
- if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
+ if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_LIST)
{
- RangeVar *rel;
+ if (pubobj->targettype == TARGETOBJ_TABLE)
+ *rels = lappend(*rels, (RangeVar *) pubobj->object);
+ else
+ {
+ RangeVar *rel;
- rel = makeRangeVarFromNameList(pubobj->name);
- rel->inh = pubobj->inh;
- rel->location = pubobj->location;
- *rels = lappend(*rels, rel);
+ rel = makeRangeVarFromNameList((List *) pubobj->object);
+ rel->inh = true;
+ rel->location = pubobj->location;
+ *rels = lappend(*rels, rel);
+ }
}
- else if (pubobj->pubobjtype == PUBLICATIONOBJ_REL_IN_SCHEMA)
+ else if (pubobj->pubobjtype == PUBLICATIONOBJ_SCHEMA_LIST)
{
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 (pubobj->targettype == TARGETOBJ_SCHEMA ||
+ pubobj->targettype == TARGETOBJ_UNKNOWN)
+ name = (List *) pubobj->object;
+ else
ereport(ERROR,
errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid schema name at or near"),
parser_errposition(pstate, pubobj->location));
- schemaname = strVal(linitial(pubobj->name));
+ 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 fb5129af74..0b0522e3dd 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,64 +9630,44 @@ 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;
+ $$ = makeNode(PublicationObjSpec);
+ $$->targettype = TARGETOBJ_UNKNOWN;
+ $$->object = $1;
}
- | any_name '*'
+ | special_relation_expr
{
- /* inheritance query, explicitly */
- PublicationObjSpec *n = makeNode(PublicationObjSpec);
- n->name = $1;
- n->inh = true;
- n->spl_rel_type_syn = true;
- $$ = n;
- }
- | ONLY any_name
- {
- /* 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);
+ $$->targettype = TARGETOBJ_TABLE;
+ $$->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"));
+ $$->targettype = TARGETOBJ_SCHEMA;
}
;
+
+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
{
$$ = $2;
- $$->pubobjtype = PUBLICATIONOBJ_TABLE;
+ $$->pubobjtype = PUBLICATIONOBJ_TABLE_LIST;
$$->location = @1;
}
| ALL TABLES IN_P SCHEMA pubobj_expr
{
$$ = $5;
- $$->pubobjtype = PUBLICATIONOBJ_REL_IN_SCHEMA;
+ $$->pubobjtype = PUBLICATIONOBJ_SCHEMA_LIST;
$$->location = @1;
}
| pubobj_expr
@@ -12493,7 +12474,14 @@ relation_expr:
$$->inh = true;
$$->alias = NULL;
}
- | qualified_name '*'
+ | special_relation_expr
+ {
+ $$ = $1;
+ }
+ ;
+
+special_relation_expr:
+ qualified_name '*'
{
/* inheritance query, explicitly */
$$ = $1;
@@ -12516,7 +12504,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 6380fa4a7a..fbc4cfa148 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -346,20 +346,24 @@ typedef struct RoleSpec
*/
typedef enum PublicationObjSpecType
{
- PUBLICATIONOBJ_TABLE, /* Table type */
- PUBLICATIONOBJ_REL_IN_SCHEMA, /* Relations in schema type */
- PUBLICATIONOBJ_UNKNOWN /* Unknown type */
+ PUBLICATIONOBJ_TABLE_LIST, /* Start flag of table list */
+ PUBLICATIONOBJ_SCHEMA_LIST, /* Start flag of schema list */
+ PUBLICATIONOBJ_UNKNOWN
} PublicationObjSpecType;
+typedef enum TargetObjType
+{
+ TARGETOBJ_TABLE, /* Table name */
+ TARGETOBJ_SCHEMA, /* Schema name */
+ TARGETOBJ_UNKNOWN /* Unknown type */
+} TargetObjType;
+
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 */
+ TargetObjType targettype; /* type of target object */
+ void *object; /* publication object name */
int location; /* token location, or -1 if unknown */
} PublicationObjSpec;
--
2.18.4