sql: support new sql to redistribution for the given table
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Feature Request
TiDB has provided the sql to show the location of every region. But sometimes users want to detect the hotspot in stores distinct by tikv/tiflash instance.
**Is your feature request related to a problem? Please describe:**
The DBA can use more complex SQL to show the distribution of every instance such as grouping by the table `TIKV_REGION_PEERS` and join in `TIKV_REGION_STATUS`.
**Describe the feature you'd like:**
1. Show the distribution of special instances, such as:
```
show table t1 partition(p0,p2) distribution;
| STORE_ID | STORE_TYPE | REGION_LEADER_NUM | REGION_PEER_NUM | REGION_WRITE_BYTES | REGION_WRITE_KEYS | REGION_WRITE_QUERY | REGION_LEADER_READ_BYTES | REGION_LEADER_READ_KEYS | REGION_LEADER_READ_QUERY | REGION_PEER_READ_BYTES | REGION_PEER_READ_KEYS | REGION_PEER_READ_QUERY |
|----------|------------|-------------------|-----------------|--------------------|-------------------|--------------------|--------------------------|-------------------------|--------------------------|------------------------|-----------------------|------------------------|
| 1 | tikv | 10 | 20 | 200 | 10 | 5 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | tikv | 10 | 20 | 200 | 10 | 5 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3 | tiflash | 0 | 20 | 200 | 10 | 5 | 0 | 0 | 0 | 200 | 30 | 10 |
```
2. Trigger one `balance-keyrange-scheduler` for the special range, such as:
```
DISTRIBUTE TABLE t1 partition(p0,p2) rule= "peer-scatter" engine="tikv"
101
```
3. Check the status of `balance-keyrange-scheduler` jobs, such as:
```
SHOW DISTRIBUTION JOBS [JOB_ID]
| JOB_ID | DB_NAME | TABLE_NAME | PARTITON_LIST | ENGINE | RULE | STATUS | CREATED_TIME | STARTED_TIME | END_TIME |
|--------|---------|------------|---------------|---------|----------|----------|---------------------|---------------------|---------------------|
| 1 | user | t1 | p0,p1 | tikv | leader | finished | 2025-02-25 10:00:00 | 2025-02-25 10:00:00 | 2025-02-25 10:10:00 |
| 2 | user | t2 | p1 | tikv | follower | running | 2025-02-25 10:00:00 | 2025-02-25 10:10:00 | null |
| 3 | user | t2 | p0 | tiflash | learner | pending | 2025-02-25 10:00:00 | null | null |
```
4. Cancel one `balance-keyrange-scheduler` job, such as:
```
cancel distribution job JOB_ID
ok
```
**Describe alternatives you've considered:**
**Teachability, Documentation, Adoption, Migration Strategy:**
Contributor guide
Assessment
This issue has not been assessed yet.