zoukankan      html  css  js  c++  java
  • 分页语句 where 条件列和Order by 列 引导列的问题

    SQL> select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));
    
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    SQL_ID	599jjhj1rar9u, child number 0
    -------------------------------------
    select rownum - 1 as xuhao, ggbt, czsj, fj, id	 from (select  *
       from mbank.t_ises_gg t	   where t.status = '1' 	   and
    to_date(t.zzrq, 'YYYY-MM-DD') >=		to_date('20150310',
    'YYYY-MM-DD')	       order by czsj desc)  where rownum <= 4
    
    Plan hash value: 747778291
    
    --------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation		       | Name		| Starts | E-Rows | A-Rows |   A-Time	| Buffers |  OMem |  1Mem | Used-Mem |
    --------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT	       |		|      1 |	  |	 4 |00:00:00.01 |      10 |	  |	  |	     |
    |*  1 |  COUNT STOPKEY		       |		|      1 |	  |	 4 |00:00:00.01 |      10 |	  |	  |	     |
    |   2 |   VIEW			       |		|      1 |	2 |	 4 |00:00:00.01 |      10 |	  |	  |	     |
    |*  3 |    SORT ORDER BY STOPKEY       |		|      1 |	2 |	 4 |00:00:00.01 |      10 |  4096 |  4096 | 4096  (0)|
    |   4 |     TABLE ACCESS BY INDEX ROWID| T_ISES_GG	|      1 |	2 |	29 |00:00:00.01 |      10 |	  |	  |	     |
    |*  5 |      INDEX RANGE SCAN	       | T_ISES_GG_IDX1 |      1 |	1 |	29 |00:00:00.01 |	1 |	  |	  |	     |
    --------------------------------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter(ROWNUM<=4)
       3 - filter(ROWNUM<=4)
       5 - access("T"."SYS_NC00019$">=TO_DATE('20150310','YYYY-MM-DD') AND "T"."STATUS"='1' AND "T"."SYS_NC00019$" IS NOT NULL)
           filter("T"."STATUS"='1')
    
    
    28 rows selected.
    
    
    
     create index mbank.t_ises_gg_idx1 on mbank.t_ises_gg(to_date(zzrq, 'YYYY-MM-DD'),czsj,status)
    
    
    此时创建的索引顺序为,where 条件列再前
    
    
    
    
    创建如下索引:
     create index mbank.t_ises_gg_idx1 on mbank.t_ises_gg(czsj,to_date(zzrq, 'YYYY-MM-DD'),status);
    
    order by 列在前
    
    
    SQL> select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));
    
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    SQL_ID	599jjhj1rar9u, child number 0
    -------------------------------------
    select rownum - 1 as xuhao, ggbt, czsj, fj, id	 from (select  *
       from mbank.t_ises_gg t	   where t.status = '1' 	   and
    to_date(t.zzrq, 'YYYY-MM-DD') >=		to_date('20150310',
    'YYYY-MM-DD')	       order by czsj desc)  where rownum <= 4
    
    Plan hash value: 3991473710
    
    ----------------------------------------------------------------------------------------------------------
    | Id  | Operation		      | Name	       | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
    ----------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT	      | 	       |      1 |	 |	4 |00:00:00.01 |       4 |
    |*  1 |  COUNT STOPKEY		      | 	       |      1 |	 |	4 |00:00:00.01 |       4 |
    |   2 |   VIEW			      | 	       |      1 |      2 |	4 |00:00:00.01 |       4 |
    |   3 |    TABLE ACCESS BY INDEX ROWID| T_ISES_GG      |      1 |      2 |	4 |00:00:00.01 |       4 |
    |*  4 |     INDEX FULL SCAN DESCENDING| T_ISES_GG_IDX1 |      1 |      1 |	4 |00:00:00.01 |       2 |
    ----------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter(ROWNUM<=4)
       4 - access("T"."STATUS"='1' AND "T"."SYS_NC00019$">=TO_DATE('20150310','YYYY-MM-DD'))
           filter(("T"."STATUS"='1' AND "T"."SYS_NC00019$">=TO_DATE('20150310','YYYY-MM-DD')))
    
    
    26 rows selected.
    
    此时只访问了4条记录。
    
    验证了 分页SQL 引导列不一定是where 条件列

  • 相关阅读:
    进程间通讯----消息队列和共享内存方式的实现
    初探 Yii2 的测试模式 index-test.php
    nginx缓存功能的设置
    php五大运行模式CGI,FAST-CGI,CLI,ISAPI,APACHE模式
    workerman如何写mysql连接池
    Varnish 一般是放在 Nginx 前面还是后面的?
    关于PATH_INFO
    Java8 Lambda表达式
    synchronized的一些记录
    类和实例
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351837.html
Copyright © 2011-2022 走看看