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高于索引扫描,故选择全表扫描

  • 相关阅读:
    leetcode二叉树翻转二叉树
    编译PBRTv2
    人最大的快乐不是赚多少钱,而是将一个一个的梦想付诸实现。
    今天终于把工作的事定下了安心开始新的学习
    Ogre学习(二)
    关于游戏引擎关于心情
    Ogitor的安装与使用
    软件随想录
    Lost in Island
    OGRE学习(一)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352191.html
Copyright © 2011-2022 走看看