我正在探索按年和月分区MySQL表的方法。您能否请在下面分析我的表创建,看看这种分区方法是否会最终按月和年在这些子分区中放置数据?我使用的是MySQL 5.5,我无法使用
SELECT * FROM points_log PARTITION (p0_p0sp0);
验证分区是否正常工作。如果有一种方法可以在MySQL 5.5中验证这一点,请评论。感谢您对此表分区的反馈和批评。
这是我创建的表格:
CREATE TABLE `points_log` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`nick` char(25) NOT NULL,
`amount` decimal(7,4) NOT NULL,
`stream_online` tinyint(1) NOT NULL,
`modification_type` tinyint(3) unsigned NOT NULL,
`dt` datetime NOT NULL,
PRIMARY KEY (`id`,`dt`,`nick`),
KEY `nick_idx` (`nick`),
KEY `amount_idx` (`amount`),
KEY `modification_type_idx` (`modification_type`),
KEY `dt_idx` (`dt`),
KEY `stream_online_idx` (`stream_online`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1
PARTITION BY RANGE( YEAR(dt) )
SUBPARTITION BY HASH( MONTH(dt) )
SUBPARTITIONS 12 (
PARTITION p0 VALUES LESS THAN (2014),
PARTITION p1 VALUES LESS THAN (2015),
PARTITION p2 VALUES LESS THAN (2016),
PARTITION p3 VALUES LESS THAN (2017),
PARTITION p4 VALUES LESS THAN (2018),
PARTITION p5 VALUES LESS THAN (2019),
PARTITION p6 VALUES LESS THAN (2020),
PARTITION p7 VALUES LESS THAN MAXVALUE
);
答案 0 :(得分:10)
SUBPARTITIONs
可能没用。BY RANGE(TO_DAYS(dt)) VALUES LESS THAN (TO_DAYS('2015-02-01'))
BY HASH
可能对性能毫无用处。WHERE dt BETWEEN .. AND ..
无法在您拥有的结构中执行分区修剪。CHAR
用于可变长度字段。使用VARCHAR
。