diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index 7dc630be249d..30fe5e1e99ee 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -1120,6 +1120,7 @@ unreserved_keyword ::= | 'VARYING' | 'VIEW' | 'VIEWACTIVITY' + | 'VOTERS' | 'WITHIN' | 'WITHOUT' | 'WRITE' diff --git a/pkg/ccl/kvccl/kvfollowerreadsccl/followerreads_test.go b/pkg/ccl/kvccl/kvfollowerreadsccl/followerreads_test.go index 2d9d205620f4..4224f60736cf 100644 --- a/pkg/ccl/kvccl/kvfollowerreadsccl/followerreads_test.go +++ b/pkg/ccl/kvccl/kvfollowerreadsccl/followerreads_test.go @@ -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 @@ -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 diff --git a/pkg/sql/parser/parse_test.go b/pkg/sql/parser/parse_test.go index de66593e214c..c2bbe1b7967f 100644 --- a/pkg/sql/parser/parse_test.go +++ b/pkg/sql/parser/parse_test.go @@ -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`}, @@ -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)`}, diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index adfbc0628714..5dc8ddc6387c 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -701,7 +701,7 @@ func (u *sqlSymUnion) objectNamePrefixList() tree.ObjectNamePrefixList { %token UNBOUNDED UNCOMMITTED UNION UNIQUE UNKNOWN UNLOGGED UNSPLIT %token UPDATE UPSERT UNTIL USE USER USERS USING UUID -%token VALID VALIDATE VALUE VALUES VARBIT VARCHAR VARIADIC VIEW VARYING VIEWACTIVITY VIRTUAL VISIBLE +%token VALID VALIDATE VALUE VALUES VARBIT VARCHAR VARIADIC VIEW VARYING VIEWACTIVITY VIRTUAL VISIBLE VOTERS %token WHEN WHERE WINDOW WITH WITHIN WITHOUT WORK WRITE @@ -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: @@ -12605,6 +12609,7 @@ unreserved_keyword: | VARYING | VIEW | VIEWACTIVITY +| VOTERS | WITHIN | WITHOUT | WRITE diff --git a/pkg/sql/sem/tree/split.go b/pkg/sql/sem/tree/split.go index d379ff9d5355..21f25219d02a 100644 --- a/pkg/sql/sem/tree/split.go +++ b/pkg/sql/sem/tree/split.go @@ -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) }