更新:抱歉的人,使用后explain
它看起来像这个问题太局部化了。答案是,mysql选择了错误的索引。投票结束。为什么BETWEEN比分别运行每个查询要慢得多?
我跑了工作怎么样
select * from some_table where sql_date = '2011-12-01';
,并在30分钟内跑了。
现在我正在
select * from some_table where sql_date BETWEEN '2011-12-01' and '2011-12-08';
,并正在采取20小时以上,这让我觉得它会一直运行更快
select * from some_table where sql_date = '2011-12-01';
select * from some_table where sql_date = '2011-12-02';
select * from some_table where sql_date = '2011-12-03';
等为什么是“之间”太慢了?
更新:
@loganfsmyth:有一个日期索引。
@Magnus:在大桌上的几个连接。
@Sparky:没有二进制数据,我正在使用INTO OUTFILE 'filename.txt'
。
解释返回此为一个日期:
+----+-------------+------------+--------+----------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------+---------+------------------------------------------+---------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+--------+----------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------+---------+------------------------------------------+---------+----------------------------------------------+
| 1 | SIMPLE | dates | ref | PRIMARY,index_dates_on_sql_date | index_dates_on_sql_date | 3 | const | 1 | Using index; Using temporary; Using filesort |
| 1 | SIMPLE | views | ref | index_views_doc_id,index_views_id | index_new_views_id | 8 | olap.dates.date_key,const | 3241236 | |
| 1 | SIMPLE | docs | eq_ref | PRIMARY,pub_date,published_id,user_id,user_anonymous,user_deleted | PRIMARY | 4 | olap.views.doc_id | 1 | Using where |
| 1 | SIMPLE | docs_count | ref | user_id | user_id | 5 | slave.docs.user_id | 1 | Using where |
+----+-------------+------------+--------+----------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------+---------+------------------------------------------+---------+----------------------------------------------+
什么是日期列的类型? – 2012-02-02 22:27:18
你有'日期'列的索引吗? – loganfsmyth 2012-02-02 22:28:06
20小时这样的简单查询?!你有什么样的怪物表? – Magnus 2012-02-02 22:28:18