database partitioning - MySQL Partition by Month not working -
i create table by
create table `part_tab` ( `id` int not null, `use_time` datetime not null ) engine=innodb default charset=utf8 partition hash(month(use_time)) partitions 12;
then use explain partions syntax, seems mysql didn't use partition, still scans whole table:
mysql> explain partitions select * part_tab use_time < '2013-02-01' \g *************************** 1. row *************************** id: 1 select_type: simple table: part_tab partitions: p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11 type: possible_keys: null key: null key_len: null ref: null rows: 12 extra: using 1 row in set (0.00 sec)
if change condition equal,the partition used:
mysql> explain partitions select * part_tab use_time = '2013-02-01' \g *************************** 1. row *************************** id: 1 select_type: simple table: part_tab partitions: p2 type: possible_keys: null key: null key_len: null ref: null rows: 2 extra: using 1 row in set (0.00 sec)
your query is:
select * part_tab use_time = '2013-02-01';
your partition statement is:
partition hash(month(use_time)) partitions 12;
what trying called "partition pruning". according documentation,
pruning can applied tables partitioned on date or datetime column when partitioning expression uses year() or to_days() function. in addition, in mysql 5.7, pruning can applied such tables when partitioning expression uses to_seconds() function.
i don't believe there way partition pruning directly on month()
instead of year()
. can rewrite query as:
select * part_tab month(use_time) = 1;
however, suspect range partitioning on date better solution.
Comments
Post a Comment