Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TLDR: - hide broken columns from crdb_internal.ranges{,no_leases} - use crdb_internal.index_spans, .table_spans instead - rework SHOW RANGES. - select between "1 row per range" and "1 row per range/object intersection" using new syntax - fix representation of start/end key (see text of release notes below for details) To test this, use for example the following setup: ``` > -- Enable merge of adjacent ranges with same zone config. > set cluster setting spanconfig.host_coalesce_adjacent.enabled = true; > -- Table t has two indexes with some split points. > create table t(x int primary key, y int); > create index sec_idx on t(y); > alter index t@primary split at values(3); > alter index t@sec_idx split at values(3); > -- Tables u and v share a range with t@sec_idx. > create table u(x int); > create table v(x int); > -- Make some other tables with forced split points due to different > -- zone configs. > create schema otherschema; > create table otherschema.w(x int); > create table otherschema.z(x int); > alter table otherschema.w configure zone using num_replicas = 5; > alter table otherschema.z configure zone using num_replicas = 7; ``` Example output for `SHOW RANGES FROM DATABASE`: ``` > show ranges from database defaultdb; -- 1 row per range > show ranges from current_catalog; -- implicit db from session start_key | end_key | range_id | ... -----------------+----------------+----------+---- /Table/104 | /Table/104/1/3 | 56 | ... /Table/104/1/3 | /Table/104/2 | 57 | ... /Table/104/2 | /Table/104/2/3 | 55 | ... /Table/104/2/3 | /Table/108 | 58 | ... /Table/108 | /Table/109 | 59 | ... /Table/109 | /Max | 60 | ... ``` New syntax: `WITH TABLES` / `WITH INDEXES`: ``` > show ranges from database defaultdb with tables; -- 1 row per range/table intersection start_key | end_key | range_id | schema_name | table_name | table_start_key | table_end_key | ... -----------------+----------------+----------+-------------+------------+-----------------+----------------------+---- /Table/104 | /Table/104/1/3 | 56 | public | t | /Table/104 | /Table/105 | ... /Table/104/1/3 | /Table/104/2 | 57 | public | t | /Table/104 | /Table/105 | ... /Table/104/2 | /Table/104/2/3 | 55 | public | t | /Table/104 | /Table/105 | ... /Table/104/2/3 | /Table/108 | 58 | public | t | /Table/104 | /Table/105 | ... /Table/104/2/3 | /Table/108 | 58 | public | u | /Table/105 | /Table/106 | ... /Table/104/2/3 | /Table/108 | 58 | public | v | /Table/106 | /Table/107 | ... /Table/108 | /Table/109 | 59 | otherschema | w | /Table/108 | /Table/109 | ... /Table/109 | /Max | 60 | otherschema | z | /Table/109 | /Table/109/PrefixEnd | ... ``` ``` > show ranges from database defaultdb with indexes; -- 1 row per range/index intersection start_key | end_key | range_id | schema_name | table_name | index_name | index_start_key | index_end_key | ... -----------------+----------------+----------+-------------+------------+------------+-----------------+---------------+---- /Table/104 | /Table/104/1/3 | 56 | public | t | t_pkey | /Table/104/1 | /Table/104/2 | ... /Table/104/1/3 | /Table/104/2 | 57 | public | t | t_pkey | /Table/104/1 | /Table/104/2 | ... /Table/104/2 | /Table/104/2/3 | 55 | public | t | sec_idx | /Table/104/2 | /Table/104/3 | ... /Table/104/2/3 | /Table/108 | 58 | public | t | sec_idx | /Table/104/2 | /Table/104/3 | ... /Table/104/2/3 | /Table/108 | 58 | public | u | u_pkey | /Table/105/1 | /Table/105/2 | ... /Table/104/2/3 | /Table/108 | 58 | public | v | v_pkey | /Table/106/1 | /Table/106/2 | ... /Table/108 | /Table/109 | 59 | otherschema | w | w_pkey | /Table/108/1 | /Table/108/2 | ... /Table/109 | /Max | 60 | otherschema | z | z_pkey | /Table/109/1 | /Table/109/2 | ... ``` Example output for `SHOW RANGES FROM TABLE`: ``` > show ranges from table t; start_key | end_key | range_id | ... ---------------+--------------------+----------+---- …/<TableMin> | …/1/3 | 56 | ... …/1/3 | …/2 | 57 | ... …/2 | …/2/3 | 55 | ... …/2/3 | <after:/Table/108> | 58 | ... ``` ``` > show ranges from table u; start_key | end_key | range_id | ... --------------------------+--------------------+----------+---- <before:/Table/104/2/3> | <after:/Table/108> | 58 | ... ``` ``` > show ranges from table otherschema.w; start_key | end_key | range_id | ... ---------------+--------------+----------+---- …/<TableMin> | …/<TableMax> | 59 | ... ``` New syntax: `SHOW RANGES FROM TABLE ... WITH INDEXES`: ``` > show ranges from table t with indexes; start_key | end_key | range_id | index_name | index_start_key | index_end_key | ... ---------------+--------------------+----------+------------+-----------------+---------------+---- …/<TableMin> | …/1/3 | 56 | t_pkey | …/1 | …/2 | ... …/1/3 | …/<IndexMax> | 57 | t_pkey | …/1 | …/2 | ... …/<IndexMin> | …/2/3 | 55 | sec_idx | …/2 | …/3 | ... …/2/3 | <after:/Table/108> | 58 | sec_idx | …/2 | …/3 | ... ``` ``` > show ranges from table u with indexes; start_key | end_key | range_id | index_name | index_start_key | index_end_key | ... --------------------------+--------------------+----------+------------+-----------------+---------------+---- <before:/Table/104/2/3> | <after:/Table/108> | 58 | u_pkey | …/1 | …/2 | ... ``` ``` > show ranges from table otherschema.w with indexes; start_key | end_key | range_id | index_name | index_start_key | index_end_key | ... ---------------+--------------+----------+------------+-----------------+---------------+---- …/<TableMin> | …/<TableMax> | 59 | w_pkey | …/1 | …/2 | ... ``` Example output for `SHOW RANGES FROM INDEX`: ``` > show ranges from index t@t_pkey; start_key | end_key | range_id | ... ---------------+--------------+----------+---- …/<TableMin> | …/3 | 56 | ... …/3 | …/<IndexMax> | 57 | ... ``` ``` > show ranges from index t@sec_idx; start_key | end_key | range_id | ... ---------------+--------------------+----------+---- …/<IndexMin> | …/3 | 55 | ... …/3 | <after:/Table/108> | 58 | ... ``` ``` > show ranges from index u@u_pkey; start_key | end_key | range_id | ... --------------------------+--------------------+----------+---- <before:/Table/104/2/3> | <after:/Table/108> | 58 | ... ``` ``` > show ranges from index otherschema.w@w_pkey; start_key | end_key | range_id | ... ---------------+--------------+----------+---- …/<TableMin> | …/<TableMax> | 59 | ... ``` See release notes below for details. ---- Release note (backward-incompatible change): CockroachDB now supports sharing storage ranges across multiple indexes/tables. As a result, there is no more guarantee that there is at most one SQL object (e.g. table/index/sequence/materialized view) per storage range. Therefore, the columns `table_id`, `database_name`, `schema_name`, `table_name` and `index_name` in `crdb_internal.ranges` and `.ranges_no_leases` have become nonsensical: a range cannot be attributed to a single table/index any more. As a result: - The aforementioned columns in the `crdb_internal` virtual tables have been marked as hidden, and will now report NULL. - `SHOW RANGES FROM DATABASE` continues to report one row per range, but stops returning the database / schema / table / index name. - `SHOW RANGES FROM TABLE` continues to report one row per range, but stops returning the index name. Summary: | Statement | Row identity | Before | After | |----------------------------------------------------|----------------------------------|----------------------------|----------------------------------| | `SHOW RANGES FROM DATABASE` | rangeID | Includes schema/table name | (NEW) No schema/table name | | `SHOW RANGES FROM TABLE` | rangeID | Includes index name | (NEW) No index name | | `SHOW RANGES FROM INDEX` | rangeID | Includes index name | Unchanged | | `SHOW RANGES FROM DATABASE ... WITH TABLES` (NEW) | rangeID, schema/table name | N/A | Includes schema/table name | | `SHOW RANGES FROM DATABASE ... WITH INDEXES` (NEW) | rangeID, schema/table/index name | N/A | Includes schema/table/index name | | `SHOW RANGES FROM TABLE ... WITH INDEXES` (NEW) | rangeID, index name | N/A | Includes index name | Release note (backward-incompatible change): The format of the columns `start_key` and `end_key` for `SHOW RANGES FROM DATABASE` and `SHOW RANGES FROM TABLE` have been extended to include which table/index the key belong to. This is necessary because a range can now contain data from more than one table/index. Summary: | Statement | Start/end key column, before | Start/end key column, after | |----------------------------------------------------|------------------------------|---------------------------------------| | `SHOW RANGES FROM DATABASE` | Truncates table/index IDs | (NEW) Includes table/index ID | | `SHOW RANGES FROM TABLE` | Truncates table/index IDs | (NEW) Includes table/index ID | | `SHOW RANGES FROM INDEX` | Truncates table/index IDs | Unchanged | | `SHOW RANGES FROM DATABASE ... WITH TABLES` (NEW) | N/A | Includes table/index ID | | `SHOW RANGES FROM DATABASE ... WITH INDEXES` (NEW) | N/A | Includes table/index ID | | `SHOW RANGES FROM TABLE ... WITH INDEXES` (NEW) | N/A | Truncates table ID, includes index ID | Release note (backward-incompatible change): The format of the columns `start_key` and `end_key` for `SHOW RANGE ... FOR ROW` has been changed to stay consistent with the output of `SHOW RANGES FROM INDEX`. Release note (bug fix): In some cases the start/end key columns of the output of `SHOW RANGES` was missing. This was corrected. Release note (sql change): Two new virtual tables `crdb_internal.index_spans` and `.table_spans` have been introduced, which list the logical keyspace used by each index/table. Release note (sql change): The following new statements are introduced: - `SHOW RANGES FROM CURRENT_CATALOG`: alias for `SHOW RANGES FROM DATABASE` on the session's current database. - `SHOW RANGES FROM DATABASE ... WITH TABLES` Reports at least one row per table. It's possible for the same range ID to be repeated across multiple rows, when a range spans multiple tables. - `SHOW RANGES FROM DATABASE ... WITH INDEXES` Reports at least one row per index. It's possible for the same range ID to be repeated across multiple rows, when a range spans multiple indexes. - `SHOW RANGES FROM TABLE ... WITH INDEXES` Reports at least one row per index. It's possible for the same range ID to be repeated across multiple rows, when a range spans multiple indexes. Under the hood, these statements are implemented by means of a join between `crdb_internal.ranges` and `crdb_internal.{index,table}_spans`.
- Loading branch information