我有一个关于从分区表(MySQL数据库)中检索数据的一般性问题。
我在表格中按年份范围进行了分区。此外,我已将分区列编入索引。
PARTITION BY RANGE (YEAR(`RDATE`))
(PARTITION pp0 VALUES LESS THAN (0) ENGINE = MyISAM,
PARTITION p0 VALUES LESS THAN (2000) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (2005) ENGINE = MyISAM,
PARTITION p2 VALUES LESS THAN (2008) ENGINE = MyISAM,
PARTITION p3 VALUES LESS THAN (2010) ENGINE = MyISAM,
PARTITION p4 VALUES LESS THAN (2011) ENGINE = MyISAM,
PARTITION p5 VALUES LESS THAN (2012) ENGINE = MyISAM,
PARTITION p6 VALUES LESS THAN (2013) ENGINE = MyISAM,
PARTITION p7 VALUES LESS THAN (2014) ENGINE = MyISAM,
PARTITION p8 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
在运行下面的查询时..
explain partitions select Products from salesdata where rdate between '2011-11-01' and LAST_DAY('2011-11-01')
结果就像(扫描总行数2502 ..)
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE sldata p5 range sls_ind sls_ind 3 2502 Using where
但如果我运行此查询..
explain partitions select Products from salesdata where rdate between '2011-12-01' and LAST_DAY('2011-12-01')
结果是(扫描总行数55181 ..)
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE sldata p5 ALL sls_ind 55181 Using where
任何人都有一个想法,为什么第二个查询扫描整个分区不像第一个查询..?