索引回表操作,ORACLE所作的優化
create table t2 as select * from dba_objects where 1=0;
begin
for i in 1 ... 1000000 loop
insert into t2(object_id) values(SEQ_AP_ISSUE.nextval);
commit;
end loop;
end;
/
select
2 /*+ gather_plan_statistics index(t2) */
3 dbms_rowid.ROWID_RELATIVE_FNO(rowid) rfile#,
4 dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block#
5 from
6 t2
7 where
8 object_id between 120000 and 120110
9 ;
RFILE# BLOCK#
---------- ----------
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
共計111條記錄
select
2 /*+ gather_plan_statistics index(t2) */
3 count(object_name)
4 from
5 t2
6 where
7 object_id between 120000 and 120110
8 ;
COUNT(OBJECT_NAME)
------------------
0
select * from table(dbms_xplan.display_cursor('f2gq4d8xdm382',null,'iostats last'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID f2gq4d8xdm382, child number 0
-------------------------------------
select /*+ gather_plan_statistics index(t2) */ count(object_name) from
t2 where object_id between 120000 and 120110
Plan hash value: 2103910247
-----------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.01 | 112 |
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 112 |
| 2 | TABLE ACCESS BY INDEX ROWID| T2 | 1 | 111 | 111 |00:00:00.01 | 112 |
|* 3 | INDEX RANGE SCAN | TTTT | 1 | 111 | 111 |00:00:00.01 | 4 |
-----------------------------------------------------------------------------------------------
112-4=98,ORACLE只是對連續能命中一個塊的索引鍵值回表操作做了優化,只回表一次,而對於1 2 1 2 1 2這種索引鍵值,只是每次讀取一個鍵值就回表一次
begin
for i in 1 ... 1000000 loop
insert into t2(object_id) values(SEQ_AP_ISSUE.nextval);
commit;
end loop;
end;
/
select
2 /*+ gather_plan_statistics index(t2) */
3 dbms_rowid.ROWID_RELATIVE_FNO(rowid) rfile#,
4 dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block#
5 from
6 t2
7 where
8 object_id between 120000 and 120110
9 ;
RFILE# BLOCK#
---------- ----------
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
13 51211
13 51208
共計111條記錄
select
2 /*+ gather_plan_statistics index(t2) */
3 count(object_name)
4 from
5 t2
6 where
7 object_id between 120000 and 120110
8 ;
COUNT(OBJECT_NAME)
------------------
0
select * from table(dbms_xplan.display_cursor('f2gq4d8xdm382',null,'iostats last'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID f2gq4d8xdm382, child number 0
-------------------------------------
select /*+ gather_plan_statistics index(t2) */ count(object_name) from
t2 where object_id between 120000 and 120110
Plan hash value: 2103910247
-----------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.01 | 112 |
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 112 |
| 2 | TABLE ACCESS BY INDEX ROWID| T2 | 1 | 111 | 111 |00:00:00.01 | 112 |
|* 3 | INDEX RANGE SCAN | TTTT | 1 | 111 | 111 |00:00:00.01 | 4 |
-----------------------------------------------------------------------------------------------
112-4=98,ORACLE只是對連續能命中一個塊的索引鍵值回表操作做了優化,只回表一次,而對於1 2 1 2 1 2這種索引鍵值,只是每次讀取一個鍵值就回表一次
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22034023/viewspace-764372/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 索引的優化Oracle索引優化
- Oracle對索引分析的優化Oracle索引優化
- Oracle union all 不走索引的優化Oracle索引優化
- mysql優化 | 儲存引擎,建表,索引,sql的優化建議MySql優化儲存引擎索引
- oracle索引操作Oracle索引
- Oracle優化案例-正確的使用索引(二)Oracle優化索引
- oracle優化器和不走索引的原因Oracle優化索引
- Oracle效能優化之虛擬索引Oracle優化索引
- MySQL 的覆蓋索引與回表MySql索引
- 理解索引:索引優化索引優化
- Oracle優化案例-分割槽索引之無字首索引(六)Oracle優化索引
- Oracle優化-索引原理[注意索引跳躍式掃描!Oracle優化索引
- ORACLE 9i資料庫優化案例(2) --- 單列索引變複合索引的優化Oracle資料庫優化索引
- oracle update操作的優化一例Oracle優化
- 【oracle 效能優化】組合索引查詢。Oracle優化索引
- 達夢SQL優化-回表BLKUP2SQL優化
- MSSQL優化之索引優化SQL優化索引
- oracle全文索引之同步和優化索引做了什麼Oracle索引優化
- Mysql索引優化之索引的分類MySql索引優化
- Oracle優化案例-單表分頁語句的優化(八)Oracle優化
- Oracle表與索引的分析及索引重建Oracle索引
- Oracle堆組織表的索引和索引組織表Oracle索引
- Oracle優化案例-自定義函式索引(五)Oracle優化函式索引
- Elasitcsearch索引優化索引優化
- MySQL索引優化MySql索引優化
- mysql優化索引MySql優化索引
- SQL優化-索引SQL優化索引
- 藉助索引+非空優化distinct操作一例索引優化
- MySQL 效能優化之索引優化MySql優化索引
- oracle分割槽表的常規操作導致對索引的影響Oracle索引
- MySQL 覆蓋索引、回表查詢MySql索引
- Oracle 之 閃回操作Oracle
- 使用Elasticsearch的動態索引和索引優化Elasticsearch索引優化
- Oracle表與索引的分析及索引重建(轉)Oracle索引
- 優化Oracle with全表掃描的問題優化Oracle
- ORACLE表連線方式的分析與優化Oracle優化
- SQL精華總結索引型別優化SQL優化事務大表優化思維導圖❤️SQL索引型別優化
- 【oracle 效能優化】組合索引之index_ssOracle優化索引Index