Skip to content

Commit

Permalink
Merge #40720
Browse files Browse the repository at this point in the history
40720: sql: add hint for ALTER PARTITION OF INDEX error r=solongordon a=solongordon

If a user accidentally passes a table name (or some other non-existent
index name) to ALTER PARTITION ... OF INDEX, they now get a helpful hint
suggesting that the use the `<tablename>@<indexname>` syntax to specify
the index.

Fixes #39477

Release note: None

Co-authored-by: Solon Gordon <solon@cockroachlabs.com>
  • Loading branch information
craig[bot] and solongordon committed Sep 12, 2019
2 parents 7007e06 + 1f9c8d6 commit 4bdf82b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/zone
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ CREATE INDEX x2 ON t2 (x) PARTITION BY LIST (x) (
statement ok
ALTER PARTITION p1 OF INDEX t2@* CONFIGURE ZONE USING num_replicas = 1

statement error index "t2" does not exist\nHINT: try specifying the index as <tablename>@<indexname>
ALTER PARTITION p1 OF INDEX t2 CONFIGURE ZONE USING num_replicas = 1

query TT
SELECT * FROM [SHOW ALL ZONE CONFIGURATIONS] WHERE target LIKE '%t2@%'
----
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/set_zone_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ func (n *setZoneConfigNode) startExec(params runParams) error {
// descriptor.
table, err := params.p.resolveTableForZone(params.ctx, &n.zoneSpecifier)
if err != nil {
if n.zoneSpecifier.TargetsIndex() && n.zoneSpecifier.TableOrIndex.Table.TableName == "" {
return errors.WithHint(err, "try specifying the index as <tablename>@<indexname>")
}
return err
}

Expand Down

0 comments on commit 4bdf82b

Please sign in to comment.