更新:抱歉的人,使用後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