2014-07-02 105 views
1

我有用於7秒運行時過濾器標準是MySQL的性能減慢where子句

select * from table where date1 is null 

AA查詢之後加入「或」,但是當我添加

select * from table where (date1 is null or (date1 < date2)) 

則查詢需要32秒。如何提高此查詢的性能?我在兩個日期列上都有索引。

+2

您是否檢查過兩個查詢的'EXPLAIN'的結果? – raina77ow

+1

嘗試使用'UNION',取下'OR'並將其放入另一個選擇 –

+0

是否爲索引的字段? – Barranka

回答

0

您正在強制SQL先比較兩個日期,然後才能評估其餘條件。

你應該寫這麼見好轉:

select * from table where date1 is null or date1 < date2 

這將使更快速的解決素養,因爲病情會是真實的瞬間滿足第一條件。

+0

這沒有做出區別 – user1721546