【发布时间】:2012-03-29 21:15:00
【问题描述】:
我有 98w 行数据。当我想用 pub_time 对数据进行排序时,我发现了一件有趣的事情。
这里是 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.2 秒。
我想知道,为什么?
【问题讨论】:
-
pub_time列上是否有索引? -
只是猜测,但 t.pub_time 可以为 NULL 吗?
-
显然你的 where 子句过滤掉了很多记录,为什么?
null值,或者只是在 01.01.1900 之前具有错误时间值的条目 -
是的,它在pub_time上有索引,我的同事使用oracle explan时间工具发现,第一次查询没有使用索引,它查询了195M数据!!
标签: sql performance oracle datestamp