优化让Oracle分页的加速

时间:2022-10-12 21:11:57
 Oracle分页大家一般使用这种形式

  SELECT * FROM

  (

  SELECT A.*, rownum r

  FROM

  (

  SELECT *

  FROM Articles

  ORDER BY PubTime DESC

  ) A

  ) B

  WHERE r <= PageUpperBound

  and r > PageLowerBound;

  在很多时候,并不需要排序,而是要进行多表的联查计算等,这个时候数据多了就会显的很慢

  发现慢就慢在Order By上

  更改如下:

  SELECT * FROM

  (

  SELECT A.*, rownum r

  FROM

  (

  SELECT *

  FROM Articles

  ) A

  WHERE rownum <= PageUpperBound  ORDER BY PubTime DESC //Order by 放这来

  )B

  and r > PageLowerBound;