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) #17663

Closed

Conversation

sre-bot
Copy link
Contributor

@sre-bot sre-bot commented Jun 4, 2020

cherry-pick #16537 to release-3.0


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: sre-bot <sre-bot@pingcap.com>
@sre-bot
Copy link
Contributor Author

sre-bot commented Jun 4, 2020

/run-all-tests

@@ -1451,7 +1451,12 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e
go preSplit()
}
}
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

@crazycs520
Please fix the conflict.

@crazycs520 crazycs520 closed this Jun 4, 2020
@tiancaiamao
Copy link
Contributor

Closed by #17668

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants