Skip to content

Commit 838cfa1

Browse files
committed
sql: add a syntax hint for ALTER PARTITION
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
1 parent 99bed27 commit 838cfa1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pkg/sql/parser/parse_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,14 @@ DETAIL: source SQL:
26832683
CREATE STATISTICS a ON col1 FROM t WITH OPTIONS AS OF SYSTEM TIME '-1s' THROTTLING 0.1 AS OF SYSTEM TIME '-2s'
26842684
^`,
26852685
},
2686+
{
2687+
`ALTER PARTITION p OF TABLE tbl@* CONFIGURE ZONE USING num_replicas = 1`,
2688+
`at or near "configure": syntax error: index wildcard unsupported in ALTER PARTITION ... OF TABLE
2689+
DETAIL: source SQL:
2690+
ALTER PARTITION p OF TABLE tbl@* CONFIGURE ZONE USING num_replicas = 1
2691+
^
2692+
HINT: try ALTER PARTITION <partition> OF INDEX <tablename>@*`,
2693+
},
26862694
}
26872695
for _, d := range testData {
26882696
t.Run(d.sql, func(t *testing.T) {

pkg/sql/parser/sql.y

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,14 @@ alter_table_stmt:
11701170
// ALTER PARTITION <name> <command>
11711171
//
11721172
// Commands:
1173-
// ALTER PARTITION ... OF TABLE ... CONFIGURE ZONE <zoneconfig>
1174-
// ALTER PARTITION ... OF INDEX ... CONFIGURE ZONE <zoneconfig>
1173+
// -- Alter a single partition which exists on any of a table's indexes.
1174+
// ALTER PARTITION <partition> OF TABLE <tablename> CONFIGURE ZONE <zoneconfig>
1175+
//
1176+
// -- Alter a partition of a specific index.
1177+
// ALTER PARTITION <partition> OF INDEX <tablename>@<indexname> CONFIGURE ZONE <zoneconfig>
1178+
//
1179+
// -- Alter all partitions with the same name across a table's indexes.
1180+
// ALTER PARTITION <partition> OF INDEX <tablename>@* CONFIGURE ZONE <zoneconfig>
11751181
//
11761182
// Zone configurations:
11771183
// DISCARD
@@ -1499,6 +1505,12 @@ alter_zone_partition_stmt:
14991505
s.AllIndexes = true
15001506
$$.val = s
15011507
}
1508+
| ALTER PARTITION partition_name OF TABLE table_name '@' '*' error
1509+
{
1510+
err := errors.New("index wildcard unsupported in ALTER PARTITION ... OF TABLE")
1511+
err = errors.WithHint(err, "try ALTER PARTITION <partition> OF INDEX <tablename>@*")
1512+
return setErr(sqllex, err)
1513+
}
15021514

15031515
var_set_list:
15041516
var_name '=' COPY FROM PARENT

0 commit comments

Comments
 (0)