I have one query that is used to search on products on website and uses pagination.
I have read your articles on pagination and Top N query, where you have described both the option.
https://asktom.oracle.com/Misc/oramag/on-rownum-and-limiting-results.html https://asktom.oracle.com/Misc/oramag/on-top-n-and-pagination-queries.html I checked following 2 approach and need your opinion on which one is better?
Approach 1 : SELECT PKID
,NAME
,PRODUCT_NUMBER
,PROD_TYPE
,RENEWABLE_FLAG
,FROM_DATE
,TO_DATE
-- */
FROM (SELECT ROWNUM RNUM
,V.*
FROM (SELECT PKID
,NAME
,PRODUCT_NUMBER
,PROD_TYPE
,RENEWABLE_FLAG
,FROM_DATE
,TO_DATE
FROM PRODUCT PRD
WHERE 1 = 1 AND PROD_TYPE = 'Sell'
ORDER BY UPPER (NAME) DESC) V
WHERE ROWNUM <= :V_CNT2)
WHERE RNUM >= :V_CNT;
Plan for one time execution SELECT STATEMENT CHOOSE Cost: 19 Bytes: 20,655 Cardinality: 15
5 VIEW UHC_USER. Cost: 19 Bytes: 20,655 Cardinality: 15
4 COUNT STOPKEY
3 VIEW UHC_USER. Cost: 19 Bytes: 23,188 Cardinality: 17
2 TABLE ACCESS BY INDEX ROWID TABLE UHC_USER.PRODUCT Cost: 19 Bytes: 832,910,169 Cardinality: 3,050,953
1 INDEX FULL SCAN DESCENDING INDEX UHC_USER.PROD_UPP_NAME_IX Cost: 3 Cardinality: 17
34 msecsPlan for 100000 executionsSELECT STATEMENT CHOOSE Cost: 197,270 Bytes: 4,201,162,281 Cardinality: 3,050,953
5 VIEW UHC_USER. Cost: 197,270 Bytes: 4,201,162,281 Cardinality: 3,050,953
4 COUNT STOPKEY
3 VIEW UHC_USER. Cost: 197,270 Bytes: 4,161,499,892 Cardinality: 3,050,953
2 SORT ORDER BY STOPKEY Cost: 197,270 Bytes: 832,910,169 Cardinality: 3,050,953
1 TABLE ACCESS FULL TABLE UHC_USER.PRODUCT Cost: 17,765 Bytes: 832,910,169 Cardinality: 3,050,953
5.61 SecondsApproach 2SELECT PKID
,NAME
,PRODUCT_NUMBER
,PROD_TYPE
,RENEWABLE_FLAG
,FROM_DATE
,TO_DATE
FROM (SELECT /*+ FIRST_ROWS(10) */
PKID
,NAME
,PRODUCT_NUMBER
,PROD_TYPE
,RENEWABLE_FLAG
,FROM_DATE
,TO_DATE
,ROW_NUMBER () OVER (ORDER BY UPPER (NAME) DESC) AS RNUM
FROM PRODUCT P
WHERE PROD_TYPE = 'Sell')
WHERE RNUM BETWEEN :V_CNT AND :V_CNT2
Plan for one time executionSELECT STATEMENT HINT: FIRST_ROWS Cost: 29 Bytes: 158,301 Cardinality: 27
5 SORT ORDER BY Cost: 29 Bytes: 158,301 Cardinality: 27
4 VIEW UHC_USER. Cost: 28 Bytes: 158,301 Cardinality: 27
3 WINDOW NOSORT STOPKEY Cost: 28 Bytes: 7,371 Cardinality: 27
2 TABLE ACCESS BY INDEX ROWID TABLE UHC_USER.PRODUCT Cost: 28 Bytes: 832,910,169 Cardinality: 3,050,953
1 INDEX FULL SCAN DESCENDING INDEX UHC_USER.PROD_UPP_NAME_IX Cost: 3 Cardinality: 27
109 msecsPlan for 100000 executiosSELECT STATEMENT HINT: FIRST_ROWS Cost: 15 Bytes: 70,356 Cardinality: 12
6 SORT ORDER BY Cost: 15 Bytes: 70,356 Cardinality: 12
5 VIEW UHC_USER. Cost: 14 Bytes: 70,356 Cardinality: 12
4 WINDOW NOSORT Cost: 14 Bytes: 3,276 Cardinality: 12
3 FILTER
2 TABLE ACCESS BY INDEX ROWID TABLE UHC_USER.PRODUCT Cost: 14 Bytes: 832,910,169 Cardinality: 3,050,953
1 INDEX FULL SCAN DESCENDING INDEX UHC_USER.PROD_UPP_NAME_IX Cost: 3 Cardinality: 12
8.55 SecondsThanks,