INDEX RANGE SCAN DESCENDING的邏輯讀問題
itpub:http://www.itpub.net/thread-1335784-1-1.html
INDEX RANGE SCAN DESCENDING的邏輯讀126明顯大於INDEX RANGE SCAN 5,但最佳化器依然選擇了INDEX RANGE SCAN DESCENDING
這裡先不討論最佳化器的選擇,僅僅看看是否INDEX RANGE SCAN DESCENDING的邏輯讀會高的這麼厲害
下面是測試程式碼:
[@more@]SQL> create table emp (id,name) as select object_id,object_name from dba_objects
;
表已建立。
SQL> create index t_idx_emp on emp(id);
索引已建立。
SQL> set arraysize 5000
SQL> select id,name from emp where id between 100 and 1000;
已選擇845行。
執行計劃
----------------------------------------------------------
Plan hash value: 162245774
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 845 | 66755 | 7 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 845 | 66755 | 7 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T_IDX_EMP | 845 | | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID">=100 AND "ID"<=1000)
Note
-----
- dynamic sampling used for this statement (level=4)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
9 consistent gets
0 physical reads
0 redo size
22102 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
845 rows processed
SQL> select id,name from emp where id between 100 and 1000 order by id;
已選擇845行。
執行計劃
----------------------------------------------------------
Plan hash value: 162245774
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 845 | 66755 | 7 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 845 | 66755 | 7 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T_IDX_EMP | 845 | | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID">=100 AND "ID"<=1000)
Note
-----
- dynamic sampling used for this statement (level=4)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
9 consistent gets
0 physical reads
0 redo size
22102 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
845 rows processed
SQL> select id,name from emp where id between 100 and 1000 order by id desc;
已選擇845行。
執行計劃
----------------------------------------------------------
Plan hash value: 1596401432
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 845 | 66755 | 7 (0)|00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | EMP | 845 | 66755 | 7 (0)|00:00:01 |
|* 2 | INDEX RANGE SCAN DESCENDING| T_IDX_EMP | 845 | | 3 (0)|00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID">=100 AND "ID"<=1000)
Note
-----
- dynamic sampling used for this statement (level=4)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
9 consistent gets
0 physical reads
0 redo size
22102 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
845 rows processed
SQL> select /*+ index(emp) */ id,name from emp where id between 100 and 1000 ord
er by id desc;
已選擇845行。
執行計劃
----------------------------------------------------------
Plan hash value: 1321738087
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 845 | 66755 | 8 (13)|00:00:01 |
| 1 | SORT ORDER BY | | 845 | 66755 | 8 (13)|00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 845 | 66755 | 7 (0)|00:00:01 |
|* 3 | INDEX RANGE SCAN | T_IDX_EMP | 845 | | 3 (0)|00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("ID">=100 AND "ID"<=1000)
Note
-----
- dynamic sampling used for this statement (level=4)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
22078 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
845 rows processed
SQL> set arraysize 15
SQL> select id,name from emp where id between 100 and 1000;
已選擇845行。
執行計劃
----------------------------------------------------------
Plan hash value: 162245774
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 845 | 66755 | 7 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 845 | 66755 | 7 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T_IDX_EMP | 845 | | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID">=100 AND "ID"<=1000)
Note
-----
- dynamic sampling used for this statement (level=4)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
121 consistent gets
0 physical reads
0 redo size
29382 bytes sent via SQL*Net to client
1031 bytes received via SQL*Net from client
58 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
845 rows processed
SQL> select id,name from emp where id between 100 and 1000 order by id desc;
已選擇845行。
執行計劃
----------------------------------------------------------
Plan hash value: 1596401432
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 845 | 66755 | 7 (0)|00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | EMP | 845 | 66755 | 7 (0)|00:00:01 |
|* 2 | INDEX RANGE SCAN DESCENDING| T_IDX_EMP | 845 | | 3 (0)|00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID">=100 AND "ID"<=1000)
Note
-----
- dynamic sampling used for this statement (level=4)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
121 consistent gets
0 physical reads
0 redo size
29382 bytes sent via SQL*Net to client
1031 bytes received via SQL*Net from client
58 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
845 rows processed
SQL> select id,name from emp where id between 100 and 1000 order by id;
已選擇845行。
執行計劃
----------------------------------------------------------
Plan hash value: 162245774
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 845 | 66755 | 7 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 845 | 66755 | 7 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T_IDX_EMP | 845 | | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID">=100 AND "ID"<=1000)
Note
-----
- dynamic sampling used for this statement (level=4)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
121 consistent gets
0 physical reads
0 redo size
29382 bytes sent via SQL*Net to client
1031 bytes received via SQL*Net from client
58 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
845 rows processed
SQL> select /*+ index(emp) */ id,name from emp where id between 100 and 1000 ord
er by id desc;
已選擇845行。
執行計劃
----------------------------------------------------------
Plan hash value: 1321738087
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 845 | 66755 | 8 (13)|00:00:01 |
| 1 | SORT ORDER BY | | 845 | 66755 | 8 (13)|00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 845 | 66755 | 7 (0)|00:00:01 |
|* 3 | INDEX RANGE SCAN | T_IDX_EMP | 845 | | 3 (0)|00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("ID">=100 AND "ID"<=1000)
Note
-----
- dynamic sampling used for this statement (level=4)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
26058 bytes sent via SQL*Net to client
1031 bytes received via SQL*Net from client
58 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
845 rows processed
對於select /*+ index(emp) */ id,name from emp where id between 100 and 1000 ord
er by id desc;
貌似不受arraysize的影響,不是經過了特殊的最佳化,就是個BUG。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/19423/viewspace-1036681/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- index range scan,index fast full scan,index skip scan發生的條件IndexAST
- Index Range Scan (214)Index
- oracle index unique scan/index range scan和mysql range/const/ref/eq_ref的區別OracleIndexMySql
- 高效的SQL(index range scan優化排序)SQLIndex優化排序
- Index Range Scan成本與10053Index
- [總結]關於index range scans & INDEX (FAST FULL SCAN)IndexAST
- Index Range Scan成本 Histogram 和 10053IndexHistogram
- INDEX UNIQUE SCAN,INDEX FULL SCAN和INDEX FAST FULL SCANIndexAST
- Index的掃描方式:index full scan/index fast full scanIndexAST
- rowid,index,INDEX FULL SCAN,INDEX FAST FULL SCAN|IndexAST
- Index Full Scan vs Index Fast Full ScanIndexAST
- Index Full Scan 與 Index Fast Full ScanIndexAST
- INDEX FULL SCAN和INDEX FAST FULL SCAN的區別IndexAST
- index full scan 和 index fast full scan (IFS,FFS)的不同IndexAST
- 《金子塔原理》讀書筆記之解決問題的邏輯筆記
- INDEX FULL SCAN和INDEX FAST FULL SCAN區別IndexAST
- index full scan 和 index FAST full scan 區別IndexAST
- Index Full Scan 與 Index Fast Full Scan (Final)IndexAST
- INDEX SKIP SCANIndex
- oracle 物理讀 邏輯讀的理解Oracle
- oracle 物理讀,邏輯讀的理解Oracle
- Clustered Index Scan and Clustered Index SeekIndex
- 邏輯題
- 理解index skip scanIndex
- Index Unique Scan (213)Index
- Oracle物理讀和邏輯讀Oracle
- MySQL range問題MySql
- PostgreSQL DBA(119) - pgAdmin(LIMIT:Index Scan vs Bitmap Index Scan)SQLMITIndex
- Index Full Scan和Index Fast Full Scan行為差異分析(上)IndexAST
- Index Full Scan和Index Fast Full Scan行為差異分析(下)IndexAST
- oracle邏輯讀過程Oracle
- Oracle邏輯讀詳解Oracle
- 深入瞭解ORACLE的邏輯讀Oracle
- mysql loose index scan的實現MySqlIndex
- [轉貼]Skip Scan IndexIndex
- 關於INDEX SKIP SCANIndex
- [20230908]Oracle Index Range Scan with LIKE Condition on Wildcard '_'.txtOracleIndex
- 【優化】INDEX FULL SCAN (MIN/MAX)訪問路徑優化Index