oracle hints index格式
只是簡單記錄關於加index hints的格式
標準加hint方式
/*+index(表名 索引名)*/
SQL> create table t5 (a int,b int);
Table created.
declare
begin
for i in 1..5000 loop
insert into t5 values(i,i+1);
end loop;
commit;
end;
SQL> execute dbms_stats.gather_table_stats('SYS','T5');
PL/SQL procedure successfully completed.
SQL> create index t5_id on t5(a);
Index created.
SQL> select /*+index(t5 t5_id)*/* from t5 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 711254476
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 18 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T5 | 4001 | 28007 | 18 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T5_ID | 4001 | | 10 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("A">1000)
SQL> select /*+index(t5 t5_id)*/* from t5 t55 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 2002323537
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 5 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T5 | 4001 | 28007 | 5 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("A">1000)
有別名就是 別名 索引名
SQL> select /*+index(t55 t5_id)*/* from t5 t55 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 711254476
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 18 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T5 | 4001 | 28007 | 18 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T5_ID | 4001 | | 10 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("A">1000)
直接用表名,會選擇where上的index(自動)根據cost 選擇,如果cost都一樣,那麼此時候按index名字順序 比如a,z選a
SQL> select /*+index(t5)*/* from t5 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 711254476
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 18 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T5 | 4001 | 28007 | 18 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T5_ID | 4001 | | 10 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("A">1000)
有時候rename index是件很麻煩的事 尤其對於加hint引用這個index的sql,10g開始,oracle可以直接 表名(表名.列名) 這樣 好處是不依賴於這個index name而是這個列上的index
SQL> select /*+index(t5(t5.a))*/* from t5 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 711254476
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 18 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T5 | 4001 | 28007 | 18 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T5_ID | 4001 | | 10 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("A">1000)
SQL> select /*+index(t55(t55.a))*/* from t5 t55 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 2002323537
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 5 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T5 | 4001 | 28007 | 5 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("A">1000)
對於有別名的表 就是(別名(表名.列名))
SQL> select /*+index(t55(t5.a))*/* from t5 t55 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 711254476
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 18 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T5 | 4001 | 28007 | 18 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T5_ID | 4001 | | 10 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("A">1000)
SQL> select /*+index(t5(t5.a))*/* from t5 t55 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 2002323537
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 5 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T5 | 4001 | 28007 | 5 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("A">1000)
SQL> select /*+index(t5(t55.a))*/* from t5 t55 where a>1000;
Execution Plan
----------------------------------------------------------
Plan hash value: 2002323537
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4001 | 28007 | 5 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T5 | 4001 | 28007 | 5 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("A">1000)
SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12020513/viewspace-631365/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL index hints 使用MySqlIndex
- Oracle HintsOracle
- Oracle Hints詳解Oracle
- oracle hints的使用Oracle
- Oracle Hints的用法Oracle
- Oracle使用提示(Hints)Oracle
- index 和 index_desc hints的一點有意思的區別Index
- oracle hints用法總結Oracle
- Oracle Hints語句的用法Oracle
- oracle hints的那點事Oracle
- How to use hints in Oracle sql for performanceOracleSQLORM
- oracle hints ? use_hash ? ordered ?Oracle
- oracle效能優化之--hintsOracle優化
- oracle sql tunning all hintsOracleSQL
- Oracle leading vs. ordered hintsOracle
- oracle 體系 & hints的用法總結(轉)Oracle
- WITH AS and materialize hints
- oracle index unusableOracleIndex
- oracle document indexOracleIndex
- Oracle Index InternalsOracleIndex
- 【Oracle】global index & local index的區別OracleIndex
- oracle index索引原理OracleIndex索引
- zt_oracle indexOracleIndex
- oracle hint_no_indexOracleIndex
- oracle index monitoringOracleIndex
- oracle index 聚集因子OracleIndex
- 【譯】Resource Hints
- oracle hint之full,index,index_asc,index_desc,index_combile示例OracleIndex
- oracle hint之hint_index_ffs,index_joinOracleIndex
- ORACLE中index的rebuildOracleIndexRebuild
- Using hints for PostgresqlSQL
- oracle invisible index與unusable index的區別OracleIndex
- oracle 日期格式Oracle
- Oracle索引分裂(Index Block Split)Oracle索引IndexBloC
- oracle hint_no_parallel_no_parallel_indexOracleParallelIndex
- oracle hint_parallel_parallel_indexOracleParallelIndex
- Oracle alter index rebuild 說明OracleIndexRebuild
- [轉載]oracle_Bitmap IndexOracleIndex