-
Notifications
You must be signed in to change notification settings - Fork 1.2k
distribute-table: support to scatter the region distribution of the given table and engine #19534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bufferflies
wants to merge
13
commits into
pingcap:master
Choose a base branch
from
bufferflies:distribute_table
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ca62ac6
add distribute table fd
bufferflies a4fc306
address comment
bufferflies c0b9415
address comment
bufferflies e80d334
add toc changes and anther two sql docs
qiancai 1bdc893
Apply suggestions from code review
qiancai 2bfb0e1
update the file naming style to use hyphen
qiancai acd05fa
Apply suggestions from code review
qiancai 92d3a9c
add cancel job sql
bufferflies c7611d9
conflict
bufferflies 20a6312
split
bufferflies a4ccf2c
address comment
bufferflies 1e9b393
cancel distribution job
bufferflies 51c781b
toc add cancel distribution job link
bufferflies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
title: CANCEL DISTRIBUTION | ||
summary: TiDB 数据库中 CANCEL DISTRIBUTION 的使用情况。 | ||
--- | ||
|
||
# CANCEL IMPORT | ||
|
||
`CANCEL DISTRIBUTION` 语句用于取消 TiDB 中创建的 region 调度任务。 | ||
。 | ||
|
||
## 语法图 | ||
|
||
```ebnf+diagram | ||
CancelImportJobsStmt ::= | ||
'CANCEL' 'DISTRIBUTION' 'JOB' JobID | ||
``` | ||
|
||
## 示例 | ||
|
||
下面示例取消 ID 为 1 的导入任务: | ||
|
||
```sql | ||
CANCEL DISTRIBUTION JOB 1; | ||
``` | ||
|
||
输出结果如下: | ||
|
||
``` | ||
Query OK, 0 rows affected (0.01 sec) | ||
``` | ||
|
||
## MySQL 兼容性 | ||
|
||
该语句是 TiDB 对 MySQL 语法的扩展。 | ||
|
||
## 另请参阅 | ||
|
||
* [`DISTRIBUTE TABLE`](/sql-statements/sql-statement-distribute-table.md) | ||
* [`SHOW DISTRIBUTION JOB`](/sql-statements/sql-statement-show-distribution-jobs.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,106 @@ | ||||||||||||||||||||||||
--- | ||||||||||||||||||||||||
title: DISTRIBUTE TABLE | ||||||||||||||||||||||||
summary: 介绍 TiDB 数据库中 DISTRIBUTE TABLE 的使用概况。 | ||||||||||||||||||||||||
--- | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# DISTRIBUTE TABLE | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
`DISTRIBUTE TABLE` 语句用于对指定表的 Region 进行重新打散和调度,以实现表级别的均衡分布。执行该语句可以防止个别 Region 集中在少数 TiFlash 或 TiKV 节点上,从而解决表中 Region 分布不均衡的问题。 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
## 语法图 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
```ebnf+diagram | ||||||||||||||||||||||||
DistributeTableStmt ::= | ||||||||||||||||||||||||
"DISTRIBUTE" "TABLE" TableName PartitionNameListOpt "RULE" EqOrAssignmentEq Identifier "ENGINE" EqOrAssignmentEq Identifier "TIMEOUT" EqOrAssignmentEq Identifier | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
TableName ::= | ||||||||||||||||||||||||
(SchemaName ".")? Identifier | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
PartitionNameList ::= | ||||||||||||||||||||||||
"PARTITION" "(" PartitionName ("," PartitionName)* ")" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
## 示例 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
通过 `DISTRIBUTE TABLE` 语句重新调度表中的 Region 时,你可以根据需求指定存储引擎(如 TiFlash 或 TiKV)以及不同的 Raft 角色(如 Leader、Learner、Voter)进行均衡打散操作。 | ||||||||||||||||||||||||
timeout: 如果 PD 在改指定时间内没有打散时会退出该任务,默认值为 30m。 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
对表 `t1` 在 TiKV 上的 Leader 所在的 Region 重新进行均衡调度: | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
```sql | ||||||||||||||||||||||||
CREATE TABLE t1 (a INT); | ||||||||||||||||||||||||
... | ||||||||||||||||||||||||
DISTRIBUTE TABLE t1 RULE= `leader-scatter` ENGINE = tikv TIMEOUT=`1h` | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
+---------+ | ||||||||||||||||||||||||
| JOB_ID | | ||||||||||||||||||||||||
100 | ||||||||||||||||||||||||
+---------+ | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
bufferflies marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
对表 `t2` 在 Tiflash 上的 learner 所在的 Region 重新进行均衡调度 | ||||||||||||||||||||||||
```sql | ||||||||||||||||||||||||
CREATE TABLE t2 (a INT); | ||||||||||||||||||||||||
... | ||||||||||||||||||||||||
DISTRIBUTE table t2 RULE = `learner-scatter` ENGINE = tiflash; | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
+---------+ | ||||||||||||||||||||||||
| JOB_ID | | ||||||||||||||||||||||||
101 | ||||||||||||||||||||||||
+---------+ | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
Comment on lines
+52
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
对分区表 `t3· 的 `p1` 和 `p2` 分区在 TiKV 上的 peer 所在的 Region 重新进行均衡调度: | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
```sql | ||||||||||||||||||||||||
CREATE TABLE t3 ( a INT, b INT, INDEX idx(b)) PARTITION BY RANGE( a ) ( | ||||||||||||||||||||||||
PARTITION p1 VALUES LESS THAN (10000), | ||||||||||||||||||||||||
PARTITION p2 VALUES LESS THAN (20000), | ||||||||||||||||||||||||
PARTITION p3 VALUES LESS THAN (MAXVALUE) ); | ||||||||||||||||||||||||
... | ||||||||||||||||||||||||
DISTRIBUTE TABLE t3 PARTITION (p1, p2) RULE = `peer-scatter` ENGINE = tikv; | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
+---------+ | ||||||||||||||||||||||||
| JOB_ID | | ||||||||||||||||||||||||
102 | ||||||||||||||||||||||||
+---------+ | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
对分区表 `t4` 的 `p1` 和 `p2` 分区在 TiKV 上的 Leader 所在的 Region 重新进行均衡调度: | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
```sql | ||||||||||||||||||||||||
CREATE TABLE t4 ( a INT, b INT, INDEX idx(b)) PARTITION BY RANGE( a ) ( | ||||||||||||||||||||||||
PARTITION p1 VALUES LESS THAN (10000), | ||||||||||||||||||||||||
PARTITION p2 VALUES LESS THAN (20000), | ||||||||||||||||||||||||
PARTITION p3 VALUES LESS THAN (MAXVALUE) ); | ||||||||||||||||||||||||
DISTRIBUTE TABLE t4 PARTITION (p1, p2) RULE = `leader-scatter` ENGINE=tiflash; | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
+---------+ | ||||||||||||||||||||||||
| JOB_ID | | ||||||||||||||||||||||||
103 | ||||||||||||||||||||||||
+---------+ | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
## 注意事项 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
`DISTRIBUTE TABLE` 语句在重新调度表中的 Region 时,可能会受到 PD 热点调度器的影响。调度完成后,随着时间推移,表的 Region 分布可能再次失衡。 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
## MySQL 兼容性 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
该语句是 TiDB 对 MySQL 语法的扩展。 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
## 另请参阅 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
- [`SHOW DISTRIBUTION JOBS`](/sql-statements/sql-statement-show-distribution-jobs.md) | ||||||||||||||||||||||||
- [`SHOW TABLE DISTRIBUTION`](/sql-statements/sql-statement-show-table-distribution.md) | ||||||||||||||||||||||||
- [`SHOW TABLE REGIONS`](/sql-statements/sql-statement-show-table-regions.md) | ||||||||||||||||||||||||
- [`CANCEL DISTRIBUTION JOBS`] (/sql-statements/sql-statement-cancel-distribution-job.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: SHOW DISTRIBUTION JOBS | ||
summary: 介绍 TiDB 数据库中 SHOW DISTRIBUTION JOBS 的使用概况。 | ||
--- | ||
|
||
# SHOW DISTRIBUTION JOBS | ||
|
||
`SHOW DISTRIBUTION JOBS` 语句用于显示当前所有的 Region 调度任务。 | ||
|
||
## 语法图 | ||
|
||
```ebnf+diagram | ||
ShowDistributionJobsStmt ::= | ||
"SHOW" "DISTRIBUTION" "JOBS" | ||
``` | ||
|
||
## 示例 | ||
|
||
显示当前所有的 Region 调度任务: | ||
|
||
```sql | ||
SHOW DISTRIBUTION JOBS; | ||
``` | ||
|
||
``` | ||
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+ | ||
| Job_ID | Database | Table | Partition_List | Engine | Rule | Status | Create_Time | Start_Time | Finish_Time | | ||
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+ | ||
| 100 | test | t1 | NULL | tikv | leader-scatter | finished | 2025-04-24 16:09:55 | 2025-04-24 16:09:55 | 2025-04-24 17:09:59 | | ||
| 101 | test | t2 | NULL | tikv | learner-scatter| cancelled | 2025-05-08 15:33:29 | 2025-05-08 15:33:29 | 2025-05-08 15:33:37 | | ||
| 102 | test | t5 | p1,p2 | tikv | peer-scatter | cancelled | 2025-05-21 15:32:44 | 2025-05-21 15:32:47 | 2025-05-21 15:32:47 | | ||
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+ | ||
``` | ||
|
||
## MySQL 兼容性 | ||
|
||
该语句是 TiDB 对 MySQL 语法的扩展。 | ||
|
||
## 另请参阅 | ||
|
||
- [`DISTRIBUTE TABLE`](/sql-statements/sql-statement-distribute-table.md) | ||
- [`SHOW TABLE DISTRIBUTION`](/sql-statements/sql-statement-show-table-distribution.md) | ||
- [`CANCEL DISTRIBUTION JOB`](/sql-statements/sql-statement-cancel-distribution-job.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: SHOW TABLE DISTRIBUTION | ||
summary: 介绍 TiDB 数据库中 SHOW TABLE DISTRIBUTION 的使用概况。 | ||
--- | ||
|
||
# SHOW TABLE DISTRIBUTION | ||
|
||
`SHOW TABLE DISTRIBUTION` 语句用于显示指定表的 Region 分布情况。 | ||
|
||
## 语法图 | ||
|
||
```ebnf+diagram | ||
ShowTableDistributionStmt ::= | ||
"SHOW" "TABLE" "DISTRIBUTION" TableName | ||
|
||
TableName ::= | ||
(SchemaName ".")? Identifier | ||
``` | ||
|
||
## 示例 | ||
|
||
显示当前表 `t1` 的 Region 分布情况: | ||
|
||
```sql | ||
SHOW TABLE DISTRIBUTION t1; | ||
``` | ||
|
||
``` | ||
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+ | ||
| Job_ID | Database | Table | Partition_List | Engine | Rule | Status | Create_Time | Start_Time | Finish_Time | | ||
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+ | ||
| 100 | test | t1 | NULL | tikv | leader-scatter | finished | 2025-04-24 16:09:55 | 2025-04-24 16:09:55 | 2025-04-24 17:09:59 | | ||
| 101 | test | t2 | NULL | tikv | learner-scatter| cancelled | 2025-05-08 15:33:29 | 2025-05-08 15:33:29 | 2025-05-08 15:33:37 | | ||
| 102 | test | t5 | p1,p2 | tikv | peer-scatter | cancelled | 2025-05-21 15:32:44 | 2025-05-21 15:32:47 | 2025-05-21 15:32:47 | | ||
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+ | ||
``` | ||
|
||
## MySQL 兼容性 | ||
|
||
该语句是 TiDB 对 MySQL 语法的扩展。 | ||
|
||
## 另请参阅 | ||
|
||
- [`DISTRIBUTE TABLE`](/sql-statements/sql-statement-distribute-table.md) | ||
- [`SHOW DISTRIBUTION JOBS`](/sql-statements/sql-statement-show-distribution-jobs.md) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.