Skip to content

Commit

Permalink
sql: simplify the grammar
Browse files Browse the repository at this point in the history
There is no need for separate non-terminals for the 'LEASE' variants of
RELOCATE. This commit deletes them.

Release note: None
  • Loading branch information
knz committed Dec 14, 2021
1 parent 45cc75e commit d416008
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 36 deletions.
1 change: 0 additions & 1 deletion docs/generated/sql/bnf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ FILES = [
"alter_index_stmt",
"alter_partition_stmt",
"alter_primary_key",
"alter_range_relocate_lease_stmt",
"alter_range_relocate_stmt",
"alter_range_stmt",
"alter_rename_view_stmt",
Expand Down
3 changes: 0 additions & 3 deletions docs/generated/sql/bnf/alter_range_relocate_lease_stmt.bnf

This file was deleted.

4 changes: 3 additions & 1 deletion docs/generated/sql/bnf/alter_range_relocate_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
alter_range_relocate_stmt ::=
'ALTER' 'RANGE' relocate_kw voters_kw 'FROM' iconst64 'TO' iconst64 'FOR' select_stmt
'ALTER' 'RANGE' relocate_kw 'LEASE' 'TO' iconst64 'FOR' select_stmt
| 'ALTER' 'RANGE' iconst64 relocate_kw 'LEASE' 'TO' iconst64
| 'ALTER' 'RANGE' relocate_kw voters_kw 'FROM' iconst64 'TO' iconst64 'FOR' select_stmt
| 'ALTER' 'RANGE' iconst64 relocate_kw voters_kw 'FROM' iconst64 'TO' iconst64
| 'ALTER' 'RANGE' relocate_kw 'NONVOTERS' 'FROM' iconst64 'TO' iconst64 'FOR' select_stmt
| 'ALTER' 'RANGE' iconst64 relocate_kw 'NONVOTERS' 'FROM' iconst64 'TO' iconst64
1 change: 0 additions & 1 deletion docs/generated/sql/bnf/alter_range_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
alter_range_stmt ::=
alter_zone_range_stmt
| alter_range_relocate_lease_stmt
| alter_range_relocate_stmt
7 changes: 2 additions & 5 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,6 @@ alter_database_stmt ::=

alter_range_stmt ::=
alter_zone_range_stmt
| alter_range_relocate_lease_stmt
| alter_range_relocate_stmt

alter_partition_stmt ::=
Expand Down Expand Up @@ -1846,12 +1845,10 @@ alter_database_primary_region_stmt ::=
alter_zone_range_stmt ::=
'ALTER' 'RANGE' zone_name set_zone_config

alter_range_relocate_lease_stmt ::=
alter_range_relocate_stmt ::=
'ALTER' 'RANGE' relocate_kw 'LEASE' 'TO' iconst64 'FOR' select_stmt
| 'ALTER' 'RANGE' iconst64 relocate_kw 'LEASE' 'TO' iconst64

alter_range_relocate_stmt ::=
'ALTER' 'RANGE' relocate_kw voters_kw 'FROM' iconst64 'TO' iconst64 'FOR' select_stmt
| 'ALTER' 'RANGE' relocate_kw voters_kw 'FROM' iconst64 'TO' iconst64 'FOR' select_stmt
| 'ALTER' 'RANGE' iconst64 relocate_kw voters_kw 'FROM' iconst64 'TO' iconst64
| 'ALTER' 'RANGE' relocate_kw 'NONVOTERS' 'FROM' iconst64 'TO' iconst64 'FOR' select_stmt
| 'ALTER' 'RANGE' iconst64 relocate_kw 'NONVOTERS' 'FROM' iconst64 'TO' iconst64
Expand Down
38 changes: 13 additions & 25 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,6 @@ func (u *sqlSymUnion) setVar() *tree.SetVar {

// ALTER RANGE
%type <tree.Statement> alter_zone_range_stmt
%type <tree.Statement> alter_range_relocate_lease_stmt
%type <tree.Statement> alter_range_relocate_stmt

// ALTER TABLE
Expand All @@ -913,7 +912,6 @@ func (u *sqlSymUnion) setVar() *tree.SetVar {
%type <tree.Statement> alter_rename_table_stmt
%type <tree.Statement> alter_scatter_stmt
%type <tree.Statement> alter_relocate_stmt
%type <tree.Statement> alter_relocate_lease_stmt
%type <tree.Statement> alter_zone_table_stmt
%type <tree.Statement> alter_table_set_schema_stmt
%type <tree.Statement> alter_table_locality_stmt
Expand Down Expand Up @@ -941,7 +939,6 @@ func (u *sqlSymUnion) setVar() *tree.SetVar {
%type <tree.Statement> alter_unsplit_index_stmt
%type <tree.Statement> alter_rename_index_stmt
%type <tree.Statement> alter_relocate_index_stmt
%type <tree.Statement> alter_relocate_index_lease_stmt
%type <tree.Statement> alter_zone_index_stmt

// ALTER VIEW
Expand Down Expand Up @@ -1577,7 +1574,6 @@ alter_ddl_stmt:
alter_table_stmt:
alter_onetable_stmt
| alter_relocate_stmt
| alter_relocate_lease_stmt
| alter_split_stmt
| alter_unsplit_stmt
| alter_scatter_stmt
Expand Down Expand Up @@ -1796,7 +1792,6 @@ alter_database_primary_region_stmt:
// %SeeAlso: ALTER TABLE
alter_range_stmt:
alter_zone_range_stmt
| alter_range_relocate_lease_stmt
| alter_range_relocate_stmt
| ALTER RANGE error // SHOW HELP: ALTER RANGE

Expand All @@ -1823,7 +1818,6 @@ alter_range_stmt:
alter_index_stmt:
alter_oneindex_stmt
| alter_relocate_index_stmt
| alter_relocate_index_lease_stmt
| alter_split_index_stmt
| alter_unsplit_index_stmt
| alter_scatter_index_stmt
Expand Down Expand Up @@ -1940,6 +1934,16 @@ alter_relocate_stmt:
RelocateNonVoters: true,
}
}
| ALTER TABLE table_name relocate_kw LEASE select_stmt
{
/* SKIP DOC */
name := $3.unresolvedObjectName().ToTableName()
$$.val = &tree.Relocate{
TableOrIndex: tree.TableIndexName{Table: name},
Rows: $6.slct(),
RelocateLease: true,
}
}

alter_relocate_index_stmt:
ALTER INDEX table_index_name relocate_kw voters_kw select_stmt
Expand All @@ -1952,21 +1956,7 @@ alter_relocate_index_stmt:
/* SKIP DOC */
$$.val = &tree.Relocate{TableOrIndex: $3.tableIndexName(), Rows: $6.slct(), RelocateNonVoters: true}
}

alter_relocate_lease_stmt:
ALTER TABLE table_name relocate_kw LEASE select_stmt
{
/* SKIP DOC */
name := $3.unresolvedObjectName().ToTableName()
$$.val = &tree.Relocate{
TableOrIndex: tree.TableIndexName{Table: name},
Rows: $6.slct(),
RelocateLease: true,
}
}

alter_relocate_index_lease_stmt:
ALTER INDEX table_index_name relocate_kw LEASE select_stmt
| ALTER INDEX table_index_name relocate_kw LEASE select_stmt
{
/* SKIP DOC */
$$.val = &tree.Relocate{TableOrIndex: $3.tableIndexName(), Rows: $6.slct(), RelocateLease: true}
Expand All @@ -1980,7 +1970,7 @@ alter_zone_range_stmt:
$$.val = s
}

alter_range_relocate_lease_stmt:
alter_range_relocate_stmt:
ALTER RANGE relocate_kw LEASE TO iconst64 FOR select_stmt
{
$$.val = &tree.RelocateRange{
Expand All @@ -2001,9 +1991,7 @@ alter_range_relocate_lease_stmt:
RelocateNonVoters: false,
}
}

alter_range_relocate_stmt:
ALTER RANGE relocate_kw voters_kw FROM iconst64 TO iconst64 FOR select_stmt
| ALTER RANGE relocate_kw voters_kw FROM iconst64 TO iconst64 FOR select_stmt
{
$$.val = &tree.RelocateRange{
Rows: $10.slct(),
Expand Down

0 comments on commit d416008

Please sign in to comment.