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

ddl: split partition region when add a new partition #16537

Merged
merged 9 commits into from
Apr 24, 2020

Conversation

crazycs520
Copy link
Contributor

Signed-off-by: crazycs520 crazycs520@gmail.com

What problem does this PR solve?

Split new region when add partitions.

before

mysql>create table t (a int, b int,index(a)) PARTITION BY RANGE (a) (
      PARTITION p0 VALUES LESS THAN (10),
      PARTITION p1 VALUES LESS THAN (20),
      PARTITION p2 VALUES LESS THAN (30));
Query OK, 0 rows affected
Time: 0.072s
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 |
+-----------+-----------+---------+-----------+-----------------+------------------+------------+---------------+------------+----------------------+------------------+
| 1748      | t_1363_   | t_1364_ | 1749      | 4               | 1749, 1750, 1751 | 0          | 0             | 0          | 1                    | 0                |
| 1752      | t_1364_   | t_1365_ | 1753      | 4               | 1753, 1754, 1755 | 0          | 0             | 0          | 1                    | 0                |
| 6         | t_1365_   |         | 17        | 4               | 17, 18, 21       | 0          | 214           | 0          | 1                    | 490620           |
+-----------+-----------+---------+-----------+-----------------+------------------+------------+---------------+------------+----------------------+------------------+
3 rows in set
Time: 0.009s
mysql>alter table t add partition ( partition p3 values less than (40), partition p4 values less than (50) );
Query OK, 0 rows affected
Time: 0.070s
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 |
+-----------+-----------+---------+-----------+-----------------+------------------+------------+---------------+------------+----------------------+------------------+
| 1748      | t_1363_   | t_1364_ | 1749      | 4               | 1749, 1750, 1751 | 0          | 0             | 0          | 1                    | 0                |
| 1752      | t_1364_   | t_1365_ | 1753      | 4               | 1753, 1754, 1755 | 0          | 0             | 0          | 1                    | 0                |
| 6         | t_1365_   |         | 17        | 4               | 17, 18, 21       | 0          | 214           | 0          | 1                    | 490620           |
+-----------+-----------+---------+-----------+-----------------+------------------+------------+---------------+------------+----------------------+------------------+
3 rows in set

This PR

mysql>create table t (a int, b int,index(a)) PARTITION BY RANGE (a) (
      PARTITION p0 VALUES LESS THAN (10),
      PARTITION p1 VALUES LESS THAN (20),
      PARTITION p2 VALUES LESS THAN (30));
Query OK, 0 rows affected
Time: 0.073s
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 |
+-----------+-----------+---------+-----------+-----------------+------------------+------------+---------------+------------+----------------------+------------------+
| 1760      | t_1374_   | t_1375_ | 1761      | 4               | 1761, 1762, 1763 | 0          | 0             | 0          | 1                    | 0                |
| 1764      | t_1375_   | t_1376_ | 1765      | 4               | 1765, 1766, 1767 | 0          | 0             | 0          | 1                    | 0                |
| 6         | t_1376_   |         | 17        | 4               | 17, 18, 21       | 0          | 214           | 0          | 1                    | 0                |
+-----------+-----------+---------+-----------+-----------------+------------------+------------+---------------+------------+----------------------+------------------+
3 rows in set
Time: 0.011s
mysql>alter table t add partition ( partition p3 values less than (40), partition p4 values less than (50) )
Query OK, 0 rows affected
Time: 0.071s
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 |
+-----------+-----------+---------+-----------+-----------------+------------------+------------+---------------+------------+----------------------+------------------+
| 1760      | t_1374_   | t_1375_ | 1761      | 4               | 1761, 1762, 1763 | 0          | 0             | 0          | 1                    | 0                |
| 1764      | t_1375_   | t_1376_ | 1765      | 4               | 1765, 1766, 1767 | 0          | 0             | 0          | 1                    | 0                |
| 1768      | t_1376_   | t_1378_ | 1769      | 4               | 1769, 1770, 1771 | 0          | 0             | 0          | 1                    | 0                |
| 1772      | t_1378_   | t_1379_ | 1773      | 4               | 1773, 1774, 1775 | 0          | 0             | 0          | 1                    | 0                |
| 6         | t_1379_   |         | 17        | 4               | 17, 18, 21       | 0          | 214           | 0          | 1                    | 0                |
+-----------+-----------+---------+-----------+-----------------+------------------+------------+---------------+------------+----------------------+------------------+
5 rows in set
Time: 0.011s

What is changed and how it works?

Proposal: xxx

What's Changed:

How it Works:

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Side effects

  • No

Release note

  • Split partition region when adding a new partition

Signed-off-by: crazycs520 <crazycs520@gmail.com>
@crazycs520 crazycs520 requested a review from a team as a code owner April 17, 2020 10:15
@ghost ghost requested review from wshwsh12 and removed request for a team April 17, 2020 10:15
@crazycs520 crazycs520 added the sig/sql-infra SIG: SQL Infra label Apr 17, 2020
@github-actions github-actions bot added the sig/execution SIG execution label Apr 17, 2020
@codecov
Copy link

codecov bot commented Apr 17, 2020

Codecov Report

Merging #16537 into master will decrease coverage by 0.0470%.
The diff coverage is 100.0000%.

@@               Coverage Diff                @@
##             master     #16537        +/-   ##
================================================
- Coverage   80.4155%   80.3685%   -0.0471%     
================================================
  Files           507        507                
  Lines        137303     137127       -176     
================================================
- Hits         110413     110207       -206     
- Misses        18273      18301        +28     
- Partials       8617       8619         +2     

ddl/ddl_api.go Outdated
@@ -1625,7 +1625,9 @@ func (d *ddl) preSplitAndScatter(ctx sessionctx.Context, tbInfo *model.TableInfo
} else {
scatterRegion = variable.TiDBOptOn(val)
}
pi := tbInfo.GetPartitionInfo()
if pi == nil {
pi = tbInfo.GetPartitionInfo()
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me confused.
What's the difference between argument pi and tbInfo.GetPartitionInfo(), are't they the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pi will be the added partition information when AddTablePartitions call this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add comment for this parameter, otherwise when somebody review this code later in the future, he will have the same question.

Copy link
Contributor

@zimulala zimulala Apr 20, 2020

Choose a reason for hiding this comment

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

If AddTablePartitions calls this function and fill with partInfo, pi isn't nil, so why we need to add the check of if pi == nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CreateTableWithInfo will call this function too, then pi will be nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we call d.preSplitAndScatter(ctx, tbInfo, tbInfo.GetPartitionInfo()) to handle it in CreateTableWithInfo?

executor/executor_test.go Show resolved Hide resolved
tiancaiamao added a commit to tiancaiamao/tidb that referenced this pull request Apr 19, 2020
Copy link
Contributor

@tiancaiamao tiancaiamao 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

ddl/ddl_api.go Outdated
@@ -1625,7 +1625,9 @@ func (d *ddl) preSplitAndScatter(ctx sessionctx.Context, tbInfo *model.TableInfo
} else {
scatterRegion = variable.TiDBOptOn(val)
}
pi := tbInfo.GetPartitionInfo()
if pi == nil {
pi = tbInfo.GetPartitionInfo()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add comment for this parameter, otherwise when somebody review this code later in the future, he will have the same question.

Signed-off-by: crazycs520 <crazycs520@gmail.com>
@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 20, 2020
@tiancaiamao
Copy link
Contributor

ref #14478

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 24, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Apr 24, 2020

/run-all-tests

@sre-bot sre-bot merged commit aab9917 into pingcap:master Apr 24, 2020
@crazycs520
Copy link
Contributor Author

/run-cherry-picker

sre-bot pushed a commit to sre-bot/tidb that referenced this pull request Jun 4, 2020
Signed-off-by: sre-bot <sre-bot@pingcap.com>
@sre-bot
Copy link
Contributor

sre-bot commented Jun 4, 2020

cherry pick to release-3.0 in PR #17663

sre-bot pushed a commit to sre-bot/tidb that referenced this pull request Jun 4, 2020
Signed-off-by: sre-bot <sre-bot@pingcap.com>
@sre-bot
Copy link
Contributor

sre-bot commented Jun 4, 2020

cherry pick to release-3.1 in PR #17664

sre-bot pushed a commit to sre-bot/tidb that referenced this pull request Jun 4, 2020
Signed-off-by: sre-bot <sre-bot@pingcap.com>
@sre-bot
Copy link
Contributor

sre-bot commented Jun 4, 2020

cherry pick to release-4.0 in PR #17665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants