Skip to content
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

*: add show table regions syntax #10612

Merged
merged 30 commits into from
Jul 10, 2019
Merged

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented May 27, 2019

What problem does this PR solve?

Related Parser PR: pingcap/parser#349
Add sql syntax to check split table region status.

SHOW TABLE [table_name] REGIONS

SHOW TABLE [table_name] INDEX [index_name] REGIONS;

What is changed and how it works?

eg

tidb > create table t (a int, b int, index idx(a));
Query OK, 0 rows affected
Time: 0.077s
tidb > split table t between (0) and (10000000000000000) regions 10;
Query OK, 0 rows affected
Time: 0.046s
tidb > split table t index idx between (0) and (1000000000) regions 4;
Query OK, 0 rows affected
Time: 0.408s
mysql>show table t regions;
+-----------+-------------------------------------+-------------------------------------+-----------+-----------------+------------------+------------+
| REGION_ID | START_KEY                           | END_Key                             | LEADER_ID | LEADER_STORE_ID | PEERS            | SCATTERING |
+-----------+-------------------------------------+-------------------------------------+-----------+-----------------+------------------+------------+
| 2173      | t_89_i_1_03800000002cb4178003000000 | t_89_r_1000000000000000             | 2177      | 5               | 2175, 2176, 2177 | 0          |
| 2178      | t_89_r_1000000000000000             | t_89_r_2000000000000000             | 2179      | 6               | 2179, 2183, 2243 | 0          |
| 2184      | t_89_r_2000000000000000             | t_89_r_3000000000000000             | 2186      | 2               | 2186, 2187, 2245 | 0          |
| 2188      | t_89_r_3000000000000000             | t_89_r_4000000000000000             | 2193      | 5               | 2191, 2193, 2192 | 0          |
| 2194      | t_89_r_4000000000000000             | t_89_r_5000000000000000             | 2196      | 2               | 2195, 2196, 2198 | 0          |
| 2199      | t_89_r_5000000000000000             | t_89_r_6000000000000000             | 2202      | 13              | 2201, 2202, 2203 | 0          |
| 2204      | t_89_r_6000000000000000             | t_89_r_7000000000000000             | 2205      | 6               | 2205, 2208, 2241 | 0          |
| 2210      | t_89_r_7000000000000000             | t_89_r_8000000000000000             | 2213      | 13              | 2211, 2212, 2213 | 0          |
| 2214      | t_89_r_8000000000000000             | t_89_r_9000000000000000             | 2218      | 5               | 2217, 2218, 2219 | 0          |
| 3         | t_89_r_9000000000000000             |                                     | 122       | 6               | 122, 2066, 2073  | 0          |
| 2225      | t_89_i_1_                           | t_89_i_1_03800000000ee6b28003000000 | 2228      | 5               | 2227, 2228, 2229 | 0          |
| 2230      | t_89_i_1_03800000000ee6b28003000000 | t_89_i_1_03800000001dcd650003000000 | 2234      | 6               | 2231, 2234, 2235 | 0          |
| 2236      | t_89_i_1_03800000001dcd650003000000 | t_89_i_1_03800000002cb4178003000000 | 2238      | 13              | 2237, 2238, 2239 | 0          |
+-----------+-------------------------------------+-------------------------------------+-----------+-----------------+------------------+------------+
13 rows in set
Time: 0.012s
mysql>show table t index idx regions;
+-----------+-------------------------------------+-------------------------------------+-----------+-----------------+------------------+------------+
| REGION_ID | START_KEY                           | END_Key                             | LEADER_ID | LEADER_STORE_ID | PEERS            | SCATTERING |
+-----------+-------------------------------------+-------------------------------------+-----------+-----------------+------------------+------------+
| 2225      | t_89_i_1_                           | t_89_i_1_03800000000ee6b28003000000 | 2228      | 5               | 2227, 2228, 2229 | 0          |
| 2230      | t_89_i_1_03800000000ee6b28003000000 | t_89_i_1_03800000001dcd650003000000 | 2234      | 6               | 2231, 2234, 2235 | 0          |
| 2236      | t_89_i_1_03800000001dcd650003000000 | t_89_i_1_03800000002cb4178003000000 | 2238      | 13              | 2237, 2238, 2239 | 0          |
| 2173      | t_89_i_1_03800000002cb4178003000000 | t_89_r_1000000000000000             | 2177      | 5               | 2175, 2176, 2177 | 0          |
+-----------+-------------------------------------+-------------------------------------+-----------+-----------------+------------------+------------+

Check List

Tests

  • Unit test

Code changes

Side effects

Related changes

@ngaut
Copy link
Member

ngaut commented May 27, 2019

PTAL @morgo

@morgo
Copy link
Contributor

morgo commented May 27, 2019

Should we call the syntax ADMIN SPLIT TABLE .. instead? It is not a strong preference, but there is an advantage to having all TiDB extensions under one namespace.

@crazycs520
Copy link
Contributor Author

@morgo, Great, I will change this syntax later.

@morgo
Copy link
Contributor

morgo commented May 28, 2019

@morgo, Great, I will change this syntax later.

No problem! Don't feel you have to follow this advice if it doesn't make sense to you. ADMIN commands all explicitly require super privilege for now. If this doesn't make sense to SPLIT TABLE, feel free to take a different path.

@winkyao
Copy link
Contributor

winkyao commented Jun 4, 2019

@morgo ADMIN requires super privilege, it will hurt the usability of SPLIT TABLE statement. So I think to keep SPLIT TABLE syntax is better?

@morgo
Copy link
Contributor

morgo commented Jun 4, 2019

@morgo ADMIN requires super privilege, it will hurt the usability of SPLIT TABLE statement. So I think to keep SPLIT TABLE syntax is better?

@winkyao you are right. We may need to take a look at other admin commands (ADMIN CHECKSUM TABLE) too, but that's a separate discussion. Let's keep it as split for now.

@crazycs520
Copy link
Contributor Author

@morgo , I want to change this syntax to SHOW TABLE table_name [INDEX] [index_name] regions.

Because of I found that syntax is nothing to do with the split table. I can just use this syntax to check the table regions status/information.

@morgo
Copy link
Contributor

morgo commented Jun 11, 2019

@morgo , I want to change this syntax to SHOW TABLE table_name [INDEX] [index_name] regions.

Because of I found that syntax is nothing to do with the split table. I can just use this syntax to check the table regions status/information.

LGTM (assuming this command is read-only of course).

@codecov
Copy link

codecov bot commented Jun 11, 2019

Codecov Report

Merging #10612 into master will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##            master    #10612   +/-   ##
=========================================
  Coverage   81.261%   81.261%           
=========================================
  Files          423       423           
  Lines        91334     91334           
=========================================
  Hits         74219     74219           
  Misses       11822     11822           
  Partials      5293      5293

@crazycs520 crazycs520 changed the title *: add split table status syntax *: add show table regions syntax Jun 11, 2019
executor/show.go Outdated Show resolved Hide resolved
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest LGTM

executor/executor_test.go Outdated Show resolved Hide resolved
executor/show.go Outdated Show resolved Hide resolved
executor/show.go Outdated Show resolved Hide resolved
executor/show.go Outdated Show resolved Hide resolved
executor/show.go Outdated Show resolved Hide resolved
executor/split.go Outdated Show resolved Hide resolved
planner/core/common_plans.go Show resolved Hide resolved
planner/core/planbuilder.go Show resolved Hide resolved
@tiancaiamao
Copy link
Contributor

LGTM @winkyao

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 2, 2019
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crazycs520 crazycs520 added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 10, 2019
@crazycs520
Copy link
Contributor Author

/run-all-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2. type/new-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants