Skip to content

Commit 873ea9e

Browse files
committed
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
1 parent 2bc5887 commit 873ea9e

File tree

1 file changed

+14
-47
lines changed

1 file changed

+14
-47
lines changed

src/backend/parser/gram.y

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
315315
create_extension_opt_item alter_extension_opt_item
316316

317317
%type <ival> opt_lock lock_type cast_context
318-
%type <str> vac_analyze_option_name
319-
%type <defelt> vac_analyze_option_elem
320-
%type <list> vac_analyze_option_list
321-
%type <node> vac_analyze_option_arg
318+
%type <str> utility_option_name
319+
%type <defelt> utility_option_elem
320+
%type <list> utility_option_list
321+
%type <node> utility_option_arg
322322
%type <defelt> drop_option
323323
%type <boolean> opt_or_replace opt_no
324324
opt_grant_grant_option opt_grant_admin_option
@@ -513,10 +513,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
513513
%type <node> generic_option_arg
514514
%type <defelt> generic_option_elem alter_generic_option_elem
515515
%type <list> generic_option_list alter_generic_option_list
516-
%type <str> explain_option_name
517-
%type <node> explain_option_arg
518-
%type <defelt> explain_option_elem
519-
%type <list> explain_option_list
520516

521517
%type <ival> reindex_target_type reindex_target_multitable
522518
%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
1048310479
n->is_vacuumcmd = true;
1048410480
$$ = (Node *)n;
1048510481
}
10486-
| VACUUM '(' vac_analyze_option_list ')' opt_vacuum_relation_list
10482+
| VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
1048710483
{
1048810484
VacuumStmt *n = makeNode(VacuumStmt);
1048910485
n->options = $3;
@@ -10504,7 +10500,7 @@ AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
1050410500
n->is_vacuumcmd = false;
1050510501
$$ = (Node *)n;
1050610502
}
10507-
| analyze_keyword '(' vac_analyze_option_list ')' opt_vacuum_relation_list
10503+
| analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
1050810504
{
1050910505
VacuumStmt *n = makeNode(VacuumStmt);
1051010506
n->options = $3;
@@ -10514,12 +10510,12 @@ AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
1051410510
}
1051510511
;
1051610512

10517-
vac_analyze_option_list:
10518-
vac_analyze_option_elem
10513+
utility_option_list:
10514+
utility_option_elem
1051910515
{
1052010516
$$ = list_make1($1);
1052110517
}
10522-
| vac_analyze_option_list ',' vac_analyze_option_elem
10518+
| utility_option_list ',' utility_option_elem
1052310519
{
1052410520
$$ = lappend($1, $3);
1052510521
}
@@ -10530,19 +10526,19 @@ analyze_keyword:
1053010526
| ANALYSE /* British */
1053110527
;
1053210528

10533-
vac_analyze_option_elem:
10534-
vac_analyze_option_name vac_analyze_option_arg
10529+
utility_option_elem:
10530+
utility_option_name utility_option_arg
1053510531
{
1053610532
$$ = makeDefElem($1, $2, @1);
1053710533
}
1053810534
;
1053910535

10540-
vac_analyze_option_name:
10536+
utility_option_name:
1054110537
NonReservedWord { $$ = $1; }
1054210538
| analyze_keyword { $$ = "analyze"; }
1054310539
;
1054410540

10545-
vac_analyze_option_arg:
10541+
utility_option_arg:
1054610542
opt_boolean_or_string { $$ = (Node *) makeString($1); }
1054710543
| NumericOnly { $$ = (Node *) $1; }
1054810544
| /* EMPTY */ { $$ = NULL; }
@@ -10624,7 +10620,7 @@ ExplainStmt:
1062410620
n->options = list_make1(makeDefElem("verbose", NULL, @2));
1062510621
$$ = (Node *) n;
1062610622
}
10627-
| EXPLAIN '(' explain_option_list ')' ExplainableStmt
10623+
| EXPLAIN '(' utility_option_list ')' ExplainableStmt
1062810624
{
1062910625
ExplainStmt *n = makeNode(ExplainStmt);
1063010626
n->query = $5;
@@ -10645,35 +10641,6 @@ ExplainableStmt:
1064510641
| ExecuteStmt /* by default all are $$=$1 */
1064610642
;
1064710643

10648-
explain_option_list:
10649-
explain_option_elem
10650-
{
10651-
$$ = list_make1($1);
10652-
}
10653-
| explain_option_list ',' explain_option_elem
10654-
{
10655-
$$ = lappend($1, $3);
10656-
}
10657-
;
10658-
10659-
explain_option_elem:
10660-
explain_option_name explain_option_arg
10661-
{
10662-
$$ = makeDefElem($1, $2, @1);
10663-
}
10664-
;
10665-
10666-
explain_option_name:
10667-
NonReservedWord { $$ = $1; }
10668-
| analyze_keyword { $$ = "analyze"; }
10669-
;
10670-
10671-
explain_option_arg:
10672-
opt_boolean_or_string { $$ = (Node *) makeString($1); }
10673-
| NumericOnly { $$ = (Node *) $1; }
10674-
| /* EMPTY */ { $$ = NULL; }
10675-
;
10676-
1067710644
/*****************************************************************************
1067810645
*
1067910646
* QUERY:

0 commit comments

Comments
 (0)