Skip to content

Commit

Permalink
sql: Reorder show ranges output to be clearer
Browse files Browse the repository at this point in the history
The output of show ranges had column orderings that at a quick glance
could lead to users making the wrong conclusions about their
partitioning setup. This PR adjusts the columns and adds more readily
accessible information about the lease_holder node's locality.

Fixes #40467.

Release note (sql change): Reorder columns in show ranges output
  • Loading branch information
rohany committed Sep 5, 2019
1 parent 18bdfe1 commit 24b629d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/sql/delegate/show_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ func (d *delegator) delegateShowRanges(n *tree.ShowRanges) (tree.Statement, erro
END AS end_key,
range_id,
range_size / 1000000 as range_size_mb,
replicas,
lease_holder,
replica_localities,
replica_localities[1] as lease_holder_locality,
replicas,
replica_localities
FROM %[1]s.crdb_internal.ranges AS r
WHERE database_name=%[2]s
ORDER BY table_name, r.start_key
Expand All @@ -71,8 +72,9 @@ SELECT
CASE WHEN r.end_key >= x'%s' THEN NULL ELSE crdb_internal.pretty_key(r.end_key, 2) END AS end_key,
range_id,
range_size / 1000000 as range_size_mb,
replicas,
lease_holder,
replica_localities[1] as lease_holder_locality,
replicas,
replica_localities
FROM crdb_internal.ranges AS r
WHERE (r.start_key < x'%s')
Expand Down
7 changes: 4 additions & 3 deletions pkg/sql/show_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ func TestShowRangesWithLocality(t *testing.T) {
sqlDB.Exec(t, `CREATE TABLE t (x INT PRIMARY KEY)`)
sqlDB.Exec(t, `ALTER TABLE t SPLIT AT SELECT i FROM generate_series(0, 20) AS g(i)`)

const replicasColIdx = 4
const localitiesColIdx = 6
const replicasColIdx = 0
const localitiesColIdx = 1
replicas := make([]int, 3)

result := sqlDB.QueryStr(t, `SHOW RANGES FROM TABLE t`)
q := `SELECT replicas, replica_localities from [SHOW RANGES FROM TABLE t]`
result := sqlDB.QueryStr(t, q)
for _, row := range result {
_, err := fmt.Sscanf(row[replicasColIdx], "{%d,%d,%d}", &replicas[0], &replicas[1], &replicas[2])
if err != nil {
Expand Down

0 comments on commit 24b629d

Please sign in to comment.