mysql> use test1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show variables like '%partition%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| have_partitioning | YES |
+-------------------+-------+
1 row in set (0.01 sec)
mysql> drop table emp;
Query OK, 0 rows affected (0.03 sec)
mysql> CREATE TABLE emp(empid INT,salary DECIMAL(7,2),birth_date DATE)
-> ENGINE = INNODB
-> PARTITION BY HASH( MONTH(birth_date) )
-> PARTITIONS 6;
Query OK, 0 rows affected (0.08 sec)
mysql> CREATE TABLE emp_1(
-> id INT NOT NULL,
-> ename VARCHAR(30),
-> hired DATE NOT NULL DEFAULT '1970-01-01',
-> separated DATE NOT NULL DEFAULT '9999-12-31',
-> job VARCHAR(30) NOT NULL,
-> store_id INT NOT NULL
-> )
-> PARTITION BY RANGE (store_id)(
-> PARTITION p0 VALUES LESS THAN (10),
-> PARTITION p1 VALUES LESS THAN (20),
-> PARTITION p2 VALUES LESS THAN (30)
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> create table emp_list( id int not null, ename varchar(30), hired date not null default '1970-01-01', separated date not null default '9999-12-31', job varchar(30) not null, store_id int not null ) PARTITION by range(store_id)( PARTITION P0 VALUES LESS THAN (10), PARTITION P1 VALUES LESS THAN (20), PARTITION P2 VALUES LESS THAN (30) );
Query OK, 0 rows affected (0.05 sec)
mysql> alter table emp_list add partition ( partition p3 values less than MAXVALUE);
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> insert into emp_list(id,ename,hired,job,store_id) values
-> ('13259','tomil','2000-01-03','bily',50);
Query OK, 1 row affected (0.01 sec)
mysql> select * from emp_list;
+-------+-------+------------+------------+------+----------+
| id | ename | hired | separated | job | store_id |
+-------+-------+------------+------------+------+----------+
| 13259 | tomil | 2000-01-03 | 9999-12-31 | bily | 50 |
+-------+-------+------------+------------+------+----------+
1 row in set (0.00 sec)
mysql> CREATE TABLE emp_date_new( id INT NOT NULL, ename VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job VARCHAR(30) NOT NULL, store_id INT NOT NULL ) PARTITION BY RANGE COLUMNS (separated) ( PARTITION p0 VALUES LESS THAN ('1995-01-01'), PARTITION p1 VALUES LESS THAN ('2000-01-01'), PARTITION p2 VALUES LESS THAN ('2005-01-01') );
Query OK, 0 rows affected (0.05 sec)
mysql> insert into emp(empid) values ('15');
Query OK, 1 row affected (0.01 sec)
mysql> explain partitions select count(1) from emp \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p0,p1,p2,p3,p4,p5
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 6
Extra:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> select * from emp;
+-------+--------+------------+
| empid | salary | birth_date |
+-------+--------+------------+
| 15 | NULL | NULL |
+-------+--------+------------+
1 row in set (0.00 sec)
mysql> explain partitions select count(1) from emp where empid = 15 \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p0,p1,p2,p3,p4,p5
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 6
Extra: Using where
1 row in set (0.01 sec)
ERROR:
No query specified
mysql> create table expenses( expens_date DATE NOT NULL, category INT, amount DECIMAL(10,3) )PARTITION BY LIST(category)( PARTITION p0 VALUES IN (3,5), PARTITION p1 VALUES IN (1,10), PARTITION p2 VALUES IN (4,9), PARTITION p3 VALUES IN (2), PARTITION p4 VALUES IN (6) );
Query OK, 0 rows affected (0.06 sec)
mysql> CREATE TABLE expenses_1( expense_date DATE NOT NULL, category VARCHAR(30), amount DECIMAL(10,3) ) PARTITION BY LIST COLUMNS (category) ( PARTITION p0 VALUES IN ( 'aaa','bbb'),
PARTITION p1 VALUES IN ('ccc','ddd'),
PARTITION p2 VALUES IN ('eee','fff'),
PARTITION p3 VALUES IN ('ggg','hhh'),
PARTITION p4 VALUES IN ('iii','jjj')
);
Query OK, 0 rows affected (0.06 sec)
mysql> create table rc3( a int, b int) PARTITION BY RANGE COLUMNS(a,b)( PARTITION p01 VALUES less than (0,10), PARTITION p02 VALUES less than (10,15), PARTITION P03 values less than (10,MAXVALUE), PARTITION p04 values less than (MAXVALUE,MAXVALUE) );
Query OK, 0 rows affected (0.07 sec)
mysql> insert into rc3(a) value (3);
Query OK, 1 row affected (0.00 sec)
mysql> select (1,10) < (10,10) from dul;
ERROR 1146 (42S02): Table 'test1.dul' doesn't exist
mysql> select (1,10) < (10,10) from dual;
+------------------+
| (1,10) < (10,10) |
+------------------+
| 1 |
+------------------+
1 row in set (0.01 sec)
mysql> select partition_name part, partition_expression expr, partition_description descr, table_rows from information_schema.partitions where table_schema=schema() and table_name='rc3';
+------+---------+-------------------+------------+
| part | expr | descr | table_rows |
+------+---------+-------------------+------------+
| p01 | `a`,`b` | 0,10 | 0 |
| p02 | `a`,`b` | 10,15 | 1 |
| P03 | `a`,`b` | 10,MAXVALUE | 0 |
| p04 | `a`,`b` | MAXVALUE,MAXVALUE | 0 |
+------+---------+-------------------+------------+
4 rows in set (0.00 sec)
mysql> insert into rc3(a) value (5);
Query OK, 1 row affected (0.01 sec)
mysql> select partition_name part, partition_expression expr, partition_description descr, table_rows from information_schema.partitions where table_schema=schema() and table_name='rc3';
+------+---------+-------------------+------------+
| part | expr | descr | table_rows |
+------+---------+-------------------+------------+
| p01 | `a`,`b` | 0,10 | 0 |
| p02 | `a`,`b` | 10,15 | 2 |
| P03 | `a`,`b` | 10,MAXVALUE | 0 |
| p04 | `a`,`b` | MAXVALUE,MAXVALUE | 0 |
+------+---------+-------------------+------------+
4 rows in set (0.01 sec)
mysql> truncate rc3;
Query OK, 0 rows affected (0.03 sec)
mysql> insert into rc3(a,b) values (10,9);
Query OK, 1 row affected (0.01 sec)
mysql> select partition_name part, partition_expression expr, partition_description descr, table_rows from information_schema.partitions where table_schema=schema() and table_name='rc3';
+------+---------+-------------------+------------+
| part | expr | descr | table_rows |
+------+---------+-------------------+------------+
| p01 | `a`,`b` | 0,10 | 0 |
| p02 | `a`,`b` | 10,15 | 1 |
| P03 | `a`,`b` | 10,MAXVALUE | 0 |
| p04 | `a`,`b` | MAXVALUE,MAXVALUE | 0 |
+------+---------+-------------------+------------+
4 rows in set (0.00 sec)
mysql> select (10,9)<(10,10) from dual;
+----------------+
| (10,9)<(10,10) |
+----------------+
| 1 |
+----------------+
1 row in set (0.00 sec)
mysql> insert into rc3(a,b) values(10,10);
Query OK, 1 row affected (0.01 sec)
mysql> select (10,10)<(10,10) from dual;
+-----------------+
| (10,10)<(10,10) |
+-----------------+
| 0 |
+-----------------+
1 row in set (0.00 sec)
mysql> insert into rc3(a,b) values(0,6);
Query OK, 1 row affected (0.01 sec)
mysql> select (10,10)<(10,10) from dual;
+-----------------+
| (10,10)<(10,10) |
+-----------------+
| 0 |
+-----------------+
1 row in set (0.00 sec)
mysql> select partition_name part, partition_expression expr, partition_description descr, table_rows from information_schema.partitions where table_schema=schema() and table_name='rc3';
+------+---------+-------------------+------------+
| part | expr | descr | table_rows |
+------+---------+-------------------+------------+
| p01 | `a`,`b` | 0,10 | 1 |
| p02 | `a`,`b` | 10,15 | 2 |
| P03 | `a`,`b` | 10,MAXVALUE | 0 |
| p04 | `a`,`b` | MAXVALUE,MAXVALUE | 0 |
+------+---------+-------------------+------------+
4 rows in set (0.00 sec)
mysql> drop table emp;
Query OK, 0 rows affected (0.05 sec)
mysql> CREATE TABLE emp(
-> id INT NOT NULL,
-> ename VARCHAR(30),
-> hired DATE NOT NULL DEFAULT '1970-01-01',
-> separated DATE NOT NULL DEFAULT '9999-12-31',
-> job VARCHAR(30) NOT NULL,
-> store_id INT NOT NULL
-> )
-> PARTITION BY HASH ( store_id ) PARTITIONS 4;
Query OK, 0 rows affected (0.05 sec)
mysql> insert into emp values
-> (1,'Tom','2010-12-03','9999-12-31','Cling',235);
Query OK, 1 row affected (0.01 sec)
mysql> explain partitions
-> select * from emp where store_id = 235 \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p3
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 2
Extra: Using where
1 row in set (0.01 sec)
ERROR:
No query specified
mysql> drop table emp;
PARTITION BY LINEAR HASH ( store_id ) PARTITIONS 4;Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE emp(
-> id INT NOT NULL,
-> ename VARCHAR(30),
-> hired DATE NOT NULL DEFAULT '1970-01-01',
-> separated DATE NOT NULL DEFAULT '9999-12-31',
-> job VARCHAR(30) NOT NULL,
-> store_id INT NOT NULL
-> )
-> PARTITION BY LINEAR HASH ( store_id ) PARTITIONS 4;
Query OK, 0 rows affected (0.06 sec)
mysql> insert into emp values (1,'Tom','2010-12-03','9999-12-31','Cling',235);
Query OK, 1 row affected (0.01 sec)
mysql> explain partitions select * from emp where store_id = 235\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p3
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 2
Extra: Using where
1 row in set (0.00 sec)
mysql> drop table emp;
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE emp(
-> id INT NOT NULL,
-> ename VARCHAR(30),
-> hired DATE NOT NULL DEFAULT '1970-01-01',
-> separated DATE NOT NULL DEFAULT '9999-12-31',
-> job VARCHAR(30) NOT NULL,
-> store_id INT NOT NULL
-> )
-> PARTITION BY KEY (job) PARTITIONS 4;
Query OK, 0 rows affected (0.05 sec)
mysql> insert into emp values (1,'Tom','2010-12-03','9999-12-31','Cling',3);
Query OK, 1 row affected (0.01 sec)
mysql> explain partitions select * from emp where store_id = 3 \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p0,p1,p2,p3
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4
Extra: Using where
1 row in set (0.00 sec)
mysql> explain partitions select * from emp where store_id = 1 \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p0,p1,p2,p3
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4
Extra: Using where
1 row in set (0.00 sec)
mysql> explain partitions select * from emp where id = 3 \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p0,p1,p2,p3
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4
Extra: Using where
1 row in set (0.01 sec)
mysql> select * from emp where id = 3 ;
Empty set (0.00 sec)
mysql> select * from emp where id = 1 ;
+----+-------+------------+------------+-------+----------+
| id | ename | hired | separated | job | store_id |
+----+-------+------------+------------+-------+----------+
| 1 | Tom | 2010-12-03 | 9999-12-31 | Cling | 3 |
+----+-------+------------+------------+-------+----------+
1 row in set (0.00 sec)
mysql> explain partitions select * from emp where id = 1 \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p0,p1,p2,p3
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4
Extra: Using where
1 row in set (0.00 sec)
mysql> drop table emp;
PARTITION BY KEY () PARTITIONS 4;Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE emp(
-> id INT NOT NULL,
-> ename VARCHAR(30),
-> hired DATE NOT NULL DEFAULT '1970-01-01',
-> separated DATE NOT NULL DEFAULT '9999-12-31',
-> job VARCHAR(30) NOT NULL,
-> store_id INT NOT NULL ,
-> PRIMARY KEY (id)
-> )
-> PARTITION BY KEY () PARTITIONS 4;
Query OK, 0 rows affected (0.03 sec)
mysql> insert into emp values (1,'Tom','2010-12-03','9999-12-31','Cling',3);
Query OK, 1 row affected (0.00 sec)
mysql> explain partitions select * from emp where id = 3 \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: NULL
partitions: NULL
type: NULL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: NULL
Extra: Impossible WHERE noticed after reading const tables
1 row in set (0.00 sec)
mysql> explain partitions select * from emp where id = 1 \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emp
partitions: p0
type: const
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: const
rows: 1
Extra:
1 row in set (0.00 sec)
mysql> drop table emp;
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE emp(
-> id INT NOT NULL,
-> ename VARCHAR(30),
-> hired DATE NOT NULL DEFAULT '1970-01-01',
-> separated DATE NOT NULL DEFAULT '9999-12-31',
-> job VARCHAR(30) NOT NULL,
-> store_id INT NOT NULL ,
-> UNIQUE KEY (id)
-> )
-> PARTITION BY KEY () PARTITIONS 4;
Query OK, 0 rows affected (0.04 sec)
mysql> drop table emp;
NIQUE KEY (id,ename)
)
PARTITION BY KEY () PARTITIONS 4;Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE test_partition(id INT,purchased DATE)
-> PARTITION BY RANGE(YEAR(purchased))
-> SUBPARTITION BY HASH(TO_DAYS(purchased))
-> SUBPARTITIONS 2
-> (
-> PARTITION p0 VALUES LESS THAN (1990),
-> PARTITION p1 VALUES LESS THAN (2000),
-> PARTITION p2 VALUES LESS THAN MAXVALUE
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> CREATE TABLE tb_range(
-> id INT,
-> name VARCHAR(5)
-> )
-> PARTITION BY RANGE(id)(
-> PARTITION p0 VALUES LESS THAN (-6),
-> PARTITION P1 VALUES LESS THAN (0),
-> PARTITION p2 VALUES LESS THAN (1),
-> PARTITION p3 VALUES LESS THAN MAXVALUE
-> );
Query OK, 0 rows affected (0.05 sec)
mysql> insert into tb_range values (null,'NULL');
Query OK, 1 row affected (0.02 sec)
mysql> SELECT
-> partition_name part,
-> partition_expression expr,
-> partition_description descr,
-> table_rows
-> FROM
-> INFORMATION_SCHEMA.partitions
-> WHERE
-> TABLE_SCHEMA = schema()
-> AND TABLE_NAME='tb_range';
+------+------+----------+------------+
| part | expr | descr | table_rows |
+------+------+----------+------------+
| p0 | id | -6 | 1 |
| P1 | id | 0 | 0 |
| p2 | id | 1 | 0 |
| p3 | id | MAXVALUE | 0 |
+------+------+----------+------------+
4 rows in set (0.02 sec)
mysql> CREATE TABLE tb_list(
-> id INT,
-> name VARCHAR(5)
-> )
-> PARTITION BY LIST(id)(
-> PARTITION p1 VALUES IN (0),
-> PARTITION p2 VALUES IN (1)
-> );
Query OK, 0 rows affected (0.08 sec)
mysql> insert into tb_list values (null,'NULL');
ERROR 1526 (HY000): Table has no partition for value NULL
mysql> drop table tb_list;
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE tb_list(
-> id INT,
-> name VARCHAR(5)
-> )
-> PARTITION BY LIST(id)(
-> PARTITION p1 VALUES IN (0,NULL),
-> PARTITION p2 VALUES IN (1)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> insert into tb_list values (NULL,'NULL');
Query OK, 1 row affected (0.02 sec)
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='tb_range';
+------+------+----------+------------+
| part | expr | descr | table_rows |
+------+------+----------+------------+
| p0 | id | -6 | 1 |
| P1 | id | 0 | 0 |
| p2 | id | 1 | 0 |
| p3 | id | MAXVALUE | 0 |
+------+------+----------+------------+
4 rows in set (0.00 sec)
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='tb_list';
+------+------+--------+------------+
| part | expr | descr | table_rows |
+------+------+--------+------------+
| p1 | id | NULL,0 | 1 |
| p2 | id | 1 | 0 |
+------+------+--------+------------+
2 rows in set (0.00 sec)
mysql> CREATE TABLE tb_hash( id INT, name VARCHAR(5) ) PARTITION BY HASH(id) PARTITIONS 2;
Query OK, 0 rows affected (0.02 sec)
mysql> insert into tb_hash values (null,'NULL');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='tb_hash';
+------+------+-------+------------+
| part | expr | descr | table_rows |
+------+------+-------+------------+
| p0 | id | NULL | 1 |
| p1 | id | NULL | 0 |
+------+------+-------+------------+
2 rows in set (0.00 sec)
mysql> desc emp_date \G;
*************************** 1. row ***************************
Field: id
Type: int(11)
Null: NO
Key:
Default: NULL
Extra:
*************************** 2. row ***************************
Field: ename
Type: varchar(30)
Null: YES
Key:
Default: NULL
Extra:
*************************** 3. row ***************************
Field: hired
Type: date
Null: NO
Key:
Default: 1970-01-01
Extra:
*************************** 4. row ***************************
Field: separated
Type: date
Null: NO
Key:
Default: 9999-12-31
Extra:
*************************** 5. row ***************************
Field: job
Type: varchar(30)
Null: NO
Key:
Default: NULL
Extra:
*************************** 6. row ***************************
Field: store_id
Type: int(11)
Null: NO
Key:
Default: NULL
Extra:
6 rows in set (0.01 sec)
ERROR:
No query specified
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> drop table emp_date;
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE emp_date( id INT NOT NULL, ename VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job VARCHAR(30) NOT NULL, store_id INT NOT NULL ) PARTITION BY RANGE ( YEAR(separated) ) ( PARTITION p0 VALUES LESS THAN (1995), PARTITION p1 VALUES LESS THAN (2000), PARTITION p2 VALUES LESS THAN (2005), PARTITION p3 VALUES LESS THAN (2015) );
Query OK, 0 rows affected (0.06 sec)
mysql> insert into emp_date (id,ename,hired,separated,job,store_id) values
-> (7001,'aaaa','1981-01-01','2005-03-03','bbbbbbb',10),
-> (7300,'dddd','1982-02-01','2006-03-03','ddddddd',30),
-> (7600,'eeeedsfkasjdiwaer','1987-03-01','2073-03-5','adksjfakre',60);
mysql> insert into emp_date (id,ename,hired,separated,job,store_id) values (7001,'aaaa','1981-01-01','2005-03-03','bbbbbbb',10), (7300,'dddd','1982-02-01','2006-03-03','ddddddd',30), (7600,'eeeedsfkasjdiwaer','1987-03-01','2003-03-5','adksjfakre',60);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from emp_date
-> where separated between '2005-01-01' and '2010-12-31';
+------+-------+------------+------------+---------+----------+
| id | ename | hired | separated | job | store_id |
+------+-------+------------+------------+---------+----------+
| 7001 | aaaa | 1981-01-01 | 2005-03-03 | bbbbbbb | 10 |
| 7300 | dddd | 1982-02-01 | 2006-03-03 | ddddddd | 30 |
+------+-------+------------+------------+---------+----------+
2 rows in set (0.01 sec)
mysql> select * from emp_date where separated between '2005-01-01' and '2015-12-31';
+------+-------+------------+------------+---------+----------+
| id | ename | hired | separated | job | store_id |
+------+-------+------------+------------+---------+----------+
| 7001 | aaaa | 1981-01-01 | 2005-03-03 | bbbbbbb | 10 |
| 7300 | dddd | 1982-02-01 | 2006-03-03 | ddddddd | 30 |
+------+-------+------------+------------+---------+----------+
2 rows in set (0.00 sec)
mysql> alter table emp_date drop partition p3;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> select * from emp_date where separated between '2005-01-01' and '2015-12-31';
Empty set (0.00 sec)
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB) */
1 row in set (0.01 sec)
ERROR:
No query specified
mysql> insert into emp_date (id,ename,hired,separated,job,store_id) values (7300,'dddd','1982-02-01','2001-03-03','ddddddd',30), (7600,'eeeedsfkasjdiwaer','1987-03-01','2003-03-5','adksjfakre',60);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='tb_hash';
+------+------+-------+------------+
| part | expr | descr | table_rows |
+------+------+-------+------------+
| p0 | id | NULL | 1 |
| p1 | id | NULL | 0 |
+------+------+-------+------------+
2 rows in set (0.01 sec)
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='emp_date';
+------+------------------+-------+------------+
| part | expr | descr | table_rows |
+------+------------------+-------+------------+
| p0 | YEAR(separated) | 1995 | 0 |
| p1 | YEAR(separated) | 2000 | 0 |
| p2 | YEAR(separated) | 2005 | 3 |
+------+------------------+-------+------------+
3 rows in set (0.00 sec)
mysql> insert into emp_date (id,ename,hired,separated,job,store_id) values (7300,'dddd','1982-02-01','1996-03-03','ddddddd',30), (7600,'eeeedsfkasjdiwaer','1987-03-01','1997-03-5','adksjfakre',60);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='emp_date';
+------+------------------+-------+------------+
| part | expr | descr | table_rows |
+------+------------------+-------+------------+
| p0 | YEAR(separated) | 1995 | 0 |
| p1 | YEAR(separated) | 2000 | 2 |
| p2 | YEAR(separated) | 2005 | 3 |
+------+------------------+-------+------------+
3 rows in set (0.00 sec)
mysql> alter table emp_date add partition ( partition p4 values less than (2030));
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> alter table emp_date add partition ( partition p4 values less than (2050));
ERROR 1517 (HY000): Duplicate partition name p4
mysql> show create table expenses \G;
*************************** 1. row ***************************
Table: expenses
Create Table: CREATE TABLE `expenses` (
`expens_date` date NOT NULL,
`category` int(11) DEFAULT NULL,
`amount` decimal(10,3) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY LIST (category)
(PARTITION p0 VALUES IN (3,5) ENGINE = InnoDB,
PARTITION p1 VALUES IN (1,10) ENGINE = InnoDB,
PARTITION p2 VALUES IN (4,9) ENGINE = InnoDB,
PARTITION p3 VALUES IN (2) ENGINE = InnoDB,
PARTITION p4 VALUES IN (6) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> alter table expenses add partition ( partition p5 values in (7,8));
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table expenses \G;
*************************** 1. row ***************************
Table: expenses
Create Table: CREATE TABLE `expenses` (
`expens_date` date NOT NULL,
`category` int(11) DEFAULT NULL,
`amount` decimal(10,3) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY LIST (category)
(PARTITION p0 VALUES IN (3,5) ENGINE = InnoDB,
PARTITION p1 VALUES IN (1,10) ENGINE = InnoDB,
PARTITION p2 VALUES IN (4,9) ENGINE = InnoDB,
PARTITION p3 VALUES IN (2) ENGINE = InnoDB,
PARTITION p4 VALUES IN (6) ENGINE = InnoDB,
PARTITION p5 VALUES IN (7,8) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> alter table emp_date reorganize partition p4 into ( partition p5 values less than (2010), partition p6 values less than (2030) );
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create emp_date \G;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'emp_date' at line 1
ERROR:
No query specified
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p5 VALUES LESS THAN (2010) ENGINE = InnoDB,
PARTITION p6 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.01 sec)
ERROR:
No query specified
mysql> CREATE TABLE tb_range(
-> id INT,
-> name VARCHAR(5)
-> )
-> PARTITION BY RANGE(id)(
-> PARTITION p0 VALUES LESS THAN (-6),
-> PARTITION P1 VALUES LESS THAN (0),
-> PARTITION p2 VALUES LESS THAN (1),
-> PARTITION p3 VALUES LESS THAN MAXVALUE
-> );
Query OK, 0 rows affected (0.05 sec)
mysql> insert into tb_range values (null,'NULL');
Query OK, 1 row affected (0.02 sec)
mysql> SELECT
-> partition_name part,
-> partition_expression expr,
-> partition_description descr,
-> table_rows
-> FROM
-> INFORMATION_SCHEMA.partitions
-> WHERE
-> TABLE_SCHEMA = schema()
-> AND TABLE_NAME='tb_range';
+------+------+----------+------------+
| part | expr | descr | table_rows |
+------+------+----------+------------+
| p0 | id | -6 | 1 |
| P1 | id | 0 | 0 |
| p2 | id | 1 | 0 |
| p3 | id | MAXVALUE | 0 |
+------+------+----------+------------+
4 rows in set (0.02 sec)
mysql> CREATE TABLE tb_list(
-> id INT,
-> name VARCHAR(5)
-> )
-> PARTITION BY LIST(id)(
-> PARTITION p1 VALUES IN (0),
-> PARTITION p2 VALUES IN (1)
-> );
Query OK, 0 rows affected (0.08 sec)
mysql> insert into tb_list values (null,'NULL');
ERROR 1526 (HY000): Table has no partition for value NULL
mysql> drop table tb_list;
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE tb_list(
-> id INT,
-> name VARCHAR(5)
-> )
-> PARTITION BY LIST(id)(
-> PARTITION p1 VALUES IN (0,NULL),
-> PARTITION p2 VALUES IN (1)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> insert into tb_list values (NULL,'NULL');
Query OK, 1 row affected (0.02 sec)
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='tb_range';
+------+------+----------+------------+
| part | expr | descr | table_rows |
+------+------+----------+------------+
| p0 | id | -6 | 1 |
| P1 | id | 0 | 0 |
| p2 | id | 1 | 0 |
| p3 | id | MAXVALUE | 0 |
+------+------+----------+------------+
4 rows in set (0.00 sec)
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='tb_list';
+------+------+--------+------------+
| part | expr | descr | table_rows |
+------+------+--------+------------+
| p1 | id | NULL,0 | 1 |
| p2 | id | 1 | 0 |
+------+------+--------+------------+
2 rows in set (0.00 sec)
mysql> CREATE TABLE tb_hash( id INT, name VARCHAR(5) ) PARTITION BY HASH(id) PARTITIONS 2;
Query OK, 0 rows affected (0.02 sec)
mysql> insert into tb_hash values (null,'NULL');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='tb_hash';
+------+------+-------+------------+
| part | expr | descr | table_rows |
+------+------+-------+------------+
| p0 | id | NULL | 1 |
| p1 | id | NULL | 0 |
+------+------+-------+------------+
2 rows in set (0.00 sec)
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> drop table emp_date;
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE emp_date( id INT NOT NULL, ename VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job VARCHAR(30) NOT NULL, store_id INT NOT NULL ) PARTITION BY RANGE ( YEAR(separated) ) ( PARTITION p0 VALUES LESS THAN (1995), PARTITION p1 VALUES LESS THAN (2000), PARTITION p2 VALUES LESS THAN (2005), PARTITION p3 VALUES LESS THAN (2015) );
Query OK, 0 rows affected (0.06 sec)
mysql> insert into emp_date (id,ename,hired,separated,job,store_id) values (7001,'aaaa','1981-01-01','2005-03-03','bbbbbbb',10), (7300,'dddd','1982-02-01','2006-03-03','ddddddd',30), (7600,'eeeedsfkasjdiwaer','1987-03-01','2003-03-5','adksjfakre',60);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from emp_date
-> where separated between '2005-01-01' and '2010-12-31';
+------+-------+------------+------------+---------+----------+
| id | ename | hired | separated | job | store_id |
+------+-------+------------+------------+---------+----------+
| 7001 | aaaa | 1981-01-01 | 2005-03-03 | bbbbbbb | 10 |
| 7300 | dddd | 1982-02-01 | 2006-03-03 | ddddddd | 30 |
+------+-------+------------+------------+---------+----------+
2 rows in set (0.01 sec)
mysql> select * from emp_date where separated between '2005-01-01' and '2015-12-31';
+------+-------+------------+------------+---------+----------+
| id | ename | hired | separated | job | store_id |
+------+-------+------------+------------+---------+----------+
| 7001 | aaaa | 1981-01-01 | 2005-03-03 | bbbbbbb | 10 |
| 7300 | dddd | 1982-02-01 | 2006-03-03 | ddddddd | 30 |
+------+-------+------------+------------+---------+----------+
2 rows in set (0.00 sec)
mysql> alter table emp_date drop partition p3;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> select * from emp_date where separated between '2005-01-01' and '2015-12-31';
Empty set (0.00 sec)
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB) */
1 row in set (0.01 sec)
ERROR:
No query specified
mysql> insert into emp_date (id,ename,hired,separated,job,store_id) values (7300,'dddd','1982-02-01','2001-03-03','ddddddd',30), (7600,'eeeedsfkasjdiwaer','1987-03-01','2003-03-5','adksjfakre',60);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='tb_hash';
+------+------+-------+------------+
| part | expr | descr | table_rows |
+------+------+-------+------------+
| p0 | id | NULL | 1 |
| p1 | id | NULL | 0 |
+------+------+-------+------------+
2 rows in set (0.01 sec)
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='emp_date';
+------+------------------+-------+------------+
| part | expr | descr | table_rows |
+------+------------------+-------+------------+
| p0 | YEAR(separated) | 1995 | 0 |
| p1 | YEAR(separated) | 2000 | 0 |
| p2 | YEAR(separated) | 2005 | 3 |
+------+------------------+-------+------------+
3 rows in set (0.00 sec)
mysql> insert into emp_date (id,ename,hired,separated,job,store_id) values (7300,'dddd','1982-02-01','1996-03-03','ddddddd',30), (7600,'eeeedsfkasjdiwaer','1987-03-01','1997-03-5','adksjfakre',60);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT partition_name part, partition_expression expr, partition_description descr, table_rows FROM INFORMATION_SCHEMA.partitions WHERE TABLE_SCHEMA = schema() AND TABLE_NAME='emp_date';
+------+------------------+-------+------------+
| part | expr | descr | table_rows |
+------+------------------+-------+------------+
| p0 | YEAR(separated) | 1995 | 0 |
| p1 | YEAR(separated) | 2000 | 2 |
| p2 | YEAR(separated) | 2005 | 3 |
+------+------------------+-------+------------+
3 rows in set (0.00 sec)
mysql> alter table emp_date add partition ( partition p4 values less than (2030));
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> alter table emp_date add partition ( partition p4 values less than (2050));
ERROR 1517 (HY000): Duplicate partition name p4
mysql> show create table expenses \G;
*************************** 1. row ***************************
Table: expenses
Create Table: CREATE TABLE `expenses` (
`expens_date` date NOT NULL,
`category` int(11) DEFAULT NULL,
`amount` decimal(10,3) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY LIST (category)
(PARTITION p0 VALUES IN (3,5) ENGINE = InnoDB,
PARTITION p1 VALUES IN (1,10) ENGINE = InnoDB,
PARTITION p2 VALUES IN (4,9) ENGINE = InnoDB,
PARTITION p3 VALUES IN (2) ENGINE = InnoDB,
PARTITION p4 VALUES IN (6) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> alter table expenses add partition ( partition p5 values in (7,8));
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table expenses \G;
*************************** 1. row ***************************
Table: expenses
Create Table: CREATE TABLE `expenses` (
`expens_date` date NOT NULL,
`category` int(11) DEFAULT NULL,
`amount` decimal(10,3) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY LIST (category)
(PARTITION p0 VALUES IN (3,5) ENGINE = InnoDB,
PARTITION p1 VALUES IN (1,10) ENGINE = InnoDB,
PARTITION p2 VALUES IN (4,9) ENGINE = InnoDB,
PARTITION p3 VALUES IN (2) ENGINE = InnoDB,
PARTITION p4 VALUES IN (6) ENGINE = InnoDB,
PARTITION p5 VALUES IN (7,8) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> alter table emp_date reorganize partition p4 into ( partition p5 values less than (2010), partition p6 values less than (2030) );
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create emp_date \G;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'emp_date' at line 1
ERROR:
No query specified
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p5 VALUES LESS THAN (2010) ENGINE = InnoDB,
PARTITION p6 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.01 sec)
ERROR:
No query specified
mysql> show create table emp_date \G;
*************************** 1. row ***************************
Table: emp_date
Create Table: CREATE TABLE `emp_date` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( YEAR(separated))
(PARTITION p0 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p5 VALUES LESS THAN (2010) ENGINE = InnoDB,
PARTITION p6 VALUES LESS THAN (2030) ENGINE = InnoDB) */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> create table emp(
-> id int not null,
-> ename varchar(30),
-> hired date not null default '1970-01-01',
-> separated date not null default '9999-12-31',
-> job varchar(30) not null,
-> store_id int not null
-> )
-> partition by hash(store_id) partitions 4;
Query OK, 0 rows affected (0.05 sec)
mysql> alter table emp coalesce partition 2;
Query OK, 0 rows affected (0.25 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table emp \G;
*************************** 1. row ***************************
Table: emp
Create Table: CREATE TABLE `emp` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY HASH (store_id)
PARTITIONS 2 */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> alter table emp coalesce partition 8;
ERROR 1508 (HY000): Cannot remove all partitions, use DROP TABLE instead
mysql> alter table emp add partition partitions 8;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table emp \G;
*************************** 1. row ***************************
Table: emp
Create Table: CREATE TABLE `emp` (
`id` int(11) NOT NULL,
`ename` varchar(30) DEFAULT NULL,
`hired` date NOT NULL DEFAULT '1970-01-01',
`separated` date NOT NULL DEFAULT '9999-12-31',
`job` varchar(30) NOT NULL,
`store_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY HASH (store_id)
PARTITIONS 10 */
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
mysql 学习记录(十五)--分区
最新推荐文章于 2021-03-23 19:40:29 发布