muzisanshi

很简单的sql:

select * from (
select * from issue.db_info
order by creator_date
) where rownum<10

执行计划如下:

 

 此查询需要12秒左右。

 

创建索引

create index idx_time on db_info(creator_date);

sql改写如下:

select * from (
select * from issue.db_info
where creator_date is not null
order by creator_date
) where rownum<10

 

毫秒级别。

 

利用索引是有序的特点,减少结果集排序(sort order by);

同时不要忘记索引是不包含null值的特点,改写sql( where creator_date is not null),

如果查询条件中没有is not null的过滤条件,索引将会抑制;

同时在优化取排名前几类似的sql时,注意执行计划中的count stopkey步骤,

此步骤代表取到指定的数量后,停止后续的结果集获取,在某些情况下某些写法会导致该步骤消失,导致性能问题;

如下:

select t.*,rownum rn from (
select * from issue.db_info
where creator_date is not null
order by creator_date
) t where rn>1 and rn<10

执行计划如下:

 

分类:

技术点:

相关文章:

  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-11-11
  • 2021-12-02
  • 2021-11-19
  • 2022-02-05
猜你喜欢
  • 2021-04-04
  • 2021-07-19
  • 2022-12-23
  • 2021-12-27
  • 2021-07-31
  • 2022-01-19
相关资源
相似解决方案