zoukankan      html  css  js  c++  java
  • select count(*)和select * 区别

    explain plan for select * from F_AGT_BUSINESS_CONTRACT_H a where a.end_dt=date'2999-12-31';




    select * from table(dbms_xplan.display());


    Plan hash value: 3544262987
     
    -----------------------------------------------------------------------------------------------
    | Id  | Operation         | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |                           |   255K|   151M| 55276   (1)| 00:11:04 |
    |*  1 |  TABLE ACCESS FULL| F_AGT_BUSINESS_CONTRACT_H |   255K|   151M| 55276   (1)| 00:11:04 |
    -----------------------------------------------------------------------------------------------
     
    Predicate Information (identified by operation id):
    ---------------------------------------------------
     
       1 - filter("A"."END_DT"=TO_DATE(' 2999-12-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))


    ###########################################################################################################


    explain plan for select count(*) from F_AGT_BUSINESS_CONTRACT_H a where a.end_dt=date'2999-12-31';




    select * from table(dbms_xplan.display());
    Plan hash value: 2053193161
     
    ----------------------------------------------------------------------------------------------------
    | Id  | Operation         | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |                                |     1 |     8 |   681   (1)| 00:00:09 |
    |   1 |  SORT AGGREGATE   |                                |     1 |     8 |            |          |
    |*  2 |   INDEX RANGE SCAN| F_AGT_BUSINESS_CONTRACT_H_IDX3 |   255K|  1992K|   681   (1)| 00:00:09 |
    ----------------------------------------------------------------------------------------------------
     
    Predicate Information (identified by operation id):
    ---------------------------------------------------
     
       2 - access("A"."END_DT"=TO_DATE(' 2999-12-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))


    count(*)可以直接从索引返回数据,故可以走索引


    select * 需要索引访问后回表,Oracle认为cost高于索引扫描,故选择全表扫描

  • 相关阅读:
    .net的25个小技巧
    使用ASP.Net2.0国际化你的网站祥解
    国外C#开源项目(转)
    千千阙歌
    js中var的有或无重复声明和以后的声明
    XMLHttpRequest
    java参数与引用
    Total Commander
    XMLDOM 的async属性
    Java内嵌类
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352191.html
Copyright © 2011-2022 走看看