這篇文章將為大家詳細講解有關Oracle數(shù)據(jù)庫中索引的常見執(zhí)行計劃是什么,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
成都創(chuàng)新互聯(lián)主要從事成都網(wǎng)站設計、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設公司、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務萬年,十余年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:13518219792
今天主要介紹下Oracle索引的常見執(zhí)行計劃:
INDEX FULL SCAN:索引的全掃描,單塊讀,有序
INDEX RANGE SCAN:索引的范圍掃描
INDEX FAST FULL SCAN:索引的快速全掃描,多塊讀,無序
INDEX FULL SCAN(MIN/MAX):針對MAX(),MIN()函數(shù)的查詢
INDEX SKIP SCAN:查詢條件沒有用到組合索引的第一列,而組合索引的第一列重復度較高時,可能用到。
這里用簡單的測試案例,體會下索引使用這些執(zhí)行計劃的場景。
1. 準備測試環(huán)境
創(chuàng)建測試表和索引:
drop table test_objects; create table test_objects as select * from all_objects; create index idx_test_objects_1 on test_objects(owner, object_name, subobject_name); create index idx_test_objects_2 on test_objects(object_id); desc test_objects;
查看測試表上的索引信息:
select index_name, column_name, column_position from user_ind_columns where table_name = 'TEST_OBJECTS';
分析表并清空測試環(huán)境的shared_pool和buffer_cache:
analyze table test_objects compute statistics; alter system flush shared_pool; alter system flush buffer_cache;
2. 準備SQL語句
根據(jù)不同執(zhí)行計劃的場景,編寫SQL語句:
--INDEX RANGE SCAN(索引的范圍掃描) SELECT owner, object_name FROM test_objects WHERE owner = 'SYS' AND object_name = 'DBMS_OUTPUT'; --INDEX SKIP SCAN(針對MAX(),MIN()函數(shù)的查詢) SELECT owner, object_name FROM test_objects WHERE object_name = 'DBMS_OUTPUT'; --INDEX FAST FULL SCAN(索引的快速全掃描,多塊讀,無序) SELECT owner, object_name FROM test_objects; --INDEX FULL SCAN(索引的全掃描,單塊讀,有序) SELECT owner, object_name FROM test_objects order by 1, 2; --INDEX FULL SCAN (MIN/MAX)(針對MAX(),MIN()函數(shù)的查詢) SELECT max(object_id) FROM test_objects;
3. 實驗論證
結(jié)果如下:
(1) INDEX RANGE SCAN
set autotrace traceonly SELECT owner, object_name FROM test_objects WHERE owner = 'SYS' AND object_name = 'DBMS_OUTPUT';
(2) INDEX SKIP SCAN
SELECT owner, object_name FROM test_objects WHERE object_name = 'DBMS_OUTPUT';
(3) INDEX FAST FULL SCAN
SELECT owner, object_name FROM test_objects;
(4) INDEX FULL SCAN
SELECT owner, object_name FROM test_objects order by 1, 2;
(5) INDEX FULL SCAN (MIN/MAX)
SELECT max(object_id) FROM test_objects;
關于Oracle數(shù)據(jù)庫中索引的常見執(zhí)行計劃是什么就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。