| 76 | == Test Script == |
| 77 | |
| 78 | Following is test script to parse to mysql command |
| 79 | {{{ |
| 80 | CREATE DATABASE Payment; |
| 81 | USE Payment; |
| 82 | CREATE TABLE payments ( |
| 83 | customerNumber int(11) NOT NULL, |
| 84 | checkNumber varchar(50) NOT NULL, |
| 85 | paymentDate datetime NOT NULL, |
| 86 | amount decimal(10,2) NOT NULL ) |
| 87 | ENGINE=InnoDB PARTITION BY RANGE( TO_DAYS(paymentDate) ) |
| 88 | ( PARTITION p2003 VALUES LESS THAN (TO_DAYS('2004-01-01')), |
| 89 | PARTITION p2004 VALUES LESS THAN (TO_DAYS('2005-01-01')), |
| 90 | PARTITION p2005 VALUES LESS THAN (TO_DAYS('2006-01-01')), |
| 91 | PARTITION p3 VALUES LESS THAN MAXVALUE ); |
| 92 | |
| 93 | SHOW CREATE TABLE payments \G |
| 94 | INSERT INTO payments select * from classicmodels.payments; |
| 95 | |
| 96 | EXPLAIN SELECT * FROM payments where paymentDate = "2005-05-03"; |
| 97 | EXPLAIN SELECT * FROM classicmodels.payments where paymentDate = "2005-05-03"; |
| 98 | CREATE TABLE payments_2004 like payments; |
| 99 | SHOW CREATE TABLE payments_2004 \G |
| 100 | ALTER TABLE payments_2004 REMOVE PARTITIONING; |
| 101 | SHOW CREATE TABLE payments_2004 \G |
| 102 | ALTER TABLE payments EXCHANGE PARTITION p2004 WITH TABLE payments_2004; |
| 103 | SELECT COUNT(*) FROM payments; |
| 104 | SELECT COUNT(*) FROM payments_2004; |
| 105 | |
| 106 | ALTER TABLE payments EXCHANGE PARTITION p2004 WITH TABLE payments_2004; |
| 107 | SELECT COUNT(*) FROM payments; |
| 108 | SELECT COUNT(*) FROM payments_2004; |
| 109 | |
| 110 | -------------- query with parition ------------ |
| 111 | SELECT * FROM table1 PARTITION (A, B) WHERE col1< 10 |
| 112 | |
| 113 | SELECT * FROM payments PARTITION (p2005) where paymentDate = "2005-05-03"; |
| 114 | EXPLAIN SELECT * FROM payments PARTITION (p2005) WHERE paymentDate = "2005-05-03"; |
| 115 | EXPLAIN SELECT * FROM payments WHERE customerNumber = 209; |
| 116 | EXPLAIN SELECT * FROM payments PARTITION (p2005) WHERE customerNumber = 209; |
| 117 | |
| 118 | ------------ with primary key ----------------- |
| 119 | EXPLAIN SELECT * FROM classicmodels.payments WHERE customerNumber = 209; |
| 120 | EXPLAIN SELECT * FROM classicmodels.payments WHERE amount = 4632.31; |
| 121 | EXPLAIN SELECT * FROM payments WHERE amount = 4632.31; |
| 122 | EXPLAIN SELECT * FROM payments PARTITION (p2004) WHERE amount = 4632.31; |
| 123 | |
| 124 | |
| 125 | }}} |