我有 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 上有一个索引。
因此,第二个查询可以利用该索引仅返回指定日期之后具有非空日期的记录,而第一个查询必须查询整个表。
关于sql - 排序时间戳日期的两个 sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9684567/