MySQL优化和索引

时间:2014-11-08 07:16:07

标签: mysql

嗨,大家,请告诉我这个。

我有一个包含数百万条记录的tablemasterlist。 我使用Index for CycleDate和ProductType。 我期待记录数为100,132,但sql扫描 行太多了。

explain SELECT * FROM tblmasterlist where  CycleDate BETWEEN '2014-08-01' AND '2014-08-30'

enter image description here


1 个答案:

答案 0 :(得分:1)

CycleDate上的索引正常并在此查询中使用。就像Mike所说的那样,确保它是Typ=BTREE,因为你选择RANGE值(参见here)。

EXPLAIN给出的记录数是对行数的估计,而不是MySQL必须扫描的实际数量(参见here):

The rows column indicates the number of rows MySQL believes 
it must examine to execute the query. 
For InnoDB tables, this number is an estimate, and may not always be exact. 

您可以通过更新索引统计信息来提高准确度:

OPTIMIZE TABLE tblmasterlist
相关问题