From e699381e3ae8c52e4e334007cebd04e6a366e81d Mon Sep 17 00:00:00 2001 From: Alexey Kondratov Date: Wed, 2 Sep 2020 23:05:16 +0300 Subject: [PATCH v27 5/5] Refactor gram.y in order to add a common parenthesized option list Previously there were two identical option lists (explain_option_list and vac_analyze_option_list) + very similar reindex_option_list. Now, unified parenthesized option lists added also to REINDEX and CLUSTER. It does not seem to make sense to maintain identical option lists in the grammar, since all new options are added and parsed in the backend code. That way, new common_option_list added in order to replace all explain_option_list, vac_analyze_option_list and reindex_option_list. --- src/backend/parser/gram.y | 67 ++++++++++----------------------------- 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 87b2042d4c..8f44d7a64e 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -315,10 +315,10 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); create_extension_opt_item alter_extension_opt_item %type opt_lock lock_type cast_context -%type vac_analyze_option_name -%type vac_analyze_option_elem -%type vac_analyze_option_list -%type vac_analyze_option_arg +%type common_option_name +%type common_option_elem +%type common_option_list +%type common_option_arg %type drop_option %type opt_or_replace opt_no opt_grant_grant_option opt_grant_admin_option @@ -513,10 +513,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type generic_option_arg %type generic_option_elem alter_generic_option_elem %type generic_option_list alter_generic_option_list -%type explain_option_name -%type explain_option_arg -%type explain_option_elem -%type explain_option_list %type reindex_target_type reindex_target_multitable @@ -8196,7 +8192,7 @@ ReindexStmt: makeDefElem("concurrently", NULL, @3)); $$ = (Node *)n; } - | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name + | REINDEX '(' common_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; @@ -8208,7 +8204,7 @@ ReindexStmt: makeDefElem("concurrently", NULL, @6)); $$ = (Node *)n; } - | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name + | REINDEX '(' common_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; @@ -10398,7 +10394,7 @@ ClusterStmt: $$ = (Node*)n; } - | CLUSTER '(' vac_analyze_option_list ')' qualified_name cluster_index_specification + | CLUSTER '(' common_option_list ')' qualified_name cluster_index_specification { ClusterStmt *n = makeNode(ClusterStmt); n->relation = $5; @@ -10464,7 +10460,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relati n->is_vacuumcmd = true; $$ = (Node *)n; } - | VACUUM '(' vac_analyze_option_list ')' opt_vacuum_relation_list + | VACUUM '(' common_option_list ')' opt_vacuum_relation_list { VacuumStmt *n = makeNode(VacuumStmt); n->options = $3; @@ -10485,7 +10481,7 @@ AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list n->is_vacuumcmd = false; $$ = (Node *)n; } - | analyze_keyword '(' vac_analyze_option_list ')' opt_vacuum_relation_list + | analyze_keyword '(' common_option_list ')' opt_vacuum_relation_list { VacuumStmt *n = makeNode(VacuumStmt); n->options = $3; @@ -10495,12 +10491,12 @@ AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list } ; -vac_analyze_option_list: - vac_analyze_option_elem +common_option_list: + common_option_elem { $$ = list_make1($1); } - | vac_analyze_option_list ',' vac_analyze_option_elem + | common_option_list ',' common_option_elem { $$ = lappend($1, $3); } @@ -10511,19 +10507,19 @@ analyze_keyword: | ANALYSE /* British */ {} ; -vac_analyze_option_elem: - vac_analyze_option_name vac_analyze_option_arg +common_option_elem: + common_option_name common_option_arg { $$ = makeDefElem($1, $2, @1); } ; -vac_analyze_option_name: +common_option_name: NonReservedWord { $$ = $1; } | analyze_keyword { $$ = "analyze"; } ; -vac_analyze_option_arg: +common_option_arg: opt_boolean_or_string { $$ = (Node *) makeString($1); } | NumericOnly { $$ = (Node *) $1; } | /* EMPTY */ { $$ = NULL; } @@ -10605,7 +10601,7 @@ ExplainStmt: n->options = list_make1(makeDefElem("verbose", NULL, @2)); $$ = (Node *) n; } - | EXPLAIN '(' explain_option_list ')' ExplainableStmt + | EXPLAIN '(' common_option_list ')' ExplainableStmt { ExplainStmt *n = makeNode(ExplainStmt); n->query = $5; @@ -10626,35 +10622,6 @@ ExplainableStmt: | ExecuteStmt /* by default all are $$=$1 */ ; -explain_option_list: - explain_option_elem - { - $$ = list_make1($1); - } - | explain_option_list ',' explain_option_elem - { - $$ = lappend($1, $3); - } - ; - -explain_option_elem: - explain_option_name explain_option_arg - { - $$ = makeDefElem($1, $2, @1); - } - ; - -explain_option_name: - NonReservedWord { $$ = $1; } - | analyze_keyword { $$ = "analyze"; } - ; - -explain_option_arg: - opt_boolean_or_string { $$ = (Node *) makeString($1); } - | NumericOnly { $$ = (Node *) $1; } - | /* EMPTY */ { $$ = NULL; } - ; - /***************************************************************************** * * QUERY: -- 2.17.0