Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d158e8

Browse files
committed
parser: centralize common auxiliary productions
Things like "opt_name" can well be shared by various commands ratherthan there being multiple definitions of the same thing. Rename theseproductions and move them to appear together in gram.y, which mayimprove chances of reuse in the future.Discussion:https://postgr.es/m/20220721174212.cmitjpuimx6ssyyj@alvherre.pgsql
1 parent9853bf6 commit7d158e8

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed

‎src/backend/parser/gram.y

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
334334
simple_selectvalues_clause
335335
PLpgSQL_ExprPLAssignStmt
336336

337+
%type<str>opt_single_name
338+
%type<list>opt_qualified_name
339+
%type<boolean>opt_concurrently
340+
%type<dbehavior>opt_drop_behavior
341+
337342
%type<node>alter_column_defaultopclass_itemopclass_dropalter_using
338343
%type<ival>add_dropopt_asc_descopt_nulls_order
339344

@@ -343,8 +348,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
343348
%type<list>alter_identity_column_option_list
344349
%type<defelt>alter_identity_column_option
345350

346-
%type<dbehavior>opt_drop_behavior
347-
348351
%type<list>createdb_opt_listcreatedb_opt_itemscopy_opt_list
349352
transaction_mode_list
350353
create_extension_opt_listalter_extension_opt_list
@@ -371,7 +374,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
371374
%type<str>foreign_server_versionopt_foreign_server_version
372375
%type<str>opt_in_database
373376

374-
%type<str>OptSchemaNameparameter_name
377+
%type<str>parameter_name
375378
%type<list>OptSchemaEltListparameter_name_list
376379

377380
%type<chr>am_type
@@ -392,10 +395,10 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
392395
%type<str>copy_file_name
393396
access_method_clauseattr_name
394397
table_access_method_clausenamecursor_namefile_name
395-
opt_index_namecluster_index_specification
398+
cluster_index_specification
396399

397400
%type<list>func_namehandler_namequal_Opqual_all_Opsubquery_Op
398-
opt_classopt_inline_handleropt_validatorvalidator_clause
401+
opt_inline_handleropt_validatorvalidator_clause
399402
opt_collate
400403

401404
%type<range>qualified_nameinsert_targetOptConstrFromTable
@@ -435,7 +438,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
435438
oper_argtypesRuleActionListRuleActionMulti
436439
opt_column_listcolumnListopt_name_list
437440
sort_clauseopt_sort_clausesortby_listindex_params
438-
opt_stats_namestats_params
441+
stats_params
439442
opt_includeopt_c_includeindex_including_params
440443
name_listrole_listfrom_clausefrom_listopt_array_bounds
441444
qualified_name_listany_nameany_name_listtype_name_list
@@ -495,7 +498,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
495498
%type<str>unicode_normal_form
496499

497500
%type<boolean>opt_instead
498-
%type<boolean>opt_uniqueopt_concurrentlyopt_verboseopt_full
501+
%type<boolean>opt_uniqueopt_verboseopt_full
499502
%type<boolean>opt_freezeopt_analyzeopt_defaultopt_recheck
500503
%type<defelt>opt_binarycopy_delimiter
501504

@@ -1180,6 +1183,30 @@ stmt:
11801183
{$$ =NULL; }
11811184
;
11821185

1186+
/*
1187+
* Generic supporting productions for DDL
1188+
*/
1189+
opt_single_name:
1190+
ColId{$$ =$1; }
1191+
|/* EMPTY*/{$$ =NULL; }
1192+
;
1193+
1194+
opt_qualified_name:
1195+
any_name{$$ =$1; }
1196+
|/*EMPTY*/{$$ = NIL; }
1197+
;
1198+
1199+
opt_concurrently:
1200+
CONCURRENTLY{$$ =true; }
1201+
|/*EMPTY*/{$$ =false; }
1202+
;
1203+
1204+
opt_drop_behavior:
1205+
CASCADE{$$ = DROP_CASCADE; }
1206+
|RESTRICT{$$ = DROP_RESTRICT; }
1207+
|/* EMPTY*/{$$ = DROP_RESTRICT;/* default*/ }
1208+
;
1209+
11831210
/*****************************************************************************
11841211
*
11851212
* CALL statement
@@ -1554,7 +1581,7 @@ add_drop:ADD_P{ $$ = +1; }
15541581
*****************************************************************************/
15551582

15561583
CreateSchemaStmt:
1557-
CREATESCHEMAOptSchemaNameAUTHORIZATIONRoleSpecOptSchemaEltList
1584+
CREATESCHEMAopt_single_nameAUTHORIZATIONRoleSpecOptSchemaEltList
15581585
{
15591586
CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
15601587

@@ -1576,7 +1603,7 @@ CreateSchemaStmt:
15761603
n->if_not_exists =false;
15771604
$$ = (Node *) n;
15781605
}
1579-
|CREATESCHEMAIF_PNOTEXISTSOptSchemaNameAUTHORIZATIONRoleSpecOptSchemaEltList
1606+
|CREATESCHEMAIF_PNOTEXISTSopt_single_nameAUTHORIZATIONRoleSpecOptSchemaEltList
15801607
{
15811608
CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
15821609

@@ -1610,11 +1637,6 @@ CreateSchemaStmt:
16101637
}
16111638
;
16121639

1613-
OptSchemaName:
1614-
ColId{$$ =$1; }
1615-
|/* EMPTY*/{$$ =NULL; }
1616-
;
1617-
16181640
OptSchemaEltList:
16191641
OptSchemaEltListschema_stmt
16201642
{
@@ -2995,12 +3017,6 @@ alter_column_default:
29953017
|DROPDEFAULT{$$ =NULL; }
29963018
;
29973019

2998-
opt_drop_behavior:
2999-
CASCADE{$$ = DROP_CASCADE; }
3000-
|RESTRICT{$$ = DROP_RESTRICT; }
3001-
|/* EMPTY*/{$$ = DROP_RESTRICT;/* default*/ }
3002-
;
3003-
30043020
opt_collate_clause:
30053021
COLLATEany_name
30063022
{
@@ -4467,7 +4483,7 @@ part_params:part_elem{ $$ = list_make1($1); }
44674483
|part_params','part_elem{$$ = lappend($1,$3); }
44684484
;
44694485

4470-
part_elem:ColIdopt_collateopt_class
4486+
part_elem:ColIdopt_collateopt_qualified_name
44714487
{
44724488
PartitionElem *n = makeNode(PartitionElem);
44734489

@@ -4478,7 +4494,7 @@ part_elem: ColId opt_collate opt_class
44784494
n->location =@1;
44794495
$$ = n;
44804496
}
4481-
|func_expr_windowlessopt_collateopt_class
4497+
|func_expr_windowlessopt_collateopt_qualified_name
44824498
{
44834499
PartitionElem *n = makeNode(PartitionElem);
44844500

@@ -4489,7 +4505,7 @@ part_elem: ColId opt_collate opt_class
44894505
n->location =@1;
44904506
$$ = n;
44914507
}
4492-
|'('a_expr')'opt_collateopt_class
4508+
|'('a_expr')'opt_collateopt_qualified_name
44934509
{
44944510
PartitionElem *n = makeNode(PartitionElem);
44954511

@@ -4543,10 +4559,12 @@ ExistingIndex: USING INDEX name{ $$ = $3; }
45434559
* but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
45444560
* errors as necessary at execution.
45454561
*
4562+
* Statistics name is optional unless IF NOT EXISTS is specified.
4563+
*
45464564
*****************************************************************************/
45474565

45484566
CreateStatsStmt:
4549-
CREATESTATISTICSopt_stats_name
4567+
CREATESTATISTICSopt_qualified_name
45504568
opt_name_listONstats_paramsFROMfrom_list
45514569
{
45524570
CreateStatsStmt *n = makeNode(CreateStatsStmt);
@@ -4574,12 +4592,6 @@ CreateStatsStmt:
45744592
}
45754593
;
45764594

4577-
/* Statistics name is optional unless IF NOT EXISTS is specified*/
4578-
opt_stats_name:
4579-
any_name{$$ =$1; }
4580-
|/*EMPTY*/{$$ =NULL; }
4581-
;
4582-
45834595
/*
45844596
* Statistics attributes can be either simple column references, or arbitrary
45854597
* expressions in parens. For compatibility with index attributes permitted
@@ -7987,7 +7999,7 @@ defacl_privilege_target:
79877999
* willing to make TABLESPACE a fully reserved word.
79888000
*****************************************************************************/
79898001

7990-
IndexStmt:CREATEopt_uniqueINDEXopt_concurrentlyopt_index_name
8002+
IndexStmt:CREATEopt_uniqueINDEXopt_concurrentlyopt_single_name
79918003
ONrelation_expraccess_method_clause'('index_params')'
79928004
opt_includeopt_unique_null_treatmentopt_reloptionsOptTableSpacewhere_clause
79938005
{
@@ -8058,16 +8070,6 @@ opt_unique:
80588070
|/*EMPTY*/{$$ =false; }
80598071
;
80608072

8061-
opt_concurrently:
8062-
CONCURRENTLY{$$ =true; }
8063-
|/*EMPTY*/{$$ =false; }
8064-
;
8065-
8066-
opt_index_name:
8067-
name{$$ =$1; }
8068-
|/*EMPTY*/{$$ =NULL; }
8069-
;
8070-
80718073
access_method_clause:
80728074
USINGname{$$ =$2; }
80738075
|/*EMPTY*/{$$ = DEFAULT_INDEX_TYPE; }
@@ -8079,7 +8081,7 @@ index_params:index_elem{ $$ = list_make1($1); }
80798081

80808082

80818083
index_elem_options:
8082-
opt_collateopt_classopt_asc_descopt_nulls_order
8084+
opt_collateopt_qualified_nameopt_asc_descopt_nulls_order
80838085
{
80848086
$$ = makeNode(IndexElem);
80858087
$$->name =NULL;
@@ -8139,9 +8141,6 @@ opt_collate: COLLATE any_name{ $$ = $2; }
81398141
|/*EMPTY*/{$$ = NIL; }
81408142
;
81418143

8142-
opt_class:any_name{$$ =$1; }
8143-
|/*EMPTY*/{$$ = NIL; }
8144-
;
81458144

81468145
opt_asc_desc:ASC{$$ = SORTBY_ASC; }
81478146
|DESC{$$ = SORTBY_DESC; }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp