Oracle 索引扫描的几种情况
index range scan(索引范围扫描):
1.对于unique index来说,如果where 条件后面出现了<,> ,between ...and...的时候,那么就可能执行index range scan,如果where条件后面是=,那么就会执行index unique scan。
2.对于none unique index来说 如果where 条件后面出现了=,>,<,betweed...and...的时候,就有可能执行index range scan。
3.对于组合索引来说,如果where条件后面出现了组合索引的引导列,那么可能执行index range scan。
index fast full scan(索引快速全扫描):
如果select 语句后面中的列都被包含在组合索引中,而且where后面没有出现组合索引的引导列,并且需要检索出大部分数据,那么这个时候可能执行index fast full scan。index fast full scan 发生的条件:
1.必须是组合索引 ?。2.引导列不在where条件中
index skip scan(索引跳跃式扫描)
当查询可以通过组合索引得到结果,而且返回结果很少,并且where条件中没有包含索引引导列的时候,可能执行index skip scan
索引跳跃式扫描发生的条件:
1.必须是组合索引。
2.引导列没有出现在where条件中
-eg1
SQL> create table test as select * from dba_objects; Table created. SQL> create unique index ind_id on test(object_id); Index created. SQL> create index ind_owner on test(owner); Index created. SQL> create index ooo on test(owner,object_name,object_type); Index created. SQL> exec dbms_stats.gather_table_stats('SCOTT','TEST'); PL/SQL procedure successfully completed. SQL> set autot trace SQL> select owner from test where object_id=10; Execution Plan
----------------------------------------------------------
Plan hash value: 2544773305 --------------------------------------------------------------------------------
------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
| --------------------------------------------------------------------------------
------ | 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:0
0:01 | | 1 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 11 | 2 (0)| 00:0
0:01 | |* 2 | INDEX UNIQUE SCAN | IND_ID | 1 | | 1 (0)| 00:0
0:01 | --------------------------------------------------------------------------------
------ Predicate Information (identified by operation id):
--------------------------------------------------- 2 - access("OBJECT_ID"=10) Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
524 bytes sent via SQL*Net to client
524 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 owner from test where object_id<10; 8 rows selected. Execution Plan
----------------------------------------------------------
Plan hash value: 1361604213 --------------------------------------------------------------------------------
------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
| --------------------------------------------------------------------------------
------ | 0 | SELECT STATEMENT | | 8 | 88 | 3 (0)| 00:0
0:01 | | 1 | TABLE ACCESS BY INDEX ROWID| TEST | 8 | 88 | 3 (0)| 00:0
0:01 | |* 2 | INDEX RANGE SCAN | IND_ID | 8 | | 2 (0)| 00:0
0:01 | --------------------------------------------------------------------------------
------ Predicate Information (identified by operation id):
--------------------------------------------------- 2 - access("OBJECT_ID"<10) Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
5 consistent gets
0 physical reads
0 redo size
609 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
8 rows processed
对于唯一索引,发生index range scan的时候就是返回多行记录,where后面有<,>,between..and 等返回扫描
SQL> select owner from test where owner='SCOTT'; Execution Plan
----------------------------------------------------------
Plan hash value: 2280863269 ------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3613 | 21678 | 9 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IND_OWNER | 3613 | 21678 | 9 (0)| 00:00:01 |
------------------------------------------------------------------------------ Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("OWNER"='SCOTT') Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
526 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
对于非唯一索引,即使where后面是=条件,但也可能返回多行,也是index range scan扫描
SQL> select object_name,object_type from test where owner='SCOTT'; Execution Plan
----------------------------------------------------------
Plan hash value: 2845720098 -------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3613 | 141K| 28 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| OOO | 3613 | 141K| 28 (0)| 00:00:01 |
------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("OWNER"='SCOTT') Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
610 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
因为这个索引不是唯一索引,where后面的列用到了索引000,所以进行index range scan
SQL> select owner, object_name,object_type from test where object_name='EMP' ; no rows selected Execution Plan
----------------------------------------------------------
Plan hash value: 1799988433 -------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 80 | 26 (0)| 00:00:01 |
|* 1 | INDEX SKIP SCAN | OOO | 2 | 80 | 26 (0)| 00:00:01 |
------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("OBJECT_NAME"='EMP')
filter("OBJECT_NAME"='EMP') Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
28 consistent gets
0 physical reads
0 redo size
479 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
上面的查询可以通过索引000来得到,并且where后面没有用到索引列,而且返回的行数很少(。)所以cbo选择index skip scan
select owner, object_name,object_type from test where object_type='INDEX';
Execution Plan
----------------------------------------------------------
Plan hash value: 3464522019 -----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1971 | 78840 | 168 (1)| 00:00:03 |
|* 1 | INDEX FAST FULL SCAN| OOO | 1971 | 78840 | 168 (1)| 00:00:03 |
----------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - filter("OBJECT_TYPE"='INDEX') Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
957 consistent gets
0 physical reads
0 redo size
199834 bytes sent via SQL*Net to client
4253 bytes received via SQL*Net from client
341 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5088 rows processed
同上,但是这里返回行数较多,cbo选择了index fast full scan,避免了全表扫描
Oracle 索引扫描的几种情况的更多相关文章
- Oracle 索引扫描的4种类型
根据索引的类型与where限制条件的不同,有4种类型的Oracle索引扫描: 3,4可归一种 (1) 索引唯一扫描(index uniquescan) (2) 索引范围扫描(index range s ...
- Oracle 索引扫描的五种类型
之前在讨论CBO和RBO的时候提到了索引扫描的几种类型. Oracle Optimizer CBO RBO http://blog.csdn.net/tianlesoftware/archive/20 ...
- Oracle索引扫描
Oracle索引扫描:先通过index查找到索引的值,并根据索引的值对应的rowid值(对于非唯一索引可能返回多个rowid值)直接从表中得到具体的数据.一个rowid唯一的表示一行数据,该行对应的数 ...
- MySQL索引失效的几种情况
1.索引不存储null值 更准确的说,单列索引不存储null值,复合索引不存储全为null的值.索引不能存储Null,所以对这列采用is null条件时,因为索引上根本 没Null值,不能利用到索引, ...
- mysql索引总结(4)-MySQL索引失效的几种情况
mysql索引总结(1)-mysql 索引类型以及创建 mysql索引总结(2)-MySQL聚簇索引和非聚簇索引 mysql索引总结(3)-MySQL聚簇索引和非聚簇索引 mysql索引总结(4)-M ...
- oracle数据库中索引失效的几种情况
原文1:https://blog.csdn.net/u012255097/article/details/102792683 原文2:https://www.cnblogs.com/lanseyita ...
- Oracle索引扫描算法
SQL> create table t as select * from dba_objects; Table created. SQL> create index idx_t on t( ...
- oracle 索引扫描类型的分类与构造
1. INDEX RANGE SCAN--请记住这个INDEX RANGE SCAN扫描方式drop table t purge;create table t as select * from dba ...
- mysql 索引失效的几种情况+
随机推荐
- easyui datagrid 行编辑功能
datagrid现在具有行编辑能力了,使用时只须在columns中为需要编辑的列添加一个editor属性,编辑保存时同时具有数据校验能力. 看一个例子效果图: 代码如下: $('#tt').datag ...
- 如何用VC编写供PB调用的DLL
和编写一般的DLL方法相同,需要注意以下两点: (1)调用约定 c函数有_stdcall._cdecl._fastcall等多种调用约定,调用约定用来说明函数参数的压栈顺序和由谁(函数自身还是调用者) ...
- 【转】Java设计模式-单例模式详解
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6510196.html 所谓单例,指的就是单实例,有且仅有一个类实例,这个单例不应该由人来控 ...
- srs部署到ubuntu 18.04 server
srs.txt ubuntu 18.04 安装 srs 1. 上传srs_40.7z和h2ws.7z到linux服务器,然后远程ssh连接 (假设登陆用户名是bob,linux服务器ip是192.16 ...
- sha1加密
SHA-1是一种数据加密算法,该算法的思维是接纳一段明文,然后以一种不可逆的方式将它转换成一段(一般更小)密文, 也能够简略的理解为取一串输入码(称为预映射或信息),并把它们转化为长度较短.位数固定的 ...
- 在一个web 应用中,改变url无非是2种方式,一种是利用超链接进行跳转,另一种是使用浏览器的前进和回退功能
在一个web 应用中,改变url无非是2种方式,一种是利用超链接进行跳转,另一种是使用浏览器的前进和回退功能 https://www.jianshu.com/p/27ee7df4ccc1
- Activity的基本概念与Activity的生命周期
一.Activity的基本概念 Activity是Android的四大组件之一,它是一种可以包含用户界面的组件,主要用于和用户进行交互,比如打电话,照相,发送邮件,或者显示一个地图!Activity用 ...
- Template pattern模板方法模式
1>模板模式定义了算法的步骤,把这些步骤的实现延续到子类 2>模板模式为我们提供了一个代码复用的技巧 3>模板抽象类中可以定义具体方法.抽象方法和钩子方法 4>为了防止子类改变 ...
- Sqlite/ FMDB
Sqlite 1. Sqlite数据库 > 数据库? 按数据结构来组织,存储和管理数据的仓库. > 关系型数据库:使用二维表及其之间的联系组织成一个数据组织. 关系:可以理解为一张二维表, ...
- xhtml html
xhtml是用xml语言重写了html,相比html更规范了, XHTML是HTML像XML的一个过渡语言,它比HTML严谨性会高点,然后基本语言都还是沿用的HTML的标签,只不过废除了部分表现层的标 ...