From 61546a59613aa6b4561acccbfe00d1bbcaddd7f2 Mon Sep 17 00:00:00 2001 From: "houzj.fnst" Date: Fri, 10 Sep 2021 11:04:37 +0800 Subject: [PATCH] refactor without flag --- src/backend/commands/publicationcmds.c | 38 +++++++++++++-------- src/backend/parser/gram.y | 62 +++++++++++++--------------------- src/include/nodes/parsenodes.h | 8 ++--- 3 files changed, 50 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..7a7095b 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 opt_routine_body %type group_clause @@ -518,6 +518,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type table_ref %type joined_table %type relation_expr +%type special_relation_expr %type relation_expr_opt_alias %type tablesample_clause opt_repeatable_clause %type target_el set_target insert_column_item @@ -9629,52 +9630,29 @@ 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); + $$->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); + $$->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")); } ; + +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 +12471,14 @@ relation_expr: $$->inh = true; $$->alias = NULL; } - | qualified_name '*' + | special_relation_expr + { + $$ = $1; + } + ; + +special_relation_expr: + qualified_name '*' { /* inheritance query, explicitly */ $$ = $1; @@ -12516,7 +12501,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