您好,登錄后才能下訂單哦!
這篇文章主要介紹“oracle中訪問(wèn)索引的方法有哪些”,在日常操作中,相信很多人在oracle中訪問(wèn)索引的方法有哪些問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”oracle中訪問(wèn)索引的方法有哪些”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
本文總結(jié)了訪問(wèn)索引的幾種方法。
1、索引唯一掃描(INDEX UNIQUE SCAN)
(1)結(jié)果至多只返回一條記錄
示例:
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)索引范圍掃描的結(jié)果可能會(huì)返回多條記錄
示例:
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)掃描目標(biāo)索引所有葉子塊的所有索引行。
(2)索引全掃描的執(zhí)行結(jié)果是有序的,避免了真正排序操作。
(3)通常情況下索引全掃面使用的是單塊讀。
(4)索引全掃面的前提條件是目標(biāo)索引鍵值列的屬性是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)和索引全掃面一樣,掃描目標(biāo)索引所有葉子塊的所有索引行。
(2)索引快速全掃描只適用于CBO。
(3)索引快速全掃面可以多塊讀,也可以并行執(zhí)行。
(4)索引快速全掃描的執(zhí)行結(jié)果不一定是有序的。
示例:
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)適用于復(fù)合B樹(shù)索引
(2) where條件中沒(méi)有對(duì)目標(biāo)索引的前導(dǎo)列指定查詢條件同時(shí)又對(duì)該索引的非前導(dǎo)列指定了查詢條件的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 |
--------------------------------------------------------------------------
到此,關(guān)于“oracle中訪問(wèn)索引的方法有哪些”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。