我有一个关于从分区表(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
任何人都有一个想法,为什么第二个查询不像第一个查询那样扫描整个分区..?