oracle hint之full,index,index_asc,index_desc,index_combile示例
oracle hint之full,index,index_asc,index_desc,index_combile示例
1,full hint
SQL> explain plan for select a,b from t_test where a=3;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------
Plan hash value: 3273242040
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------
Plan hash value: 3273242040
--------------------------------------------------------------------------------
----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------------------
----------
| 0 | SELECT STATEMENT | | 1 | 8 | 4 (0)|
00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_TEST | 1 | 8 | 4 (0)|
00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_T_TEST | 1 | | 3 (0)|
00:00:01 |
--------------------------------------------------------------------------------
----------
----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------------------
----------
| 0 | SELECT STATEMENT | | 1 | 8 | 4 (0)|
00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_TEST | 1 | 8 | 4 (0)|
00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_T_TEST | 1 | | 3 (0)|
00:00:01 |
--------------------------------------------------------------------------------
----------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------
---------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------
---------------------------------------------------
2 - access("A"=3)
已選擇14行。
SQL> explain plan for select /*+ full(t_test) */ a,b from t_test where a=3;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------
Plan hash value: 2796558804
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------
Plan hash value: 2796558804
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 306 (2)| 00:00:04 |
|* 1 | TABLE ACCESS FULL| T_TEST | 1 | 8 | 306 (2)| 00:00:04 |
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 306 (2)| 00:00:04 |
|* 1 | TABLE ACCESS FULL| T_TEST | 1 | 8 | 306 (2)| 00:00:04 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
---------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------
1 - filter("A"=3)
已選擇13行。
SQL>
hash int
hash提示對指定的表進行hash 掃描,它僅適用於cluster table中的表
hash提示對指定的表進行hash 掃描,它僅適用於cluster table中的表
index hint
index提示如果對錶指定多個索引列表,oracle僅會選取成本最低的索引進行掃描表,而不會同時使用列表中所有索引,可以用index_combile
SQL> explain plan for select a,b from t_test where a=1 and b=1;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Plan hash value: 3273242040
--------------------------------------------------------------------------------
----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
Time |
--------------------------------------------------------------------------------
----------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 4 (0)|
00:00:01 |
00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| T_TEST | 1 | 8 | 4 (0)|
00:00:01 |
00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_T_TEST | 1 | | 3 (0)|
00:00:01 |
00:00:01 |
--------------------------------------------------------------------------------
----------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
---------------------------------------------------
1 - filter("B"=1)
2 - access("A"=1)
2 - access("A"=1)
已選擇15行。
--oracle依舊僅應用一個索引,而非a,b列的兩個索引
SQL> explain plan for select /*+ index(t_test idx_t_test idx_t_b) */ a,b from
t_test where a=1 and b=1;
SQL> explain plan for select /*+ index(t_test idx_t_test idx_t_b) */ a,b from
t_test where a=1 and b=1;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Plan hash value: 3273242040
--------------------------------------------------------------------------------
----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
Time |
--------------------------------------------------------------------------------
----------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 4 (0)|
00:00:01 |
00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| T_TEST | 1 | 8 | 4 (0)|
00:00:01 |
00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_T_TEST | 1 | | 3 (0)|
00:00:01 |
00:00:01 |
--------------------------------------------------------------------------------
----------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
---------------------------------------------------
1 - filter("B"=1)
2 - access("A"=1)
2 - access("A"=1)
已選擇15行。
index_combile hint
1,連線多個索引進行訪問表
2,以點陣圖方式訪問表
3,如果不指定索引,oracle使用經評估後最小成本的索引組合來訪問表
SQL> explain plan for select /*+ index_combine(t_test idx_t_test idx_t_b) */
a,b from t_test where a=1 and b=1;
a,b from t_test where a=1 and b=1;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Plan hash value: 3260031232
-------------------------------------------------------------------------------
--------------
| Id | Operation | Name | Rows | Bytes | Cost (%C
U)| Time |
-------------------------------------------------------------------------------
--------------
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 951
1)| 00:00:12 |
| 1 | BITMAP CONVERSION TO ROWIDS | | 1 | 8 | 951
1)| 00:00:12 |
| 2 | BITMAP AND | | | |
| |
| |
| 3 | BITMAP CONVERSION FROM ROWIDS| | | |
| |
| |
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
|* 4 | INDEX RANGE SCAN | IDX_T_TEST | | | 3
0)| 00:00:01 |
| 5 | BITMAP CONVERSION FROM ROWIDS| | | |
| |
| |
|* 6 | INDEX RANGE SCAN | IDX_T_B | | | 946 --先查詢單個索引,然後轉化為點陣圖,繼而把點陣圖進行與操作,即把兩個索引進行組合運算,因為where條件是and
此時把點陣圖再轉化為rowid,最後用rowid定位查詢到的表記錄
大家看點陣圖訪問成本很高的,要N步驟
此時把點陣圖再轉化為rowid,最後用rowid定位查詢到的表記錄
大家看點陣圖訪問成本很高的,要N步驟
1)| 00:00:12 |
-------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
--------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("A"=1)
6 - access("B"=1)
6 - access("B"=1)
已選擇19行。
SQL> explain plan for select /*+ index_combine(t_test) */ a,b from t_test wh
re a=1 and b=1;
re a=1 and b=1;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Plan hash value: 3260031232
-------------------------------------------------------------------------------
--------------
| Id | Operation | Name | Rows | Bytes | Cost (%C
U)| Time |
-------------------------------------------------------------------------------
--------------
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 951
1)| 00:00:12 |
| 1 | BITMAP CONVERSION TO ROWIDS | | 1 | 8 | 951
1)| 00:00:12 |
| 2 | BITMAP AND | | | |
| |
| |
| 3 | BITMAP CONVERSION FROM ROWIDS| | | |
| |
| |
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
|* 4 | INDEX RANGE SCAN | IDX_T_TEST | | | 3
0)| 00:00:01 |
| 5 | BITMAP CONVERSION FROM ROWIDS| | | |
| |
| |
|* 6 | INDEX RANGE SCAN | IDX_T_B | | | 946
1)| 00:00:12 |
-------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
--------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("A"=1)
6 - access("B"=1)
6 - access("B"=1)
已選擇19行。
SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-751317/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 索引反向使用案例,加index_desc hint索引Index
- oracle hint之hint_index_ffs,index_joinOracleIndex
- oracle hint_no_indexOracleIndex
- Use index_descIndex
- oracle hint_no_parallel_no_parallel_indexOracleParallelIndex
- oracle hint_parallel_parallel_indexOracleParallelIndex
- rowid,index,INDEX FULL SCAN,INDEX FAST FULL SCAN|IndexAST
- Index Full Scan vs Index Fast Full ScanIndexAST
- Index Full Scans和Index Fast Full ScansIndexAST
- Index Full Scan 與 Index Fast Full ScanIndexAST
- How to Specify an INDEX Hint oracle官方文件IndexOracle
- INDEX UNIQUE SCAN,INDEX FULL SCAN和INDEX FAST FULL SCANIndexAST
- Index的掃描方式:index full scan/index fast full scanIndexAST
- 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
- oracle hint_skip scan_index_ssOracleIndex
- INDEX FULL SCAN和INDEX FAST FULL SCAN的區別IndexAST
- LOCAL INDEX和HINT的使用【DO BE USED LOCAL INDEX IN HINT】薦Index
- oracle hint_use_concat_use_nl_with_indexOracleIndex
- index full scan 和 index fast full scan (IFS,FFS)的不同IndexAST
- sql優化一例(index_desc)SQL優化Index
- oracle之hint概述Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(五)Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(四)Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(三)Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(二)Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(一)Oracle
- Index Full Scan和Index Fast Full Scan行為差異分析(上)IndexAST
- Index Full Scan和Index Fast Full Scan行為差異分析(下)IndexAST
- index 和 index_desc hints的一點有意思的區別Index
- Oracle學習系列—資料庫最佳化—Full Scans和Fast Full Index ScansOracle資料庫ASTIndex
- Oracle之Hint使用總結Oracle
- 【HINT】使用“NO_INDEX ”Hint提示避免SQL使用特定索引IndexSQL索引
- index fast full scan 和 nullIndexASTNull
- Fast full index scan 淺析ASTIndex
- 收集full table / index scan sqlIndexSQL
- 【SQL 提示 之二】index_ss Index Skip HintSQLIndex