zoukankan      html  css  js  c++  java
  • 分页SQL取下一页

    20条记录一页,扫描第2页就需要访问40条记录。
    
    SQL> select * from ( select * from ( select /*+ index_desc(a idx_page_3) */ a.*,rownum rn   from page
    a  where object_id >1000 and owner='SYS'  order by object_id desc ) where rownum<=40 ) where
    rn>=21  2    3  
      4  ;
    
    
    SQL> select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    --------------------------------------------
    SQL_ID	bwcbf54a6h4th, child number 1
    -------------------------------------
    select * from ( select * from ( select /*+ index_desc(a idx_page_3) */
    a.*,rownum rn	from page a  where object_id >1000 and owner='SYS'
    order by object_id desc ) where rownum<=40 ) where rn>=21
    
    Plan hash value: 3526010999
    
    ---------------------------------------------------------------------------------------------------------
    | Id  | Operation			 | Name       | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
    ---------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT		 |	      |      1 |	|     20 |00:00:00.01 |      10 |
    |*  1 |  VIEW				 |	      |      1 |     40 |     20 |00:00:00.01 |      10 |
    |*  2 |   COUNT STOPKEY 		 |	      |      1 |	|     40 |00:00:00.01 |      10 |
    |   3 |    VIEW 			 |	      |      1 |  30556 |     40 |00:00:00.01 |      10 |
    |   4 |     COUNT			 |	      |      1 |	|     40 |00:00:00.01 |      10 |
    |   5 |      TABLE ACCESS BY INDEX ROWID | PAGE       |      1 |  30556 |     40 |00:00:00.01 |      10 |
    |*  6 |       INDEX RANGE SCAN DESCENDING| IDX_PAGE_3 |      1 |  30556 |     40 |00:00:00.01 |       4 |
    ---------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter("RN">=21)
       2 - filter(ROWNUM<=40)
       6 - access("OBJECT_ID" IS NOT NULL AND "OBJECT_ID">1000 AND "OWNER"='SYS')
           filter("OWNER"='SYS')
    
    
    28 rows selected.
    
    
    SQL> select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    --------------------------------------------
    SQL_ID	6gay6kkxxsqgw, child number 0
    -------------------------------------
    select * from ( select * from ( select /*+ index_desc(a idx_page_3) */
    a.*,rownum rn	from page a  where object_id >1000 and owner='SYS'
    order by object_id desc ) where rownum<=60 ) where rn>=41
    
    Plan hash value: 3526010999
    
    ---------------------------------------------------------------------------------------------------------
    | Id  | Operation			 | Name       | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
    ---------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT		 |	      |      1 |	|     20 |00:00:00.01 |      11 |
    |*  1 |  VIEW				 |	      |      1 |     60 |     20 |00:00:00.01 |      11 |
    |*  2 |   COUNT STOPKEY 		 |	      |      1 |	|     60 |00:00:00.01 |      11 |
    |   3 |    VIEW 			 |	      |      1 |  30556 |     60 |00:00:00.01 |      11 |
    |   4 |     COUNT			 |	      |      1 |	|     60 |00:00:00.01 |      11 |
    |   5 |      TABLE ACCESS BY INDEX ROWID | PAGE       |      1 |  30556 |     60 |00:00:00.01 |      11 |
    |*  6 |       INDEX RANGE SCAN DESCENDING| IDX_PAGE_3 |      1 |  30556 |     60 |00:00:00.01 |       4 |
    ---------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter("RN">=41)
       2 - filter(ROWNUM<=60)
       6 - access("OBJECT_ID" IS NOT NULL AND "OBJECT_ID">1000 AND "OWNER"='SYS')
           filter("OWNER"='SYS')
    
    
    28 rows selected.

  • 相关阅读:
    吐槽下博客园
    关于爱情
    CCD 驱动 时序理解
    写在博客的第一天
    51单片机最小系统
    swing之登陆功能
    TDSQL | 在整个技术解决方案中HTAP对应的混合交易以及分析系统应该如何实现?
    TDSQL | 深度解读HTAP系统的问题与主义之争
    硬核干货!TDSQL全局一致性读技术详解|
    35w奖金池,腾讯云TDSQL精英挑战赛等你来战!
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352405.html
Copyright © 2011-2022 走看看