Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:54:43+00:00 2026-06-15T06:54:43+00:00

Possible Duplicate: Does Oracle fetch all the rows before evaluating rownum? If I run

  • 0

Possible Duplicate:
Does Oracle fetch all the rows before evaluating rownum?

If I run the following query on a table with 100k rows

select * from 
(
 select rownum rownumber, fname, lastname
 from customers
) where rownumber between 1 and 100;

Does Oracle fetch all 100k then filter the list of rows fetched to get the first 100 or does it have a clever way of filtering to the first 100 without fetching all 100k rows?

Is there a way find out how Oracle actually will do the fetch in the above example?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:54:46+00:00Added an answer on June 15, 2026 at 6:54 am

    First, since your inner query isn’t doing any sort of ordering, your query returns an arbitrary 100 rows. If this is at attempt to build a query to page through the results, this is not the proper approach both since it is not efficient and because it is not correct– the set of rows that is returned could well change over time and rows could easily appear on many different pages of the results or no page at all.

    It is easy enough, though, to see when the filter is applied by looking at the query plan. I’ll build a trivial table FOO with 100,000 rows

    SQL> drop table foo;
    
    Table dropped.
    
    SQL> create table foo
      2  as
      3  select level col1
      4    from dual
      5   connect by level <= 100000;
    
    Table created.
    

    Now, enable autotrace, suppress the display of the actual data and run the query

    SQL> set autotrace traceonly;
    
    SQL> select *
      2    from (select rownum rn, col1
      3            from foo)
      4   where rn between 1 and 100;
    
    100 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3193632835
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |   101K|  2577K|    47   (3)| 00:00:01 |
    |*  1 |  VIEW               |      |   101K|  2577K|    47   (3)| 00:00:01 |
    |   2 |   COUNT             |      |       |       |            |          |
    |   3 |    TABLE ACCESS FULL| FOO  |   101K|  1288K|    47   (3)| 00:00:01 |
    ----------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter("RN"<=100 AND "RN">=1)
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    
    
    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
            164  consistent gets
              0  physical reads
              0  redo size
           2504  bytes sent via SQL*Net to client
            590  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            100  rows processed
    

    If you look at the query plan, you can see that we did a full table scan of FOO before applying the rn between 1 and 100 predicate. So the entire result set was materialized (and the number of consistent gets is roughly the number of blocks in the table).

    If you used a more appropriate pagination query (for example, Tom Kyte has an Oracle Magazine article on pagination and a much longer discussion of pagination on askTom), you would see something in the query plan like SORT ORDER BY STOPKEY that tells you that Oracle knows it can stop processing after a certain point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Does the compiler continue evaluating an expression where all must be true
Possible Duplicate: Does a finally block always run? let's imagine the following scenario: public
Possible Duplicate: Simple Oracle query: literal does not match format string I am getting
Possible Duplicate: Is there an Oracle SQL query that aggregates multiple rows into one
Possible Duplicate: Does C# have extension properties? I have the following: public static class
Possible Duplicate: Does a finally block always run? I learned that the finally clause
Possible Duplicate: Does Firefox support position: relative on table elements? Does Firefox ignore relative
Possible Duplicate: Does reading from stdin flush stdout? C++ Standard guarantees that all data
Possible Duplicate: Oracle "(+)" Operator Can some one tell me what does (+) sign
Possible Duplicate: Why does Oracle 9i treat an empty string as NULL? I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.