您好,欢迎访问一九零五行业门户网

Oracle TABLE ACCESS BY INDEX ROWID 说明

oracle table access by index rowid 说明,rowid是伪列(pseudocolumn),在查询结果输出时它被构造出来的。rowid并不会真正存在
一.  测试环境
sql> select * from v$version where rownum=1; 
banner
--------------------------------------------------------------------------------
oracle database 11g enterprise edition release11.2.0.3.0 - 64bit production 
sql> create table dave as selectobject_id,object_name,object_type,created,timestamp,status from all_objects;
表已创建。 
sql> create table dave2 as select * from dave;
表已创建。 
--收集统计信息,这里没有收集直方图:
sql> exec dbms_stats.gather_table_stats(ownname=>'sys',tabname =>'dave',estimate_percent => 10 ,method_opt =>'forcolumns size 1',degree=>10,cascade => true); 
pl/sql 过程已成功完成。 
sql> exec dbms_stats.gather_table_stats(ownname=>'sys',tabname =>'dave2',estimate_percent => 10 ,method_opt =>'forcolumns size 1',degree=>10,cascade => true); 
pl/sql 过程已成功完成。 
sql> alter system flush buffer_cache; 
系统已更改。 
--查看全表扫描时的执行计划:
sql> set autot traceonly 
sql> select d1.object_name,d2.object_type fromdave d1,dave2 d2 where d1.object_id=d2.object_id; 
已选择72762行。 
执行计划
----------------------------------------------------------
plan hash value: 3613449503 
------------------------------------------------------------------------------------
| id  |operation          | name  | rows | bytes |tempspc| cost (%cpu)| time    |
------------------------------------------------------------------------------------
|   0 |select statement   |       | 72520 |  3824k|      |   695   (1)| 00:00:09 |
|*  1 |  hash join         |      | 72520 |  3824k|  2536k|  695   (1)| 00:00:09 |
|   2 |   table access full| dave2 | 71990 |  1687k|      |   213   (1)| 00:00:03 |
|   3 |   table access full| dave  | 72520 | 2124k|       |   213  (1)| 00:00:03 |
------------------------------------------------------------------------------------ 
predicate information (identified by operation id):
--------------------------------------------------- 
   1 -access(d1.object_id=d2.object_id) 
统计信息
----------------------------------------------------------
         0  recursive calls
         0  db block gets
      6353  consistent gets
       1558  physical reads
         0  redo size
   3388939  bytes sent via sql*net toclient
     53874  bytes received via sql*netfrom client
      4852  sql*net roundtrips to/fromclient
         0  sorts (memory)
         0  sorts (disk)
     72762  rows processed
sql>
sql> create index idx_dave_object_idon dave(object_id);
索引已创建。
sql> create index idx_dave_object_id2 ondave2(object_id);
索引已创建。 
--在次查看执行计划: 
sql> select d1.object_name,d2.object_type fromdave d1,dave2 d2 where d1.object_id=d2.object_id; 
已选择72762行。 
执行计划
----------------------------------------------------------
plan hash value: 3613449503
------------------------------------------------------------------------------------
| id  |operation          | name  | rows | bytes |tempspc| cost (%cpu)| time    |
------------------------------------------------------------------------------------
|   0 |select statement   |       | 72520 |  3824k|      |   695   (1)| 00:00:09 |
|*  1 |  hash join         |      | 72520 |  3824k|  2536k|  695   (1)| 00:00:09 |
|   2 |   table access full| dave2 | 71990 |  1687k|      |   213   (1)| 00:00:03 |
|   3 |   table access full| dave  | 72520 | 2124k|       |   213  (1)| 00:00:03 |
------------------------------------------------------------------------------------ 
predicate information (identified by operation id):
--------------------------------------------------- 
   1 -access(d1.object_id=d2.object_id) 
统计信息
----------------------------------------------------------
         1  recursive calls
         0  db block gets
      6353  consistent gets
          0  physical reads
         0  redo size
   3388939  bytes sent via sql*net toclient
     53874  bytes received via sql*netfrom client
      4852  sql*net roundtrips to/fromclient
         0  sorts (memory)
         0  sorts (disk)
     72762  rows processed 
这里的物理读为0. 但是还是走的是全表扫描。 
sql> alter system flush buffer_cache; 
系统已更改。 
sql> select d1.object_name,d2.object_type fromdave d1,dave2 d2 where d1.object_id=d2.object_id  and d1.object_id
已选择98行。 
执行计划
----------------------------------------------------------
plan hash value: 504164237 
----------------------------------------------------------------------------------------------------
| id  |operation                    | name                | rows  | bytes | cost (%cpu)| time     |
----------------------------------------------------------------------------------------------------
|   0 |select statement             |                     |  3600 |  189k|    23   (5)| 00:00:01 |
|*  1 |  hash join                   |                     |  3600 |  189k|    23   (5)| 00:00:01 |
|   2 |   table access by index rowid| dave2               |  3600 | 86400 |    11  (0)| 00:00:01 |
|*  3 |    index range scan          | idx_dave_object_id2 |   648 |      |     3   (0)| 00:00:01 |
|   4 |   table access by index rowid| dave                |  3626 |  106k|    11   (0)| 00:00:01 |
|*  5 |    index range scan          | idx_dave_object_id  |   653|       |     3  (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------- 
predicate information (identified by operation id):
---------------------------------------------------
1 -access(d1.object_id=d2.object_id)
   3 -access(d2.object_id
   5 -access(d1.object_id
统计信息
----------------------------------------------------------
         1  recursive calls
         0  db block gets
        20  consistent gets
         6  physical reads
         0  redo size
      3317  bytes sent via sql*net toclient
       590  bytes received via sql*netfrom client
         8  sql*net roundtrips to/fromclient
         0  sorts (memory)
         0  sorts (disk)
        98  rows processed
sql> 
走索引之后,物理读从1558降到6.

其它类似信息

推荐信息