From d743ba1985d38630c8399a1b000337d5ddb9dd6f Mon Sep 17 00:00:00 2001 From: Nullnotnil Date: Wed, 22 Jul 2020 11:30:55 -0600 Subject: [PATCH 1/7] sql-statements: improve SHOW TABLE REGIONS examples --- .../sql-statement-show-table-regions.md | 78 +++++++++++++++---- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/sql-statements/sql-statement-show-table-regions.md b/sql-statements/sql-statement-show-table-regions.md index 932c706356d82..d9bb1037e83db 100644 --- a/sql-statements/sql-statement-show-table-regions.md +++ b/sql-statements/sql-statement-show-table-regions.md @@ -57,43 +57,83 @@ Executing `SHOW TABLE REGIONS` returns the following columns: ## Examples +Create an example table with enough data that it fills a few regions: + +{{< copyable "sql" >}} + ```sql -test> create table t (id int key,name varchar(50), index (name)); -Query OK, 0 rows affected +CREATE TABLE t1 ( + id INT NOT NULL PRIMARY KEY auto_increment, + b INT NOT NULL, + pad1 VARBINARY(1024), + pad2 VARBINARY(1024), + pad3 VARBINARY(1024) +); +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM dual; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 10000; +SELECT SLEEP(5); +SHOW TABLE t1 REGIONS; ``` -After a table is created, the table data is stored in a newly split Region by default. In this initial phase, all row data and index data of the table are written into this Region. +The output should show that the table is split into regions. The `REGION_ID`, `START_KEY` and `END_KEY` may not match exactly: ```sql -test> show table t regions; -+-----------+-----------+---------+-----------+-----------------+-----------+------------+---------------+------------+----------------------+------------------+ -| REGION_ID | START_KEY | END_KEY | LEADER_ID | LEADER_STORE_ID | PEERS | SCATTERING | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE(MB) | APPROXIMATE_KEYS | -+-----------+-----------+---------+-----------+-----------------+-----------+------------+---------------+------------+----------------------+------------------+ -| 3 | t_43_ | | 73 | 9 | 5, 73, 93 | 0 | 35 | 0 | 1 | 0 | -+-----------+-----------+---------+-----------+-----------------+-----------+------------+---------------+------------+----------------------+------------------+ -1 row in set +.. +mysql> SHOW TABLE t1 REGIONS; ++-----------+--------------+--------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+ +| REGION_ID | START_KEY | END_KEY | LEADER_ID | LEADER_STORE_ID | PEERS | SCATTERING | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE(MB) | APPROXIMATE_KEYS | ++-----------+--------------+--------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+ +| 94 | t_75_ | t_75_r_31717 | 95 | 1 | 95 | 0 | 0 | 0 | 112 | 207465 | +| 96 | t_75_r_31717 | t_75_r_63434 | 97 | 1 | 97 | 0 | 0 | 0 | 97 | 0 | +| 2 | t_75_r_63434 | | 3 | 1 | 3 | 0 | 269323514 | 66346110 | 245 | 162020 | ++-----------+--------------+--------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+ +3 rows in set (0.00 sec) ``` -In the above result, `t_43_` is the value of `START_KEY` row. In this value, `t` is the table prefix and `43` is the table ID. The value of `END_KEY` row is empty (""), which means that it is an infinite value. +In the output above, a `START_KEY` of `t_75_r_31717` and `END_KEY` of `t_75_r_63434` shows that data with a PRIMARY KEY between `31717` and `63434` will be stored in this region. The prefix `t_75_` indicates that this is the region for a table (`t`) which has an internal table ID of `75`. An empty key value for `START_KEY` or `END_KEY` indicates negative infinity or positive infinity respectively. -Use the `SPLIT TABLE REGION` statement to split row data into five Regions. +TiDB will automatically rebalance regions as needed. For manual rebalancing, use the `SPLIT TABLE REGION` statement: ```sql -test> split table t between (0) and (100000) regions 5; +mysql> SPLIT TABLE t1 BETWEEN (31717) AND (63434) REGIONS 2; +--------------------+----------------------+ | TOTAL_SPLIT_REGION | SCATTER_FINISH_RATIO | +--------------------+----------------------+ -| 5 | 1.0 | +| 1 | 1 | +--------------------+----------------------+ +1 row in set (42.34 sec) + +mysql> SHOW TABLE t1 REGIONS; ++-----------+--------------+--------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+ +| REGION_ID | START_KEY | END_KEY | LEADER_ID | LEADER_STORE_ID | PEERS | SCATTERING | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE(MB) | APPROXIMATE_KEYS | ++-----------+--------------+--------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+ +| 94 | t_75_ | t_75_r_31717 | 95 | 1 | 95 | 0 | 0 | 0 | 112 | 207465 | +| 98 | t_75_r_31717 | t_75_r_47575 | 99 | 1 | 99 | 0 | 1325 | 0 | 53 | 12052 | +| 96 | t_75_r_47575 | t_75_r_63434 | 97 | 1 | 97 | 0 | 1526 | 0 | 48 | 0 | +| 2 | t_75_r_63434 | | 3 | 1 | 3 | 0 | 0 | 55752049 | 60 | 0 | ++-----------+--------------+--------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+ +4 rows in set (0.00 sec) ``` -In the above example: +The above output shows that region 96 was split, with a new region 98 being created. The remaining regions in the table were unaffected by the split operation. This is confirmed by the output statistics: -* `TOTAL_SPLIT_REGION` indicates the number of newly split Regions. In this example, the number is 5. +* `TOTAL_SPLIT_REGION` indicates the number of newly split Regions. In this example, the number is 1. * `SCATTER_FINISH_RATIO` indicates the rate at which the newly split Regions are successfully scattered. `1.0` means that all Regions are scattered. +For a more detailed example: + ```sql -test> show table t regions; +mysql> show table t regions; +-----------+--------------+--------------+-----------+-----------------+---------------+------------+---------------+------------+----------------------+------------------+ | REGION_ID | START_KEY | END_KEY | LEADER_ID | LEADER_STORE_ID | PEERS | SCATTERING | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE(MB) | APPROXIMATE_KEYS | +-----------+--------------+--------------+-----------+-----------------+---------------+------------+---------------+------------+----------------------+------------------+ @@ -155,6 +195,10 @@ test> show table t regions; 7 rows in set ``` +## MySQL compatibility + +This statement is a TiDB extension to MySQL syntax. + ## See also * [SPLIT REGION](/sql-statements/sql-statement-split-region.md) From 35ba8354de0429ab8cc7b19c74c6aa3d8d471f63 Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:00:53 -0600 Subject: [PATCH 2/7] Update sql-statements/sql-statement-show-table-regions.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- sql-statements/sql-statement-show-table-regions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-table-regions.md b/sql-statements/sql-statement-show-table-regions.md index d9bb1037e83db..6613b3637ba0d 100644 --- a/sql-statements/sql-statement-show-table-regions.md +++ b/sql-statements/sql-statement-show-table-regions.md @@ -57,7 +57,7 @@ Executing `SHOW TABLE REGIONS` returns the following columns: ## Examples -Create an example table with enough data that it fills a few regions: +Create an example table with enough data that fills a few Regions: {{< copyable "sql" >}} From 89ec9c4ecf2b95fb1c256066bea0536f9c40cff7 Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:01:00 -0600 Subject: [PATCH 3/7] Update sql-statements/sql-statement-show-table-regions.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- sql-statements/sql-statement-show-table-regions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-table-regions.md b/sql-statements/sql-statement-show-table-regions.md index 6613b3637ba0d..dfd1bcef53575 100644 --- a/sql-statements/sql-statement-show-table-regions.md +++ b/sql-statements/sql-statement-show-table-regions.md @@ -85,7 +85,7 @@ SELECT SLEEP(5); SHOW TABLE t1 REGIONS; ``` -The output should show that the table is split into regions. The `REGION_ID`, `START_KEY` and `END_KEY` may not match exactly: +The output should show that the table is split into Regions. The `REGION_ID`, `START_KEY` and `END_KEY` may not match exactly: ```sql .. From ee8a879d7e90322b7eaac216e989609adda31f30 Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:01:13 -0600 Subject: [PATCH 4/7] Update sql-statements/sql-statement-show-table-regions.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- sql-statements/sql-statement-show-table-regions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-table-regions.md b/sql-statements/sql-statement-show-table-regions.md index dfd1bcef53575..722ab1662c6c1 100644 --- a/sql-statements/sql-statement-show-table-regions.md +++ b/sql-statements/sql-statement-show-table-regions.md @@ -100,7 +100,7 @@ mysql> SHOW TABLE t1 REGIONS; 3 rows in set (0.00 sec) ``` -In the output above, a `START_KEY` of `t_75_r_31717` and `END_KEY` of `t_75_r_63434` shows that data with a PRIMARY KEY between `31717` and `63434` will be stored in this region. The prefix `t_75_` indicates that this is the region for a table (`t`) which has an internal table ID of `75`. An empty key value for `START_KEY` or `END_KEY` indicates negative infinity or positive infinity respectively. +In the output above, a `START_KEY` of `t_75_r_31717` and `END_KEY` of `t_75_r_63434` shows that data with a PRIMARY KEY between `31717` and `63434` is stored in this Region. The prefix `t_75_` indicates that this is the Region for a table (`t`) which has an internal table ID of `75`. An empty key value for `START_KEY` or `END_KEY` indicates negative infinity or positive infinity respectively. TiDB will automatically rebalance regions as needed. For manual rebalancing, use the `SPLIT TABLE REGION` statement: From 40d5f12226c64daaab7b41d9d0963b49ed8953fe Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:01:27 -0600 Subject: [PATCH 5/7] Update sql-statements/sql-statement-show-table-regions.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- sql-statements/sql-statement-show-table-regions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-table-regions.md b/sql-statements/sql-statement-show-table-regions.md index 722ab1662c6c1..a5ba6fd2b9a78 100644 --- a/sql-statements/sql-statement-show-table-regions.md +++ b/sql-statements/sql-statement-show-table-regions.md @@ -125,7 +125,7 @@ mysql> SHOW TABLE t1 REGIONS; 4 rows in set (0.00 sec) ``` -The above output shows that region 96 was split, with a new region 98 being created. The remaining regions in the table were unaffected by the split operation. This is confirmed by the output statistics: +The above output shows that Region 96 was split, with a new Region 98 being created. The remaining Regions in the table were unaffected by the split operation. This is confirmed by the output statistics: * `TOTAL_SPLIT_REGION` indicates the number of newly split Regions. In this example, the number is 1. * `SCATTER_FINISH_RATIO` indicates the rate at which the newly split Regions are successfully scattered. `1.0` means that all Regions are scattered. From 844d575e47ac0916eda0e0af0f6f73513db25e63 Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:01:33 -0600 Subject: [PATCH 6/7] Update sql-statements/sql-statement-show-table-regions.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- sql-statements/sql-statement-show-table-regions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-table-regions.md b/sql-statements/sql-statement-show-table-regions.md index a5ba6fd2b9a78..3077d6d006a19 100644 --- a/sql-statements/sql-statement-show-table-regions.md +++ b/sql-statements/sql-statement-show-table-regions.md @@ -102,7 +102,7 @@ mysql> SHOW TABLE t1 REGIONS; In the output above, a `START_KEY` of `t_75_r_31717` and `END_KEY` of `t_75_r_63434` shows that data with a PRIMARY KEY between `31717` and `63434` is stored in this Region. The prefix `t_75_` indicates that this is the Region for a table (`t`) which has an internal table ID of `75`. An empty key value for `START_KEY` or `END_KEY` indicates negative infinity or positive infinity respectively. -TiDB will automatically rebalance regions as needed. For manual rebalancing, use the `SPLIT TABLE REGION` statement: +TiDB automatically rebalances Regions as needed. For manual rebalancing, use the `SPLIT TABLE REGION` statement: ```sql mysql> SPLIT TABLE t1 BETWEEN (31717) AND (63434) REGIONS 2; From d6a16c4c1af87164ebd0f5351507bbdd1c0b0f6e Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:01:43 -0600 Subject: [PATCH 7/7] Update sql-statements/sql-statement-show-table-regions.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- sql-statements/sql-statement-show-table-regions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-table-regions.md b/sql-statements/sql-statement-show-table-regions.md index 3077d6d006a19..2c76d141a999e 100644 --- a/sql-statements/sql-statement-show-table-regions.md +++ b/sql-statements/sql-statement-show-table-regions.md @@ -88,7 +88,7 @@ SHOW TABLE t1 REGIONS; The output should show that the table is split into Regions. The `REGION_ID`, `START_KEY` and `END_KEY` may not match exactly: ```sql -.. +... mysql> SHOW TABLE t1 REGIONS; +-----------+--------------+--------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+ | REGION_ID | START_KEY | END_KEY | LEADER_ID | LEADER_STORE_ID | PEERS | SCATTERING | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE(MB) | APPROXIMATE_KEYS |