Skip to content

Commit

Permalink
sql/parser: add sequence_name_list element for DROP SEQUENCE
Browse files Browse the repository at this point in the history
This will hopefully make for better diagrams.

Fixes #86059

Release note: None
  • Loading branch information
ajwerner committed Aug 16, 2022
1 parent 55e0f99 commit 45e777b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 48 deletions.
12 changes: 6 additions & 6 deletions docs/generated/sql/bnf/drop_sequence_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
drop_sequence_stmt ::=
'DROP' 'SEQUENCE' table_name ( ( ',' table_name ) )* 'CASCADE'
| 'DROP' 'SEQUENCE' table_name ( ( ',' table_name ) )* 'RESTRICT'
| 'DROP' 'SEQUENCE' table_name ( ( ',' table_name ) )*
| 'DROP' 'SEQUENCE' 'IF' 'EXISTS' table_name ( ( ',' table_name ) )* 'CASCADE'
| 'DROP' 'SEQUENCE' 'IF' 'EXISTS' table_name ( ( ',' table_name ) )* 'RESTRICT'
| 'DROP' 'SEQUENCE' 'IF' 'EXISTS' table_name ( ( ',' table_name ) )*
'DROP' 'SEQUENCE' sequence_name_list 'CASCADE'
| 'DROP' 'SEQUENCE' sequence_name_list 'RESTRICT'
| 'DROP' 'SEQUENCE' sequence_name_list
| 'DROP' 'SEQUENCE' 'IF' 'EXISTS' sequence_name_list 'CASCADE'
| 'DROP' 'SEQUENCE' 'IF' 'EXISTS' sequence_name_list 'RESTRICT'
| 'DROP' 'SEQUENCE' 'IF' 'EXISTS' sequence_name_list
12 changes: 6 additions & 6 deletions docs/generated/sql/bnf/drop_table.bnf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
drop_table_stmt ::=
'DROP' 'TABLE' table_name ( ( ',' table_name ) )* 'CASCADE'
| 'DROP' 'TABLE' table_name ( ( ',' table_name ) )* 'RESTRICT'
| 'DROP' 'TABLE' table_name ( ( ',' table_name ) )*
| 'DROP' 'TABLE' 'IF' 'EXISTS' table_name ( ( ',' table_name ) )* 'CASCADE'
| 'DROP' 'TABLE' 'IF' 'EXISTS' table_name ( ( ',' table_name ) )* 'RESTRICT'
| 'DROP' 'TABLE' 'IF' 'EXISTS' table_name ( ( ',' table_name ) )*
'DROP' 'TABLE' table_name_list 'CASCADE'
| 'DROP' 'TABLE' table_name_list 'RESTRICT'
| 'DROP' 'TABLE' table_name_list
| 'DROP' 'TABLE' 'IF' 'EXISTS' table_name_list 'CASCADE'
| 'DROP' 'TABLE' 'IF' 'EXISTS' table_name_list 'RESTRICT'
| 'DROP' 'TABLE' 'IF' 'EXISTS' table_name_list
8 changes: 4 additions & 4 deletions docs/generated/sql/bnf/drop_view.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
drop_view_stmt ::=
'DROP' 'VIEW' ( ( table_name ) ( ( ',' table_name ) )* ) ( 'CASCADE' | 'RESTRICT' | )
| 'DROP' 'VIEW' 'IF' 'EXISTS' ( ( table_name ) ( ( ',' table_name ) )* ) ( 'CASCADE' | 'RESTRICT' | )
| 'DROP' 'MATERIALIZED' 'VIEW' ( ( table_name ) ( ( ',' table_name ) )* ) ( 'CASCADE' | 'RESTRICT' | )
| 'DROP' 'MATERIALIZED' 'VIEW' 'IF' 'EXISTS' ( ( table_name ) ( ( ',' table_name ) )* ) ( 'CASCADE' | 'RESTRICT' | )
'DROP' 'VIEW' view_name_list ( 'CASCADE' | 'RESTRICT' | )
| 'DROP' 'VIEW' 'IF' 'EXISTS' view_name_list ( 'CASCADE' | 'RESTRICT' | )
| 'DROP' 'MATERIALIZED' 'VIEW' view_name_list ( 'CASCADE' | 'RESTRICT' | )
| 'DROP' 'MATERIALIZED' 'VIEW' 'IF' 'EXISTS' view_name_list ( 'CASCADE' | 'RESTRICT' | )
16 changes: 8 additions & 8 deletions docs/generated/sql/bnf/for_locking.bnf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
for_locking_item ::=
'FOR' 'UPDATE' 'OF' table_name ( ( ',' table_name ) )* 'SKIP' 'LOCKED'
| 'FOR' 'UPDATE' 'OF' table_name ( ( ',' table_name ) )* 'NOWAIT'
| 'FOR' 'NO' 'KEY' 'UPDATE' 'OF' table_name ( ( ',' table_name ) )* 'SKIP' 'LOCKED'
| 'FOR' 'NO' 'KEY' 'UPDATE' 'OF' table_name ( ( ',' table_name ) )* 'NOWAIT'
| 'FOR' 'SHARE' 'OF' table_name ( ( ',' table_name ) )* 'SKIP' 'LOCKED'
| 'FOR' 'SHARE' 'OF' table_name ( ( ',' table_name ) )* 'NOWAIT'
| 'FOR' 'KEY' 'SHARE' 'OF' table_name ( ( ',' table_name ) )* 'SKIP' 'LOCKED'
| 'FOR' 'KEY' 'SHARE' 'OF' table_name ( ( ',' table_name ) )* 'NOWAIT'
'FOR' 'UPDATE' 'OF' table_name_list 'SKIP' 'LOCKED'
| 'FOR' 'UPDATE' 'OF' table_name_list 'NOWAIT'
| 'FOR' 'NO' 'KEY' 'UPDATE' 'OF' table_name_list 'SKIP' 'LOCKED'
| 'FOR' 'NO' 'KEY' 'UPDATE' 'OF' table_name_list 'NOWAIT'
| 'FOR' 'SHARE' 'OF' table_name_list 'SKIP' 'LOCKED'
| 'FOR' 'SHARE' 'OF' table_name_list 'NOWAIT'
| 'FOR' 'KEY' 'SHARE' 'OF' table_name_list 'SKIP' 'LOCKED'
| 'FOR' 'KEY' 'SHARE' 'OF' table_name_list 'NOWAIT'
23 changes: 16 additions & 7 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1764,14 +1764,14 @@ drop_table_stmt ::=
| 'DROP' 'TABLE' 'IF' 'EXISTS' table_name_list opt_drop_behavior

drop_view_stmt ::=
'DROP' 'VIEW' table_name_list opt_drop_behavior
| 'DROP' 'VIEW' 'IF' 'EXISTS' table_name_list opt_drop_behavior
| 'DROP' 'MATERIALIZED' 'VIEW' table_name_list opt_drop_behavior
| 'DROP' 'MATERIALIZED' 'VIEW' 'IF' 'EXISTS' table_name_list opt_drop_behavior
'DROP' 'VIEW' view_name_list opt_drop_behavior
| 'DROP' 'VIEW' 'IF' 'EXISTS' view_name_list opt_drop_behavior
| 'DROP' 'MATERIALIZED' 'VIEW' view_name_list opt_drop_behavior
| 'DROP' 'MATERIALIZED' 'VIEW' 'IF' 'EXISTS' view_name_list opt_drop_behavior

drop_sequence_stmt ::=
'DROP' 'SEQUENCE' table_name_list opt_drop_behavior
| 'DROP' 'SEQUENCE' 'IF' 'EXISTS' table_name_list opt_drop_behavior
'DROP' 'SEQUENCE' sequence_name_list opt_drop_behavior
| 'DROP' 'SEQUENCE' 'IF' 'EXISTS' sequence_name_list opt_drop_behavior

drop_schema_stmt ::=
'DROP' 'SCHEMA' schema_name_list opt_drop_behavior
Expand Down Expand Up @@ -2479,7 +2479,13 @@ table_index_name_list ::=
( table_index_name ) ( ( ',' table_index_name ) )*

table_name_list ::=
( table_name ) ( ( ',' table_name ) )*
db_object_name_list

view_name_list ::=
db_object_name_list

sequence_name_list ::=
db_object_name_list

non_reserved_word ::=
'identifier'
Expand Down Expand Up @@ -3034,6 +3040,9 @@ only_signed_fconst ::=
'+' 'FCONST'
| '-' 'FCONST'

db_object_name_list ::=
( db_object_name ) ( ( ',' db_object_name ) )*

scrub_option ::=
'INDEX' 'ALL'
| 'INDEX' '(' name_list ')'
Expand Down
11 changes: 5 additions & 6 deletions pkg/cmd/docgen/diagrams.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ var specs = []stmtSpec{
{
name: "for_locking",
stmt: "for_locking_item",
inline: []string{"for_locking_strength", "opt_locked_rels", "opt_nowait_or_skip", "table_name_list"},
inline: []string{"for_locking_strength", "opt_locked_rels", "opt_nowait_or_skip"},
},
{
name: "col_qualification",
Expand Down Expand Up @@ -844,7 +844,7 @@ var specs = []stmtSpec{
},
{
name: "drop_sequence_stmt",
inline: []string{"table_name_list", "opt_drop_behavior"},
inline: []string{"opt_drop_behavior"},
unlink: []string{"sequence_name"},
},
{
Expand All @@ -855,24 +855,23 @@ var specs = []stmtSpec{
},
{
name: "drop_stmt",
inline: []string{"table_name_list", "drop_ddl_stmt"},
inline: []string{"drop_ddl_stmt"},
},
{
name: "drop_table",
stmt: "drop_table_stmt",
inline: []string{"opt_drop_behavior", "table_name_list"},
inline: []string{"opt_drop_behavior"},
match: []*regexp.Regexp{regexp.MustCompile("'DROP' 'TABLE'")},
},
{
name: "drop_type",
stmt: "drop_type_stmt",
inline: []string{"table_name_list"},
replace: map[string]string{"opt_drop_behavior": ""},
},
{
name: "drop_view",
stmt: "drop_view_stmt",
inline: []string{"opt_drop_behavior", "table_name_list"},
inline: []string{"opt_drop_behavior"},
nosplit: true,
},
{
Expand Down
31 changes: 20 additions & 11 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ func (u *sqlSymUnion) functionObjs() tree.FuncObjs {
%type <tree.From> from_clause
%type <tree.TableExprs> from_list rowsfrom_list opt_from_list
%type <tree.TablePatterns> table_pattern_list
%type <tree.TableNames> table_name_list opt_locked_rels
%type <tree.TableNames> db_object_name_list table_name_list view_name_list sequence_name_list opt_locked_rels
%type <tree.Exprs> expr_list opt_expr_list tuple1_ambiguous_values tuple1_unambiguous_values
%type <*tree.Tuple> expr_tuple1_ambiguous expr_tuple_unambiguous
%type <tree.NameList> attrs
Expand Down Expand Up @@ -4824,15 +4824,15 @@ drop_ddl_stmt:
// %Text: DROP [MATERIALIZED] VIEW [IF EXISTS] <tablename> [, ...] [CASCADE | RESTRICT]
// %SeeAlso: WEBDOCS/drop-index.html
drop_view_stmt:
DROP VIEW table_name_list opt_drop_behavior
DROP VIEW view_name_list opt_drop_behavior
{
$$.val = &tree.DropView{Names: $3.tableNames(), IfExists: false, DropBehavior: $4.dropBehavior()}
}
| DROP VIEW IF EXISTS table_name_list opt_drop_behavior
| DROP VIEW IF EXISTS view_name_list opt_drop_behavior
{
$$.val = &tree.DropView{Names: $5.tableNames(), IfExists: true, DropBehavior: $6.dropBehavior()}
}
| DROP MATERIALIZED VIEW table_name_list opt_drop_behavior
| DROP MATERIALIZED VIEW view_name_list opt_drop_behavior
{
$$.val = &tree.DropView{
Names: $4.tableNames(),
Expand All @@ -4841,7 +4841,7 @@ drop_view_stmt:
IsMaterialized: true,
}
}
| DROP MATERIALIZED VIEW IF EXISTS table_name_list opt_drop_behavior
| DROP MATERIALIZED VIEW IF EXISTS view_name_list opt_drop_behavior
{
$$.val = &tree.DropView{
Names: $6.tableNames(),
Expand All @@ -4857,11 +4857,11 @@ drop_view_stmt:
// %Text: DROP SEQUENCE [IF EXISTS] <sequenceName> [, ...] [CASCADE | RESTRICT]
// %SeeAlso: DROP
drop_sequence_stmt:
DROP SEQUENCE table_name_list opt_drop_behavior
DROP SEQUENCE sequence_name_list opt_drop_behavior
{
$$.val = &tree.DropSequence{Names: $3.tableNames(), IfExists: false, DropBehavior: $4.dropBehavior()}
}
| DROP SEQUENCE IF EXISTS table_name_list opt_drop_behavior
| DROP SEQUENCE IF EXISTS sequence_name_list opt_drop_behavior
{
$$.val = &tree.DropSequence{Names: $5.tableNames(), IfExists: true, DropBehavior: $6.dropBehavior()}
}
Expand Down Expand Up @@ -5005,18 +5005,27 @@ drop_role_stmt:
}
| DROP role_or_group_or_user error // SHOW HELP: DROP ROLE

table_name_list:
table_name
db_object_name_list:
db_object_name
{
name := $1.unresolvedObjectName().ToTableName()
$$.val = tree.TableNames{name}
}
| table_name_list ',' table_name
| db_object_name_list ',' db_object_name
{
name := $3.unresolvedObjectName().ToTableName()
$$.val = append($1.tableNames(), name)
}

table_name_list:
db_object_name_list

sequence_name_list:
db_object_name_list

view_name_list:
db_object_name_list

// %Help: ANALYZE - collect table statistics
// %Category: Misc
// %Text:
Expand Down Expand Up @@ -7225,7 +7234,7 @@ show_create_stmt:
/* SKIP DOC */
$$.val = &tree.ShowCreate{Mode: tree.ShowCreateModeView, Name: $4.unresolvedObjectName()}
}
| SHOW CREATE SEQUENCE table_name
| SHOW CREATE SEQUENCE sequence_name
{
/* SKIP DOC */
$$.val = &tree.ShowCreate{Mode: tree.ShowCreateModeSequence, Name: $4.unresolvedObjectName()}
Expand Down

0 comments on commit 45e777b

Please sign in to comment.