Speed of paged queries in Oracle

后端 未结 4 1612
死守一世寂寞
死守一世寂寞 2020-12-14 12:27

This is a never-ending topic for me and I\'m wondering if I might be overlooking something. Essentially I use two types of SQL statements in an application:

  1. Re
4条回答
  •  无人及你
    2020-12-14 13:02

    It may perform better to run two queries instead of trying to count() and return the results in the same query. Oracle may be able to answer the count() without any sorting or joining to all the tables (join table elimination based on declared foreign key constraints). This is what we generally do in our application. For performance important statements, we write a separate query that we know will return the correct count as we can sometimes do better than Oracle.

    Alternatively, you can make a tradeoff between performance and recency of the data. Bringing back the first 5 pages is going to be nearly as quick as bringing back the first page. So you could consider storing the results from 5 pages in a temporary table along with an expiry date for the information. Take the result from the temporary table if valid. Put a background task in to delete the expired data periodically.

提交回复
热议问题