Skip to content

Commit 1dfe3ef

Browse files
author
Álvaro Herrera
committed
Refactor grammar to create opt_utility_option_list
This changes the grammar for REINDEX, CHECKPOINT, CLUSTER, ANALYZE/ANALYSE; they still accept the same options as before, but the grammar is written differently for convenience of future development. Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://postgr.es/m/202507231538.ir7pjzoow6oe@alvherre.pgsql
1 parent b5d084c commit 1dfe3ef

File tree

1 file changed

+56
-68
lines changed

1 file changed

+56
-68
lines changed

src/backend/parser/gram.y

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
318318
%type <list> opt_qualified_name
319319
%type <boolean> opt_concurrently
320320
%type <dbehavior> opt_drop_behavior
321+
%type <list> opt_utility_option_list
322+
%type <list> utility_option_list
323+
%type <defelt> utility_option_elem
324+
%type <str> utility_option_name
325+
%type <node> utility_option_arg
321326

322327
%type <node> alter_column_default opclass_item opclass_drop alter_using
323328
%type <ival> add_drop opt_asc_desc opt_nulls_order
@@ -338,10 +343,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
338343
create_extension_opt_item alter_extension_opt_item
339344

340345
%type <ival> opt_lock lock_type cast_context
341-
%type <str> utility_option_name
342-
%type <defelt> utility_option_elem
343-
%type <list> utility_option_list
344-
%type <node> utility_option_arg
345346
%type <defelt> drop_option
346347
%type <boolean> opt_or_replace opt_no
347348
opt_grant_grant_option
@@ -556,7 +557,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
556557
%type <list> generic_option_list alter_generic_option_list
557558

558559
%type <ival> reindex_target_relation reindex_target_all
559-
%type <list> opt_reindex_option_list
560560

561561
%type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
562562
%type <defelt> copy_generic_opt_elem
@@ -1141,6 +1141,41 @@ opt_drop_behavior:
11411141
| /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
11421142
;
11431143

1144+
opt_utility_option_list:
1145+
'(' utility_option_list ')' { $$ = $2; }
1146+
| /* EMPTY */ { $$ = NULL; }
1147+
;
1148+
1149+
utility_option_list:
1150+
utility_option_elem
1151+
{
1152+
$$ = list_make1($1);
1153+
}
1154+
| utility_option_list ',' utility_option_elem
1155+
{
1156+
$$ = lappend($1, $3);
1157+
}
1158+
;
1159+
1160+
utility_option_elem:
1161+
utility_option_name utility_option_arg
1162+
{
1163+
$$ = makeDefElem($1, $2, @1);
1164+
}
1165+
;
1166+
1167+
utility_option_name:
1168+
NonReservedWord { $$ = $1; }
1169+
| analyze_keyword { $$ = "analyze"; }
1170+
| FORMAT_LA { $$ = "format"; }
1171+
;
1172+
1173+
utility_option_arg:
1174+
opt_boolean_or_string { $$ = (Node *) makeString($1); }
1175+
| NumericOnly { $$ = (Node *) $1; }
1176+
| /* EMPTY */ { $$ = NULL; }
1177+
;
1178+
11441179
/*****************************************************************************
11451180
*
11461181
* CALL statement
@@ -2028,18 +2063,12 @@ constraints_set_mode:
20282063
* Checkpoint statement
20292064
*/
20302065
CheckPointStmt:
2031-
CHECKPOINT
2066+
CHECKPOINT opt_utility_option_list
20322067
{
20332068
CheckPointStmt *n = makeNode(CheckPointStmt);
20342069

20352070
$$ = (Node *) n;
2036-
}
2037-
| CHECKPOINT '(' utility_option_list ')'
2038-
{
2039-
CheckPointStmt *n = makeNode(CheckPointStmt);
2040-
2041-
$$ = (Node *) n;
2042-
n->options = $3;
2071+
n->options = $2;
20432072
}
20442073
;
20452074

@@ -9354,7 +9383,7 @@ DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_d
93549383
*****************************************************************************/
93559384

93569385
ReindexStmt:
9357-
REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
9386+
REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
93589387
{
93599388
ReindexStmt *n = makeNode(ReindexStmt);
93609389

@@ -9367,7 +9396,7 @@ ReindexStmt:
93679396
makeDefElem("concurrently", NULL, @4));
93689397
$$ = (Node *) n;
93699398
}
9370-
| REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
9399+
| REINDEX opt_utility_option_list SCHEMA opt_concurrently name
93719400
{
93729401
ReindexStmt *n = makeNode(ReindexStmt);
93739402

@@ -9380,7 +9409,7 @@ ReindexStmt:
93809409
makeDefElem("concurrently", NULL, @4));
93819410
$$ = (Node *) n;
93829411
}
9383-
| REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
9412+
| REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
93849413
{
93859414
ReindexStmt *n = makeNode(ReindexStmt);
93869415

@@ -9402,10 +9431,6 @@ reindex_target_all:
94029431
SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
94039432
| DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
94049433
;
9405-
opt_reindex_option_list:
9406-
'(' utility_option_list ')' { $$ = $2; }
9407-
| /* EMPTY */ { $$ = NULL; }
9408-
;
94099434

94109435
/*****************************************************************************
94119436
*
@@ -11903,13 +11928,13 @@ ClusterStmt:
1190311928
n->params = $3;
1190411929
$$ = (Node *) n;
1190511930
}
11906-
| CLUSTER '(' utility_option_list ')'
11931+
| CLUSTER opt_utility_option_list
1190711932
{
1190811933
ClusterStmt *n = makeNode(ClusterStmt);
1190911934

1191011935
n->relation = NULL;
1191111936
n->indexname = NULL;
11912-
n->params = $3;
11937+
n->params = $2;
1191311938
$$ = (Node *) n;
1191411939
}
1191511940
/* unparenthesized VERBOSE kept for pre-14 compatibility */
@@ -11919,21 +11944,18 @@ ClusterStmt:
1191911944

1192011945
n->relation = $3;
1192111946
n->indexname = $4;
11922-
n->params = NIL;
1192311947
if ($2)
11924-
n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11948+
n->params = list_make1(makeDefElem("verbose", NULL, @2));
1192511949
$$ = (Node *) n;
1192611950
}
1192711951
/* unparenthesized VERBOSE kept for pre-17 compatibility */
11928-
| CLUSTER opt_verbose
11952+
| CLUSTER VERBOSE
1192911953
{
1193011954
ClusterStmt *n = makeNode(ClusterStmt);
1193111955

1193211956
n->relation = NULL;
1193311957
n->indexname = NULL;
11934-
n->params = NIL;
11935-
if ($2)
11936-
n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11958+
n->params = list_make1(makeDefElem("verbose", NULL, @2));
1193711959
$$ = (Node *) n;
1193811960
}
1193911961
/* kept for pre-8.3 compatibility */
@@ -11943,9 +11965,8 @@ ClusterStmt:
1194311965

1194411966
n->relation = $5;
1194511967
n->indexname = $3;
11946-
n->params = NIL;
1194711968
if ($2)
11948-
n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11969+
n->params = list_make1(makeDefElem("verbose", NULL, @2));
1194911970
$$ = (Node *) n;
1195011971
}
1195111972
;
@@ -11996,64 +12017,31 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relati
1199612017
}
1199712018
;
1199812019

11999-
AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
12020+
AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
1200012021
{
1200112022
VacuumStmt *n = makeNode(VacuumStmt);
1200212023

12003-
n->options = NIL;
12004-
if ($2)
12005-
n->options = lappend(n->options,
12006-
makeDefElem("verbose", NULL, @2));
12024+
n->options = $2;
1200712025
n->rels = $3;
1200812026
n->is_vacuumcmd = false;
1200912027
$$ = (Node *) n;
1201012028
}
12011-
| analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
12029+
| analyze_keyword VERBOSE opt_vacuum_relation_list
1201212030
{
1201312031
VacuumStmt *n = makeNode(VacuumStmt);
1201412032

12015-
n->options = $3;
12016-
n->rels = $5;
12033+
n->options = list_make1(makeDefElem("verbose", NULL, @2));
12034+
n->rels = $3;
1201712035
n->is_vacuumcmd = false;
1201812036
$$ = (Node *) n;
1201912037
}
1202012038
;
1202112039

12022-
utility_option_list:
12023-
utility_option_elem
12024-
{
12025-
$$ = list_make1($1);
12026-
}
12027-
| utility_option_list ',' utility_option_elem
12028-
{
12029-
$$ = lappend($1, $3);
12030-
}
12031-
;
12032-
1203312040
analyze_keyword:
1203412041
ANALYZE
1203512042
| ANALYSE /* British */
1203612043
;
1203712044

12038-
utility_option_elem:
12039-
utility_option_name utility_option_arg
12040-
{
12041-
$$ = makeDefElem($1, $2, @1);
12042-
}
12043-
;
12044-
12045-
utility_option_name:
12046-
NonReservedWord { $$ = $1; }
12047-
| analyze_keyword { $$ = "analyze"; }
12048-
| FORMAT_LA { $$ = "format"; }
12049-
;
12050-
12051-
utility_option_arg:
12052-
opt_boolean_or_string { $$ = (Node *) makeString($1); }
12053-
| NumericOnly { $$ = (Node *) $1; }
12054-
| /* EMPTY */ { $$ = NULL; }
12055-
;
12056-
1205712045
opt_analyze:
1205812046
analyze_keyword { $$ = true; }
1205912047
| /*EMPTY*/ { $$ = false; }

0 commit comments

Comments
 (0)