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: support range multi-columns #26

Merged
merged 7 commits into from
Oct 14, 2020

Conversation

crazycs520
Copy link
Collaborator

@crazycs520 crazycs520 commented Oct 13, 2020

What problem does this PR solve?

What is changed and how it works?

This PR uses to support range multi-columns partition, both in DDL and DML.

Here is an example:

CREATE TABLE t(
    id INT,
    hired DATE,
    age INT,
	unique index idx (id,hired)
)
PARTITION BY RANGE COLUMNS (id,hired)  (
    PARTITION p0 VALUES LESS THAN (100,'1970-01-01'),
    PARTITION p1 VALUES LESS THAN (200,'1980-01-01'),
    PARTITION p2 VALUES LESS THAN (200,'1990-01-01'),
    PARTITION p3 VALUES LESS THAN (500,'2000-01-01'));

insert into t values  (1, '1960-01-01',20),(101, '1960-01-01',20),(101, '1980-01-02',20),(250, '1960-01-01',20);
select * from t;
select * from t partition (p0);
alter table t drop partition p1;
insert into t values  (500, '1960-01-01',20);
select * from t;
alter table t add partition (partition p4 values less than (600,'2000-01-01'));
insert into t values  (500, '1960-01-01',20);
test> CREATE TABLE t(
   ->     id INT,
   ->         hired DATE,
   ->             age INT,
   ->                 unique index idx (id,hired)
   ->                 )
   ->                 PARTITION BY RANGE COLUMNS (id,hired)  (
   ->                     PARTITION p0 VALUES LESS THAN (100,'1970-01-01'),
   ->                         PARTITION p1 VALUES LESS THAN (200,'1980-01-01'),
   ->                             PARTITION p2 VALUES LESS THAN (200,'1990-01-01'),
   ->                                 PARTITION p3 VALUES LESS THAN (500,'2000-01-01'));
Query OK, 0 rows affected
Time: 0.008s
test> insert into t values  (1, '1960-01-01',20),(101, '1960-01-01',20),(101, '1980-01-02',20),(250, '1960-01-01',20);
Query OK, 4 rows affected
Time: 0.004s
test> select * from t;
+-----+------------+-----+
| id  | hired      | age |
+-----+------------+-----+
| 101 | 1960-01-01 | 20  |
| 250 | 1960-01-01 | 20  |
| 101 | 1980-01-02 | 20  |
| 1   | 1960-01-01 | 20  |
+-----+------------+-----+
4 rows in set
Time: 0.011s
test> select * from t partition (p0);
+----+------------+-----+
| id | hired      | age |
+----+------------+-----+
| 1  | 1960-01-01 | 20  |
+----+------------+-----+
1 row in set
Time: 0.011s
test> alter table t drop partition p1;
Query OK, 0 rows affected
Time: 0.006s
test> insert into t values  (500, '1960-01-01',20);
(1526, 'Table has no partition for value from column_list')
test> select * from t;
+-----+------------+-----+
| id  | hired      | age |
+-----+------------+-----+
| 1   | 1960-01-01 | 20  |
| 250 | 1960-01-01 | 20  |
| 101 | 1980-01-02 | 20  |
+-----+------------+-----+
3 rows in set
Time: 0.011s
test> alter table t add partition (partition p4 values less than (600,'2000-01-01'));
Query OK, 0 rows affected
Time: 0.006s
test> insert into t values  (500, '1960-01-01',20);
Query OK, 1 row affected
Time: 0.001s
test> select * from t;
+-----+------------+-----+
| id  | hired      | age |
+-----+------------+-----+
| 250 | 1960-01-01 | 20  |
| 500 | 1960-01-01 | 20  |
| 1   | 1960-01-01 | 20  |
| 101 | 1980-01-02 | 20  |
+-----+------------+-----+
4 rows in set
Time: 0.011s
test> show create table t;
+-------+-------------------------------------------------------------+
| Table | Create Table                                                |
+-------+-------------------------------------------------------------+
| t     | CREATE TABLE `t` (                                          |
|       |   `id` int(11) DEFAULT NULL,                                |
|       |   `hired` date DEFAULT NULL,                                |
|       |   `age` int(11) DEFAULT NULL,                               |
|       |   UNIQUE KEY `idx` (`id`,`hired`)                           |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
|       | PARTITION BY RANGE COLUMNS(id,hired) (                      |
|       |   PARTITION `p0` VALUES LESS THAN (100,"1970-01-01"),       |
|       |   PARTITION `p2` VALUES LESS THAN (200,"1990-01-01"),       |
|       |   PARTITION `p3` VALUES LESS THAN (500,"2000-01-01"),       |
|       |   PARTITION `p4` VALUES LESS THAN (600,"2000-01-01")        |
|       | )                                                           |
+-------+-------------------------------------------------------------+

Check List

Tests

  • Unit test

Release note

  • No.

Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
@crazycs520
Copy link
Collaborator Author

@tiancaiamao PTAL

@tiancaiamao
Copy link
Collaborator

LGTM

Signed-off-by: crazycs520 <crazycs520@gmail.com>
@crazycs520 crazycs520 merged commit bc113df into bb7133:4.0-itai Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants