您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Oracle數據庫中索引的常見執行計劃是什么,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
今天主要介紹下Oracle索引的常見執行計劃:
INDEX FULL SCAN:索引的全掃描,單塊讀,有序
INDEX RANGE SCAN:索引的范圍掃描
INDEX FAST FULL SCAN:索引的快速全掃描,多塊讀,無序
INDEX FULL SCAN(MIN/MAX):針對MAX(),MIN()函數的查詢
INDEX SKIP SCAN:查詢條件沒有用到組合索引的第一列,而組合索引的第一列重復度較高時,可能用到。
這里用簡單的測試案例,體會下索引使用這些執行計劃的場景。
1. 準備測試環境
創建測試表和索引:
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';
分析表并清空測試環境的shared_pool和buffer_cache:
analyze table test_objects compute statistics; alter system flush shared_pool; alter system flush buffer_cache;
2. 準備SQL語句
根據不同執行計劃的場景,編寫SQL語句:
--INDEX RANGE SCAN(索引的范圍掃描) SELECT owner, object_name FROM test_objects WHERE owner = 'SYS' AND object_name = 'DBMS_OUTPUT'; --INDEX SKIP SCAN(針對MAX(),MIN()函數的查詢) 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()函數的查詢) SELECT max(object_id) FROM test_objects;
3. 實驗論證
結果如下:
(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數據庫中索引的常見執行計劃是什么就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。