Refactor parsing rules for option lists of EXPLAIN, VACUUM and ANALYZE

Those three commands have been using the same grammar rules to handle a
a list of parenthesized options.  This refactors the code so as they use
the same parsing rules, shaving some code.  A future commit will make
use of those option parsing rules for more utility commands, like
REINDEX and CLUSTER.

Author: Alexey Kondratov, Justin Pryzby
Discussion: https://postgr.es/m/8a8f5f73-00d3-55f8-7583-1375ca8f6a91@postgrespro.ru
This commit is contained in:
Michael Paquier 2020-11-30 20:27:37 +09:00
parent 2bc588798b
commit 873ea9ee69
1 changed files with 14 additions and 47 deletions

View File

@ -315,10 +315,10 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
create_extension_opt_item alter_extension_opt_item
%type <ival> opt_lock lock_type cast_context
%type <str> vac_analyze_option_name
%type <defelt> vac_analyze_option_elem
%type <list> vac_analyze_option_list
%type <node> vac_analyze_option_arg
%type <str> utility_option_name
%type <defelt> utility_option_elem
%type <list> utility_option_list
%type <node> utility_option_arg
%type <defelt> drop_option
%type <boolean> 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 <node> generic_option_arg
%type <defelt> generic_option_elem alter_generic_option_elem
%type <list> generic_option_list alter_generic_option_list
%type <str> explain_option_name
%type <node> explain_option_arg
%type <defelt> explain_option_elem
%type <list> explain_option_list
%type <ival> reindex_target_type reindex_target_multitable
%type <ival> reindex_option_list reindex_option_elem
@ -10483,7 +10479,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 '(' utility_option_list ')' opt_vacuum_relation_list
{
VacuumStmt *n = makeNode(VacuumStmt);
n->options = $3;
@ -10504,7 +10500,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 '(' utility_option_list ')' opt_vacuum_relation_list
{
VacuumStmt *n = makeNode(VacuumStmt);
n->options = $3;
@ -10514,12 +10510,12 @@ AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
}
;
vac_analyze_option_list:
vac_analyze_option_elem
utility_option_list:
utility_option_elem
{
$$ = list_make1($1);
}
| vac_analyze_option_list ',' vac_analyze_option_elem
| utility_option_list ',' utility_option_elem
{
$$ = lappend($1, $3);
}
@ -10530,19 +10526,19 @@ analyze_keyword:
| ANALYSE /* British */
;
vac_analyze_option_elem:
vac_analyze_option_name vac_analyze_option_arg
utility_option_elem:
utility_option_name utility_option_arg
{
$$ = makeDefElem($1, $2, @1);
}
;
vac_analyze_option_name:
utility_option_name:
NonReservedWord { $$ = $1; }
| analyze_keyword { $$ = "analyze"; }
;
vac_analyze_option_arg:
utility_option_arg:
opt_boolean_or_string { $$ = (Node *) makeString($1); }
| NumericOnly { $$ = (Node *) $1; }
| /* EMPTY */ { $$ = NULL; }
@ -10624,7 +10620,7 @@ ExplainStmt:
n->options = list_make1(makeDefElem("verbose", NULL, @2));
$$ = (Node *) n;
}
| EXPLAIN '(' explain_option_list ')' ExplainableStmt
| EXPLAIN '(' utility_option_list ')' ExplainableStmt
{
ExplainStmt *n = makeNode(ExplainStmt);
n->query = $5;
@ -10645,35 +10641,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: