我创建了一个 MySQL 表,它按日期列的月份进行分区,如下所示:
CREATE TABLE `my_big_table` (
`some_id` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`some_value` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
`some_other_value` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
`time` datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
PARTITION BY LIST(MONTH(time))
(PARTITION p1 VALUES IN (1) ENGINE = MyISAM,
PARTITION p2 VALUES IN (2) ENGINE = MyISAM,
PARTITION p3 VALUES IN (3) ENGINE = MyISAM,
PARTITION p4 VALUES IN (4) ENGINE = MyISAM,
PARTITION p5 VALUES IN (5) ENGINE = MyISAM,
PARTITION p6 VALUES IN (6) ENGINE = MyISAM,
PARTITION p7 VALUES IN (7) ENGINE = MyISAM,
PARTITION p8 VALUES IN (8) ENGINE = MyISAM,
PARTITION p9 VALUES IN (9) ENGINE = MyISAM,
PARTITION p10 VALUES IN (10) ENGINE = MyISAM,
PARTITION p11 VALUES IN (11) ENGINE = MyISAM,
PARTITION p12 VALUES IN (12) ENGINE = MyISAM)
现在,当我跑步时
explain partitions select * from my_big_table where month(time) = 2 limit 10;
我得到输出:
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE my_big_table p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12 ALL NULL NULL NULL NULL 10762868 "Using where"
所以显然所有的分区都被读取了,我想知道为什么。引擎不应该足够聪明地找出匹配值只能在分区p2中找到吗?对于基于日期的查询,我得到相同的输出,例如
explain partitions select * from my_big_table where date(time) = '2013-02-01' limit 10;
有什么线索吗?
干杯,亚历克斯