我有98w行數據。當我想用pub_time對數據進行排序時,我發現了一件有趣的事情。兩個sql用於排序時間戳日期
這裏是SQL:
select *
from t_p_blog_article_info t
order by t.pub_time desc
它花費了19秒。
select *
from t_p_blog_article_info t
where t.pub_time > to_date('1900-01-01 01:00:00', 'yyyy-mm-dd hh24:mi:ss ')
order by t.pub_time desc
它花費0.2s。
我想知道,爲什麼?
「pub_time」列是否有索引? – Ollie 2012-03-13 13:13:12
只是一個猜測,但可以t.pub_time永遠是NULL? – markblandford 2012-03-13 13:13:36
顯然你的where子句過濾了很多記錄,爲什麼? 'null'值,或者簡單地在01.01.1900之前輸入錯誤的時間值 – ntziolis 2012-03-13 13:16:57