我有表结构像波纹管这么长的时间:MySQL查询需要在where子句
id item_id created
1 5 2012-09-05 09:37:59
2 5 2012-09-05 10:25:09
3 5 2012-09-05 11:05:09
4 1 2012-09-05 10:25:09
5 3 2012-09-05 03:05:01
我想知道哪些ITEM_ID是通过当前日期与大多数观点WHERE子句波纹管:
SELECT item_id, COUNT(id) AS TOTAL
FROM stats_item
WHERE DAY(created) = '05'
AND MONTH(created) = '07'
AND YEAR(created) = '2013'
GROUP BY item_id
ORDER BY TOTAL DESC
LIMIT 0 , 30
在MySQL中结果查询
Showing rows 0 - 29 (30 total, Query took 4.1747 sec)
这是需要时间可达4.1747秒
贝娄是在表
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
stats_item 0 PRIMARY 1 id A 2575580 NULL NULL BTREE
stats_item 1 created 1 created A 515116 NULL NULL YES BTREE
指数为什么查询花了这么长的时间用WHERE子句和以年,月,日筛选?
================================== 编辑与讲解:
Field Type Null Key Default Extra
id int(11) unsigned NO PRI NULL auto_increment
item_id int(11) unsigned YES NULL
created timestamp YES MUL NULL
是什么'EXPLAIN'说? –
表中有多少行? – Dmitry
这是2,577,816行 –