手机版
你好,游客 登录 注册
背景:
阅读新闻

创建索引前后执行计划的变更和软硬解析的比较

[日期:2013-09-05] 来源:Linux社区  作者:sunjiapeng [字体:大 中 小]

可以很清晰的从执行计划中看出,优化器走了全表扫描,并执行了硬解析;

再次执行上述查询:

SQL> select object_id,object_name from tt where object_id=10; 
 
 OBJECT_ID      OBJECT_NAME
----------      --------------------------------------- 
        10      C_USER# 
 
Execution Plan 
---------------------------------------------------------- 
Plan hash value: 264906180 
 
-------------------------------------------------------------------------- 
| Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time    | 
-------------------------------------------------------------------------- 
|  0 | SELECT STATEMENT  |      |    8 |  632 |  156  (1)| 00:00:02 | 
|*  1 |  TABLE ACCESS FULL| TT  |    8 |  632 |  156  (1)| 00:00:02 | 
-------------------------------------------------------------------------- 
 
Predicate Information (identified by operation id): 
--------------------------------------------------- 
 
  1 - filter("OBJECT_ID"=10) 
 
Note 
----- 
  - dynamic sampling used for this statement 
 
 
Statistics 
---------------------------------------------------------- 
          0  recursive calls 
          0  db block gets 
        707  consistent gets 
          0  physical reads 
          0  redo size 
        481  bytes sent via SQL*Net to client 
        400  bytes received via SQL*Net from client 
          2  SQL*Net roundtrips to/from client 
          0  sorts (memory) 
          0  sorts (disk) 
          1  rows processed 
 
SQL> 

执行计划虽依然走全表扫描,但是执行了软解析,这里的主要原因是在共享池中存在同样的SQL语句的一个副本(两条语句一模一样)

SQL> select object_id,OBJECT_NAME from tt where object_id=10;
 
 OBJECT_ID          OBJECT_NAME
----------          ------------------------------------------------- 
        10          C_USER# 
 
Execution Plan 
---------------------------------------------------------- 
Plan hash value: 264906180 
 
-------------------------------------------------------------------------- 
| Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time    | 
-------------------------------------------------------------------------- 
|  0 | SELECT STATEMENT  |      |    8 |  632 |  156  (1)| 00:00:02 | 
|*  1 |  TABLE ACCESS FULL| TT  |    8 |  632 |  156  (1)| 00:00:02 | 
-------------------------------------------------------------------------- 
 
Predicate Information (identified by operation id): 
--------------------------------------------------- 
 
  1 - filter("OBJECT_ID"=10) 
 
Note 
----- 
  - dynamic sampling used for this statement 
 
 
Statistics 
---------------------------------------------------------- 
          4  recursive calls 
          0  db block gets 
        779  consistent gets 
          0  physical reads 
          0  redo size 
        481  bytes sent via SQL*Net to client 
        400  bytes received via SQL*Net from client 
          2  SQL*Net roundtrips to/from client 
          0  sorts (memory) 
          0  sorts (disk) 
          1  rows processed 
 
SQL> select OBJECT_ID,OBJECT_NAME from tt where object_id=10; 

 OBJECT_ID      OBJECT_NAME
----------      ---------------------------------------------- 
        10      C_USER# 
 
Execution Plan 
---------------------------------------------------------- 
Plan hash value: 264906180 
 
-------------------------------------------------------------------------- 
| Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time    | 
-------------------------------------------------------------------------- 
|  0 | SELECT STATEMENT  |      |    8 |  632 |  156  (1)| 00:00:02 | 
|*  1 |  TABLE ACCESS FULL| TT  |    8 |  632 |  156  (1)| 00:00:02 | 
-------------------------------------------------------------------------- 
 
Predicate Information (identified by operation id): 
--------------------------------------------------- 
 
  1 - filter("OBJECT_ID"=10) 
 
Note 
----- 
  - dynamic sampling used for this statement 
 
 
Statistics 
---------------------------------------------------------- 
          4  recursive calls 
          0  db block gets 
        779  consistent gets 
          0  physical reads 
          0  redo size 
        481  bytes sent via SQL*Net to client 
        400  bytes received via SQL*Net from client 
          2  SQL*Net roundtrips to/from client 
          0  sorts (memory) 
          0  sorts (disk) 
          1  rows processed 
 
SQL> 

linux
相关资讯       Oracle索引 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款