Skip to content

Commit

Permalink
sql, parser: add EXPERIMENTAL_RELOCATE VOTERS as alias of
Browse files Browse the repository at this point in the history
`EXPERIMENTAL_RELOCATE`

Release note (sql change): `EXPERIMENTAL_RELOCATE VOTERS` is now an
alias of `EXPERIMENTAL_RELOCATE`.
  • Loading branch information
aayushshah15 committed Mar 29, 2021
1 parent e381225 commit af80850
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ unreserved_keyword ::=
| 'VARYING'
| 'VIEW'
| 'VIEWACTIVITY'
| 'VOTERS'
| 'WITHIN'
| 'WITHOUT'
| 'WRITE'
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/kvccl/kvfollowerreadsccl/followerreads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func TestFollowerReadsWithStaleDescriptor(t *testing.T) {
n1 := sqlutils.MakeSQLRunner(tc.Conns[0])
n1.Exec(t, `CREATE DATABASE t`)
n1.Exec(t, `CREATE TABLE test (k INT PRIMARY KEY)`)
n1.Exec(t, `ALTER TABLE test EXPERIMENTAL_RELOCATE VALUES (ARRAY[1,2], 1)`)
n1.Exec(t, `ALTER TABLE test EXPERIMENTAL_RELOCATE VOTERS VALUES (ARRAY[1,2], 1)`)
// Speed up closing of timestamps, as we'll in order to be able to use
// follower_read_timestamp().
// Every 0.2s we'll close the timestamp from 0.4s ago. We'll attempt follower reads
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestFollowerReadsWithStaleDescriptor(t *testing.T) {
}, entry.Desc().Replicas().Descriptors())

// Relocate the follower. n2 will no longer have a replica.
n1.Exec(t, `ALTER TABLE test EXPERIMENTAL_RELOCATE VALUES (ARRAY[1,3], 1)`)
n1.Exec(t, `ALTER TABLE test EXPERIMENTAL_RELOCATE VOTERS VALUES (ARRAY[1,3], 1)`)

// Execute the query again and assert the cache is updated. This query will
// not be executed as a follower read since it attempts to use n2 which
Expand Down
31 changes: 26 additions & 5 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1518,11 +1518,11 @@ func TestParse(t *testing.T) {
{`ALTER INDEX "primary" UNSPLIT AT VALUES (2)`},
{`ALTER INDEX public.public."primary" UNSPLIT AT VALUES (2)`},

{`ALTER TABLE a EXPERIMENTAL_RELOCATE VALUES (ARRAY[1], 1)`},
{`EXPLAIN ALTER TABLE a EXPERIMENTAL_RELOCATE TABLE b`},
{`ALTER TABLE a EXPERIMENTAL_RELOCATE SELECT * FROM t`},
{`ALTER TABLE d.a EXPERIMENTAL_RELOCATE VALUES (ARRAY[1, 2, 3], 'b', 2)`},
{`ALTER INDEX d.i EXPERIMENTAL_RELOCATE VALUES (ARRAY[1], 2)`},
{`ALTER TABLE a EXPERIMENTAL_RELOCATE VOTERS VALUES (ARRAY[1], 1)`},
{`EXPLAIN ALTER TABLE a EXPERIMENTAL_RELOCATE VOTERS TABLE b`},
{`ALTER TABLE a EXPERIMENTAL_RELOCATE VOTERS SELECT * FROM t`},
{`ALTER TABLE d.a EXPERIMENTAL_RELOCATE VOTERS VALUES (ARRAY[1, 2, 3], 'b', 2)`},
{`ALTER INDEX d.i EXPERIMENTAL_RELOCATE VOTERS VALUES (ARRAY[1], 2)`},

{`ALTER TABLE a EXPERIMENTAL_RELOCATE LEASE VALUES (1, 1)`},
{`ALTER TABLE a EXPERIMENTAL_RELOCATE LEASE SELECT * FROM t`},
Expand Down Expand Up @@ -1911,6 +1911,27 @@ func TestParse2(t *testing.T) {

{`ANALYSE t`, `ANALYZE t`},

{
`ALTER TABLE a EXPERIMENTAL_RELOCATE VALUES (ARRAY[1], 1)`,
`ALTER TABLE a EXPERIMENTAL_RELOCATE VOTERS VALUES (ARRAY[1], 1)`,
},
{
`EXPLAIN ALTER TABLE a EXPERIMENTAL_RELOCATE TABLE b`,
`EXPLAIN ALTER TABLE a EXPERIMENTAL_RELOCATE VOTERS TABLE b`,
},
{
`ALTER TABLE a EXPERIMENTAL_RELOCATE SELECT * FROM t`,
`ALTER TABLE a EXPERIMENTAL_RELOCATE VOTERS SELECT * FROM t`,
},
{
`ALTER TABLE d.a EXPERIMENTAL_RELOCATE VALUES (ARRAY[1, 2, 3], 'b', 2)`,
`ALTER TABLE d.a EXPERIMENTAL_RELOCATE VOTERS VALUES (ARRAY[1, 2, 3], 'b', 2)`,
},
{
`ALTER INDEX d.i EXPERIMENTAL_RELOCATE VALUES (ARRAY[1], 2)`,
`ALTER INDEX d.i EXPERIMENTAL_RELOCATE VOTERS VALUES (ARRAY[1], 2)`,
},

{`SELECT TIMESTAMP WITHOUT TIME ZONE 'foo'`, `SELECT TIMESTAMP 'foo'`},
{`SELECT CAST('foo' AS TIMESTAMP WITHOUT TIME ZONE)`, `SELECT CAST('foo' AS TIMESTAMP)`},
{`SELECT CAST(1 AS "timestamp")`, `SELECT CAST(1 AS TIMESTAMP)`},
Expand Down
15 changes: 10 additions & 5 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func (u *sqlSymUnion) objectNamePrefixList() tree.ObjectNamePrefixList {
%token <str> UNBOUNDED UNCOMMITTED UNION UNIQUE UNKNOWN UNLOGGED UNSPLIT
%token <str> UPDATE UPSERT UNTIL USE USER USERS USING UUID

%token <str> VALID VALIDATE VALUE VALUES VARBIT VARCHAR VARIADIC VIEW VARYING VIEWACTIVITY VIRTUAL VISIBLE
%token <str> VALID VALIDATE VALUE VALUES VARBIT VARCHAR VARIADIC VIEW VARYING VIEWACTIVITY VIRTUAL VISIBLE VOTERS

%token <str> WHEN WHERE WINDOW WITH WITHIN WITHOUT WORK WRITE

Expand Down Expand Up @@ -1684,22 +1684,26 @@ relocate_kw:
TESTING_RELOCATE
| EXPERIMENTAL_RELOCATE

voters_kw:
VOTERS {}
| /* EMPTY */ {}

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

alter_relocate_index_stmt:
ALTER INDEX table_index_name relocate_kw select_stmt
ALTER INDEX table_index_name relocate_kw voters_kw select_stmt
{
/* SKIP DOC */
$$.val = &tree.Relocate{TableOrIndex: $3.tableIndexName(), Rows: $5.slct()}
$$.val = &tree.Relocate{TableOrIndex: $3.tableIndexName(), Rows: $6.slct()}
}

alter_relocate_lease_stmt:
Expand Down Expand Up @@ -12605,6 +12609,7 @@ unreserved_keyword:
| VARYING
| VIEW
| VIEWACTIVITY
| VOTERS
| WITHIN
| WITHOUT
| WRITE
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/sem/tree/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ func (node *Relocate) Format(ctx *FmtCtx) {
ctx.WriteString("TABLE ")
}
ctx.FormatNode(&node.TableOrIndex)
ctx.WriteString(" EXPERIMENTAL_RELOCATE ")
if node.RelocateLease {
ctx.WriteString("LEASE ")
ctx.WriteString(" EXPERIMENTAL_RELOCATE LEASE ")
} else {
ctx.WriteString(" EXPERIMENTAL_RELOCATE VOTERS ")
}
ctx.FormatNode(node.Rows)
}
Expand Down

0 comments on commit af80850

Please sign in to comment.