diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go index ffc70669bc40..ce63bde66ad1 100644 --- a/pkg/sql/crdb_internal.go +++ b/pkg/sql/crdb_internal.go @@ -1591,12 +1591,19 @@ CREATE TABLE crdb_internal.ranges ( if err := r.ValueProto(&desc); err != nil { return nil, err } + + var replicas []int + for _, rd := range desc.Replicas { + replicas = append(replicas, int(rd.StoreID)) + } + sort.Ints(replicas) arr := tree.NewDArray(types.Int) - for _, replica := range desc.Replicas { - if err := arr.Append(tree.NewDInt(tree.DInt(replica.StoreID))); err != nil { + for _, replica := range replicas { + if err := arr.Append(tree.NewDInt(tree.DInt(replica))); err != nil { return nil, err } } + var dbName, tableName, indexName string if _, id, err := keys.DecodeTablePrefix(desc.StartKey.AsRawKey()); err == nil { parent := parents[id] diff --git a/pkg/sql/logictest/testdata/logic_test/ranges b/pkg/sql/logictest/testdata/logic_test/ranges index 35da2e1a3dc5..f3be0fe48b28 100644 --- a/pkg/sql/logictest/testdata/logic_test/ranges +++ b/pkg/sql/logictest/testdata/logic_test/ranges @@ -280,11 +280,11 @@ SELECT * FROM crdb_internal.ranges ---- range_id start_key start_pretty end_key end_pretty database table index replicas lease_holder 1 · /Min [189 137 137] /Table/53/1/1 · · · {1} 1 -2 [189 137 137] /Table/53/1/1 [189 137 141 137] /Table/53/1/5/1 test t · {4,3} 3 -11 [189 137 141 137] /Table/53/1/5/1 [189 137 141 138] /Table/53/1/5/2 test t · {3,1,2} 1 -12 [189 137 141 138] /Table/53/1/5/2 [189 137 141 139] /Table/53/1/5/3 test t · {3,5,2} 5 -13 [189 137 141 139] /Table/53/1/5/3 [189 137 143 144 254 190 137 145] /Table/53/1/7/8/#/54/1/9 test t · {4,1,2} 4 -14 [189 137 143 144 254 190 137 145] /Table/53/1/7/8/#/54/1/9 [189 137 146] /Table/53/1/10 test t · {4,1,2} 4 +2 [189 137 137] /Table/53/1/1 [189 137 141 137] /Table/53/1/5/1 test t · {3,4} 3 +11 [189 137 141 137] /Table/53/1/5/1 [189 137 141 138] /Table/53/1/5/2 test t · {1,2,3} 1 +12 [189 137 141 138] /Table/53/1/5/2 [189 137 141 139] /Table/53/1/5/3 test t · {2,3,5} 5 +13 [189 137 141 139] /Table/53/1/5/3 [189 137 143 144 254 190 137 145] /Table/53/1/7/8/#/54/1/9 test t · {1,2,4} 4 +14 [189 137 143 144 254 190 137 145] /Table/53/1/7/8/#/54/1/9 [189 137 146] /Table/53/1/10 test t · {1,2,4} 4 3 [189 137 146] /Table/53/1/10 [189 137 147] /Table/53/1/11 test t · {1} 1 8 [189 137 147] /Table/53/1/11 [189 137 151 152 254 191 138] /Table/53/1/15/16/#/55/2 test t · {1} 1 9 [189 137 151 152 254 191 138] /Table/53/1/15/16/#/55/2 [189 138 144] /Table/53/2/8 test t · {1} 1