Heim >Datenbank >MySQL-Tutorial >Oracle 索引访问方式

Oracle 索引访问方式

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 16:47:01974Durchsuche

Oracle 索引访问方式,唯一索引扫描,唯一索引即做单一匹配。在唯一索引中,每个非空键值只有唯一的一条,主键也是唯一索引。

Oracle 索引访问方式

本篇记录一些Oracle索引访问操作

表访问方式请参考:

显示执行计划的存储过程请参考

(1)INDEX UNIQUE SCAN

唯一索引扫描,唯一索引即做单一匹配。在唯一索引中,每个非空键值只有唯一的一条,主键也是唯一索引。示例:

SQL> exec sql_explain('select * from emp where empno=8888');
Plan hash value: 2949544139
--------------------------------------------------------------------------------
------
| Id  | Operation                  | Name  | Rows  | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
------
|  0 | SELECT STATEMENT            |        |    1 |    39 |    1  (0)|
00:00:01 |
|  1 |  TABLE ACCESS BY INDEX ROWID| EMP    |    1 |    39 |    1  (0)|
00:00:01 |
|*  2 |  INDEX UNIQUE SCAN        | PK_EMP |    1 |      |    0  (0)|
00:00:01 |
--------------------------------------------------------------------------------
------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPNO"=8888)

PL/SQL 过程已成功完成。

(2)INDEX RANGE SCAN

非唯一索引扫描,对应唯一索引扫描,索引进行范围匹配,(例如>、

SQL> create table t_xyc as select * from emp;

表已创建。
SQL> insert into t_xyc  select * from emp;

已创建15行。

SQL> commit;

提交完成。
SQL> create index xyc_index on t_xyc(empno);

索引已创建。
---用等号(=)进行单一匹配
SQL> exec sql_explain('select * from t_xyc where empno=8888');
Plan hash value: 767710755
-----------------------------------------------------------------------------------------
| Id  | Operation                  | Name      | Rows  | Bytes | Cost (%CPU)| Time    |
-----------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT            |          |    2 |    78 |    4  (0)| 00:00:01 |
|  1 |  TABLE ACCESS BY INDEX ROWID| T_XYC    |    2 |    78 |    4  (0)| 00:00:01 |
|*  2 |  INDEX RANGE SCAN          | XYC_INDEX |    2 |      |    1  (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPNO"=8888)

PL/SQL 过程已成功完成。
----用大于(>)进行范围匹配
SQL> exec sql_explain('select * from t_xyc where empno>8888');
Plan hash value: 767710755
-----------------------------------------------------------------------------------------
| Id  | Operation                  | Name      | Rows  | Bytes | Cost (%CPU)| Time    |
-----------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT            |          |    2 |    78 |    4  (0)| 00:00:01 |
|  1 |  TABLE ACCESS BY INDEX ROWID| T_XYC    |    2 |    78 |    4  (0)| 00:00:01 |
|*  2 |  INDEX RANGE SCAN          | XYC_INDEX |    2 |      |    1  (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPNO">8888)

PL/SQL 过程已成功完成。

linux

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn