Quantcast
Viewing latest article 11
Browse Latest Browse All 17

Answer by zeldi for How do I limit the number of rows returned by an Oracle query after ordering?

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

Viewing latest article 11
Browse Latest Browse All 17

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>