这篇文章主要介绍“oracle中访问索引的方法有哪些”,在日常操作中,相信很多人在oracle中访问索引的方法有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”oracle中访问索引的方法有哪些”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
本文总结了访问索引的几种方法。
1、索引唯一扫描(INDEX UNIQUE SCAN)
(1)结果至多只返回一条记录
示例:
SQL> create table test.t as select * from dba_objects;
Table created
SQL> create unique index t_ius on t(object_id);
Index created.
SQL> select * from t where object_id=99338;
Execution Plan
----------------------------------------------------------
Plan hash value: 3945981348
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 207 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 207 | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | T_IUS | 1 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
2、索引范围扫描(INDEX RANGE SCAN)
(1)索引范围扫描的结果可能会返回多条记录
示例:
SQL> create index t_irs on t(object_id);
Index created.
SQL> select * from t where object_id=99338;
Execution Plan
----------------------------------------------------------
Plan hash value: 735526888
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 207 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 207 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T_IRS | 1 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
3、索引全扫描(INDEX FULL SCAN)
(1)扫描目标索引所有叶子块的所有索引行。
(2)索引全扫描的执行结果是有序的,避免了真正排序操作。
(3)通常情况下索引全扫面使用的是单块读。
(4)索引全扫面的前提条件是目标索引键值列的属性是not null.
示例:
SQL> select object_id from t where object_id is not null order by object_id;
72920 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3775890202
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 92167 | 1170K| 176 (0)| 00:00:03 |
|* 1 | INDEX FULL SCAN | T_IRS | 92167 | 1170K| 176 (0)| 00:00:03 |
--------------------------------------------------------------------------
4、索引快速全扫面(NDEX FAST FULL SCAN)
(1)和索引全扫面一样,扫描目标索引所有叶子块的所有索引行。
(2)索引快速全扫描只适用于CBO。
(3)索引快速全扫面可以多块读,也可以并行执行。
(4)索引快速全扫描的执行结果不一定是有序的。
示例:
SQL> select object_id from t where object_id is not null;
72920 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 723523614
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 92167 | 1170K| 49 (0)| 00:00:01 |
|* 1 | INDEX FAST FULL SCAN| T_IRS | 92167 | 1170K| 49 (0)| 00:00:01 |
———————————————————————————————————————d
5、索引跳跃式扫描(INDEX SKIP SCAN)
(1)适用于复合B树索引
(2) where条件中没有对目标索引的前导列指定查询条件同时又对该索引的非前导列指定了查询条件的sql依然可以用上该索引。
示例:
SQL> create index t_isc on t(object_id,object_name);
Index created.
SQL> select /*+ index_ss(t t_isc) */ object_name from t where object_name is not null;
72920 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2656528524
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 92167 | 5940K| 429 (1)| 00:00:06 |
|* 1 | INDEX SKIP SCAN | T_ISC | 92167 | 5940K| 429 (1)| 00:00:06 |
--------------------------------------------------------------------------
到此,关于“oracle中访问索引的方法有哪些”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。