I did some performance testing for the following approaches:
Asktom
select * from ( select a.*, ROWNUM rnum from (<select statement with order by clause> ) a where rownum <= MAX_ROW) where rnum >= MIN_ROW
Analytical
select * from (<select statement with order by clause>) where myrow between MIN_ROW and MAX_ROW
Short Alternative
select * from ( select statement, rownum as RN with order by clause) where a.rn >= MIN_ROW and a.rn <= MAX_ROW
Results
Table had 10 million records, sort was on an unindexed datetime row:
- Explain plan showed same value for all three selects (323168)
- But the winner is AskTom (with analytic following close behind)
Selecting first 10 rows took:
- AskTom: 28-30 seconds
- Analytical: 33-37 seconds
- Short alternative: 110-140 seconds
Selecting rows between 100,000 and 100,010:
- AskTom: 60 seconds
- Analytical: 100 seconds
Selecting rows between 9,000,000 and 9,000,010:
- AskTom: 130 seconds
- Analytical: 150 seconds