I need to do SELECT query from java code on table that contains 1kkk rows , so the result set will be near 1kk rows. thats why I need to limit it, and run select query many times and each time to retrieve 10k rows only. After I get 10k rows I update it so in the next SELECT they wont be retrieved. The problem is - in each select oracle looking from first row in the table so it reduces the performance. How can I use OFFSET for avoiding oracle looking from first row and pass over already updated rows?
1 Answers
8
votes
None of these solutions actually improve performance.
You've got a dataset of 250,000 rows and fetch them in batches of 10,000. Unless you have a stateful connection to the database and keep that SELECT statement in progress (in oracle terms this is 'keeping the cursor open') then each select is independent of the last.
As such to fetch the batch from 180,001 to 190,000 it will still have to sort so it can work out the first 190,000 rows. Syntactic sugar such as OFFSET doesn't alter the fundamental rules of maths and logic.
To get the best performance you need to keep the resultset open and just keep fetching rows from it. Don't close it and don't re-issue the select.
OFFSETif you have Oracle 12cR1 or higher: stackoverflow.com/a/26051830/1461424 - sampathsris