Skip to content

Commit

Permalink
Merge #55543
Browse files Browse the repository at this point in the history
55543: sql: make SPLIT AT output be consistent with SHOW_RANGES r=ajwerner a=neeral

This fixes #24740

The output of the SPLIT AT command returns keys in the form
`/Table/52/1/1` whereas the output of SHOW RANGES omits the
prefix, of table id and index id, and displays keys as `/1`.
This is a little confusing and making them consistent would
make it easier to visually compare.

This patch strips the prefix from the keys in the output of
SPLIT AT.

Release note (sql change): pretty column of SPLIT AT output was changed
by stripping prefix. This makes it consistent with output from SHOW
RANGES.

Co-authored-by: neeral <neeral.dodhia@gmail.com>
  • Loading branch information
craig[bot] and neeral committed Oct 20, 2020
2 parents c0f7137 + 3ea77b0 commit 7a576e8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/split_at
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# LogicTest: !3node-tenant

# Test formatting of keys in output of SPLIT AT

statement ok
CREATE TABLE t (a INT PRIMARY KEY)

query TTTI colnames,rowsort
SELECT start_key, end_key, replicas, lease_holder FROM [SHOW RANGES FROM TABLE t]
----
start_key end_key replicas lease_holder
NULL NULL {1} 1

query TTT colnames
ALTER TABLE t SPLIT AT VALUES (1), (10)
----
key pretty split_enforced_until
[189 137 137] /1 2262-04-11 23:47:16.854776 +0000 +0000
[189 137 146] /10 2262-04-11 23:47:16.854776 +0000 +0000

query TTTI colnames,rowsort
SELECT start_key, end_key, replicas, lease_holder FROM [SHOW RANGES FROM TABLE t]
----
start_key end_key replicas lease_holder
NULL /1 {1} 1
/1 /10 {1} 1
/10 NULL {1} 1

statement ok
DROP TABLE t
3 changes: 2 additions & 1 deletion pkg/sql/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
Expand Down Expand Up @@ -74,7 +75,7 @@ func (n *splitNode) Values() tree.Datums {
}
return tree.Datums{
tree.NewDBytes(tree.DBytes(n.run.lastSplitKey)),
tree.NewDString(keys.PrettyPrint(nil /* valDirs */, n.run.lastSplitKey)),
tree.NewDString(catalogkeys.PrettyKey(nil /* valDirs */, n.run.lastSplitKey, 2)),
splitEnforcedUntil,
}
}
Expand Down

0 comments on commit 7a576e8

Please sign in to comment.