Oracle 12c – How to Implement Pagination on Large Table Using ROWID

oraclepaging

I am new to the database. I would like to implement pagination on large tables using rowid but what I found that rowid can be alphanumeric digits and not necessarily they are in any order so I wonder if we can use them to paginate the tables. The table from which I would like to get the records in pagination is very large table having more than 2 billion records and if we execute the query based on offset and length then that comes up with an error Ora1652 unable to extend temp segment in tablespace temp. So is there way to get the results in pagination using rowid.

Any help would be appreciated thank you in advance.

Edited:

Let's suppose I have a Table say LARGE_ROWS having ID and RANDOM two columns whereas ID is the primary key column.

SELECT /*+ ordered use_nl(p s) */
    *
FROM
    (
        SELECT
            ROWNUM RN,
            RD
        FROM
            (
                SELECT
                    ROWID RD
                FROM
                    large_rows
                ORDER BY
                    large_rows.id
            ) T
        WHERE
            ROWNUM < 1000
    ) P,
    large_rows S
WHERE
    RN > 900
    AND P.RD = S.ROWID;

Best Answer

You need to try following by yourself multiple times to see if you are getting any improvement in performance with the correct result.

I tried different approaches and Following is giving good performance in my case.

DROP TABLE STUDENT;

CREATE TABLE student (RNO NUMBER, NAME VARCHAR2(1000));

-- I have just added 2,000,000 records
INSERT INTO STUDENT
SELECT LEVEL, 'STUDENT - ' || LEVEL
FROM DUAL CONNECT BY LEVEL <= 2000000;


-- selecting the 10th page of length 100 each
SELECT /*+ ordered use_nl(p s) */
    *
FROM
    (
        SELECT
            ROWNUM RN,
            RD
        FROM
            (
                SELECT
                    ROWID RD
                FROM
                    STUDENT
                ORDER BY
                    RNO
            ) T
        WHERE
            ROWNUM < 1000
    ) P,
    STUDENT S
WHERE
    RN > 900
    AND P.RD = S.ROWID;

A Rowid is made by OOOOOOFFFBBBBBBRRR O is object id,F is file id,B is block id,R is row number. Starting from 11g some new mechanism is introduced. If the next rowid is in the same block with the current row, then the current block can be reused. Hence, "Consistent gets" increase.

I hope you will get direction in solving your issue.

Cheers!!