Partitioner af HASH er en meget dårlig idé med datetime-kolonner, fordi den ikke kan bruge partitionsbeskæring . Fra MySQL-dokumenterne:
SELECT * FROM t4 WHERE dob >= '2001-04-14' AND dob <= '2005-10-15';
Så du kan gemme værdien af TO_DAYS(DATE()) i en ekstra INTEGER-kolonne for at bruge beskæring.
En anden mulighed er at bruge RANGE-partitionering:
CREATE TABLE raw_log_2011_4 (
id bigint(20) NOT NULL AUTO_INCREMENT,
logid char(16) NOT NULL,
tid char(16) NOT NULL,
reporterip char(46) DEFAULT NULL,
ftime datetime DEFAULT NULL,
KEY id (id)
) ENGINE=InnoDB AUTO_INCREMENT=286802795 DEFAULT CHARSET=utf8
PARTITION BY RANGE( TO_DAYS(ftime) ) (
PARTITION p20110401 VALUES LESS THAN (TO_DAYS('2011-04-02')),
PARTITION p20110402 VALUES LESS THAN (TO_DAYS('2011-04-03')),
PARTITION p20110403 VALUES LESS THAN (TO_DAYS('2011-04-04')),
PARTITION p20110404 VALUES LESS THAN (TO_DAYS('2011-04-05')),
...
PARTITION p20110426 VALUES LESS THAN (TO_DAYS('2011-04-27')),
PARTITION p20110427 VALUES LESS THAN (TO_DAYS('2011-04-28')),
PARTITION p20110428 VALUES LESS THAN (TO_DAYS('2011-04-29')),
PARTITION p20110429 VALUES LESS THAN (TO_DAYS('2011-04-30')),
PARTITION future VALUES LESS THAN MAXVALUE
);
Nu vil følgende forespørgsel kun bruge partition p20110403:
SELECT * FROM raw_log_2011_4 WHERE ftime = '2011-04-03';