返回顶部
首页 > 资讯 > 数据库 >索引优化系列二 回表
  • 838
分享到

索引优化系列二 回表

2024-04-02 19:04:59 838人浏览 薄情痞子
摘要

--索引回表读(TABLE ACCESS BY INDEX ROWID)的例子drop table t purge;create table t as select * from dba_obje

--索引回表读(TABLE ACCESS BY INDEX ROWID)的例子

drop table t purge;

create table t as select * from dba_objects;

create index idx1_object_id on t(object_id);


--试验1

set autotrace traceonly

set linesize 1000

set timing on

select * from t where object_id<=5;


执行计划

----------------------------------------------------------------------------------------------

| Id  | Operation                   | Name           | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                |     4 |   828 |     3   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| T              |     4 |   828 |     3   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX1_OBJECT_ID |     4 |       |     2   (0)| 00:00:01 |

----------------------------------------------------------------------------------------------

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

          5  consistent gets

          0  physical reads

          0  redo size

       1666  bytes sent via sql*Net to client

        415  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          4  rows processed


--比较消除TABLE ACCESS BY INDEX ROWID回表后的性能,将select * from改为select object_id from 

set autotrace traceonly

set linesize 1000

set timing on


select object_id from t where object_id<=5;

执行计划

-----------------------------------------------------------------------------------

| Id  | Operation        | Name           | Rows  | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------

|   0 | SELECT STATEMENT |                |     4 |    52 |     2   (0)| 00:00:01 |

|*  1 |  INDEX RANGE SCAN| IDX1_OBJECT_ID |     4 |    52 |     2   (0)| 00:00:01 |

-----------------------------------------------------------------------------------

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

          3  consistent gets

          0  physical reads

          0  redo size

        478  bytes sent via SQL*Net to client

        415  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          4  rows processed




--试验2:通过构造联合索引,再观察一个消除TABLE ACCESS BY INDEX ROWID的例子

set autotrace traceonly

set linesize 1000

select object_id,object_name from t where object_id<=5;

执行计划

----------------------------------------------------------------------------------------------

| Id  | Operation                   | Name           | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                |     4 |   316 |     3   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| T              |     4 |   316 |     3   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX1_OBJECT_ID |     4 |       |     2   (0)| 00:00:01 |

----------------------------------------------------------------------------------------------

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

          5  consistent gets

          0  physical reads

          0  redo size

        567  bytes sent via SQL*Net to client

        415  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          4  rows processed

          

--准备工作,对t表建联合索引

create index idx_un_objid_objname on t(object_id,object_name);

--该联合索引建完后,产生功效了!消除了TABLE ACCESS BY INDEX ROWID


select object_id,object_name from t where object_id<=5;

执行计划

-----------------------------------------------------------------------------------------

| Id  | Operation        | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT |                      |    12 |   948 |     2   (0)| 00:00:01 |

|*  1 |  INDEX RANGE SCAN| IDX_UN_OBJID_OBJNAME |    12 |   948 |     2   (0)| 00:00:01 |

-----------------------------------------------------------------------------------------

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

          3  consistent gets

          0  physical reads

          0  redo size

        567  bytes sent via SQL*Net to client

        415  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          4  rows processed

 

 


您可能感兴趣的文档:

--结束END--

本文标题: 索引优化系列二 回表

本文链接: https://lsjlt.com/news/40974.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作