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 6343541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:27:30+00:00 2026-05-24T20:27:30+00:00

When Paging needs to be done in an web site… Which method performs better?

  • 0

When Paging needs to be done in an web site… Which method performs better?

Analytic function – ROW_NUMBER()

  • Oracle 10G
  • http://www.oracle.com/technetwork/issue-archive/2007/07-jan/o17asktom-093877.html

    SELECT columnA, 
        columnB
    FROM (SELECT columnA,
               columnB,
               row_number() over (order by columnB) rn
          FROM table)
    WHERE rn BETWEEN LOW_LIMIT AND OFFSET;
    

ROWNUM

  • http://www.oracle.com/technetwork/issue-archive/2007/07-jan/o56asktom-086197.html
  • INMHO I find this approach a more human-readable code

    SELECT * FROM (
      SELECT rownum rn, a.* 
      FROM(
        SELECT columnA, columnB
        FROM table 
        ORDER BY columnB
      ) a 
      WHERE rn <= OFFSET
    )
    WHERE rnum >= LOW_LIMIT
    
    • Note: I understand that there are RANK and DENSE_RANK analytic functions, but lets assume I just need page through deterministic queries.

    • Note 2: To retrieve the total amount of records I am thinking in using a separate simple query count(*)

  • 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-05-24T20:27:31+00:00Added an answer on May 24, 2026 at 8:27 pm

    I thought this question was interesting, so I tried a few things out.

    I have table called large_t, that contains about 1.1M rows.

    Then I have two queries:

    select * 
    from
    (
      select rownum rnum, a.*
      from (
             select owner, object_name, object_id
             from large_t
             order by object_id
           ) a
      where rownum   <= 30      
    ) where rnum > 20;
    

    And

    select *
    from
    (
    select owner, object_name, object_id,
           row_number() over (order by object_id) rnum
    from large_t
    ) where rnum > 20 and rnum <= 30;
    

    If you look at the plans the two queries generate, the first has an operation:

    SORT ORDER BY STOPKEY
    

    While the analytic query contains an operation called

    WINDOW SORT PUSHED RANK
    

    The SORT ORDER BY STOPKEY is a more efficient sort operation that a plain ORDER BY. I am not sure how a WINDOW SORT PUSHED RANK works, but it seems to work in a similar fashion.

    Looking at v$sql_workarea after running both queries, both only required a sort_area of 4096 bytes.

    In contrast, if I ran the query without a paging query:

    select owner, object_name, object_id
    from large_t
    order by object_id
    

    Then the sort area required is 37M, proving the sort in both queries is about the same.

    Normally, if you want to efficiently return the TOP N of a sorted query, you will want an index on the sorting column – that will prevent Oracle needing to sort at all. So, I created an index on OBJECT_ID, and then explained both queries again.

    This time the first query used the index and returned in 0.2 seconds, while the second query didn’t use the new index and was much slower.

    So my conclusion from this quick bit of analysis is that in the general case using rownum to filter or the analytic row_number function both perform about the same. However, the rownum example automatically started using the index I created on the table when row_number did not. Maybe I could get it to use the index with some hints – that is something else you can experiment with.

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

Sidebar

Related Questions

Task: implement paging of database records suitable for different RDBMS. Method should work for
For example, this list contains an overview of documents and needs to allow paging.
I have a select which needs to have dynamic WHERE CASE conditions. SELECT *
I have dynamic and quite large contents which needs to be populated on user
I'm building a website (a community web site like digg) but we will soon
I'm dynamically building a nhibernate projected query that needs to implement paging. Something like...
I have a client talking with server program(using sqlite3 as the storage) which needs
I would need to create a temp table for paging purposes. I would be
How to do paging in Pervasive SQL (version 9.1)? I need to do something
I am using paging on a GridView that is tied to a List<Employee> .

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.