共計 3846 個字符,預計需要花費 10 分鐘才能閱讀完成。
這篇文章主要介紹“oracle 中訪問索引的方法有哪些”,在日常操作中,相信很多人在 oracle 中訪問索引的方法有哪些問題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”oracle 中訪問索引的方法有哪些”的疑惑有所幫助!接下來,請跟著丸趣 TV 小編一起來學習吧!
本文總結了訪問索引的幾種方法。
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 中訪問索引的方法有哪些”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注丸趣 TV 網站,丸趣 TV 小編會繼續努力為大家帶來更多實用的文章!