Skip to content

Commit

Permalink
Merge #40709
Browse files Browse the repository at this point in the history
40709: sql: add a syntax hint for ALTER PARTITION r=solongordon a=solongordon

If a user tries to modify multiple index partitions via ALTER PARTITION
... OF TABLE, they now receive a hint to use ALTER PARTITION ... OF
INDEX instead.

I also improved the help docs for `\h ALTER PARTITION` to specify how to
use the wildcard syntax.

Fixes #40387

Release note: None

Co-authored-by: Solon Gordon <solon@cockroachlabs.com>
  • Loading branch information
craig[bot] and solongordon committed Sep 12, 2019
2 parents 34e9175 + 838cfa1 commit 7007e06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,14 @@ DETAIL: source SQL:
CREATE STATISTICS a ON col1 FROM t WITH OPTIONS AS OF SYSTEM TIME '-1s' THROTTLING 0.1 AS OF SYSTEM TIME '-2s'
^`,
},
{
`ALTER PARTITION p OF TABLE tbl@* CONFIGURE ZONE USING num_replicas = 1`,
`at or near "configure": syntax error: index wildcard unsupported in ALTER PARTITION ... OF TABLE
DETAIL: source SQL:
ALTER PARTITION p OF TABLE tbl@* CONFIGURE ZONE USING num_replicas = 1
^
HINT: try ALTER PARTITION <partition> OF INDEX <tablename>@*`,
},
}
for _, d := range testData {
t.Run(d.sql, func(t *testing.T) {
Expand Down
16 changes: 14 additions & 2 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,14 @@ alter_table_stmt:
// ALTER PARTITION <name> <command>
//
// Commands:
// ALTER PARTITION ... OF TABLE ... CONFIGURE ZONE <zoneconfig>
// ALTER PARTITION ... OF INDEX ... CONFIGURE ZONE <zoneconfig>
// -- Alter a single partition which exists on any of a table's indexes.
// ALTER PARTITION <partition> OF TABLE <tablename> CONFIGURE ZONE <zoneconfig>
//
// -- Alter a partition of a specific index.
// ALTER PARTITION <partition> OF INDEX <tablename>@<indexname> CONFIGURE ZONE <zoneconfig>
//
// -- Alter all partitions with the same name across a table's indexes.
// ALTER PARTITION <partition> OF INDEX <tablename>@* CONFIGURE ZONE <zoneconfig>
//
// Zone configurations:
// DISCARD
Expand Down Expand Up @@ -1499,6 +1505,12 @@ alter_zone_partition_stmt:
s.AllIndexes = true
$$.val = s
}
| ALTER PARTITION partition_name OF TABLE table_name '@' '*' error
{
err := errors.New("index wildcard unsupported in ALTER PARTITION ... OF TABLE")
err = errors.WithHint(err, "try ALTER PARTITION <partition> OF INDEX <tablename>@*")
return setErr(sqllex, err)
}

var_set_list:
var_name '=' COPY FROM PARENT
Expand Down

0 comments on commit 7007e06

Please sign in to comment.