Version 2 (modified by 2 years ago) (diff) | ,
---|
Partition
- mysql restore sample data (mysqlsampledatabase.sql) from here
rpl_user@node1:/mysql/test/T3$ /mysql/bin/mysql -uroot --protocol=socket --socket=/tmp/mysql.0.sock < mysqlsampledatabase.sql
- create table payments2. primary key MUST include in PARTITION
mysql> CREATE TABLE payments2 ( customerNumber int(11) NOT NULL, checkNumber varchar(50) NOT NULL, paymentDate datetime NOT NULL, amount decimal(10,2) NOT NULL, PRIMARY KEY (customerNumber,paymentDate ) ) PARTITION BY RANGE( TO_DAYS(paymentDate) ) ( PARTITION p2003 VALUES LESS THAN (TO_DAYS('2004-01-01')), PARTITION p2004 VALUES LESS THAN (TO_DAYS('2005-01-01')), PARTITION p2005 VALUES LESS THAN (TO_DAYS('2006-01-01')) );
- copy payments table to just create payments2
mysql> insert into payments2 select * from payments
- test and notice the rows between table payments (273) vs payments2 (37)
mysql> explain select * from payments2 where paymentDate = "2005-05-03"; +----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+ | 1 | SIMPLE | payments3 | p2005 | ALL | NULL | NULL | NULL | NULL | 37 | 10.00 | Using where | +----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec) mysql> explain select * from payments where paymentDate = "2005-05-03"; +----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+ | 1 | SIMPLE | payments | NULL | ALL | NULL | NULL | NULL | NULL | 273 | 10.00 | Using where | +----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec)
Attachments (1)
- mysqlsampledatabase.zip (53.1 KB) - added by 2 years ago.
Download all attachments as: .zip