【sql調優之執行計劃】使用hint(一)Hints for Optimization Approaches and Goals
版本:10.2.0.4
Hints for Optimization Approaches and Goals
可以通過使用hint來改變或者指定優化器對執行計劃的選擇,分類來看這些hint的使用規則和一些例子。
Hints for optimization approaches and goals
一些優化目標的hint比如:
All_rows,first_rows(n),rule
10g預設的優化模式是all_rows,也就是使用choose的時候優化器選擇的優化器模式。除了rule之外,其他都是CBO的優化模式。
看看hint對執行計劃影響的例子:
SQL> set linesize 1000
SQL> set autot traceonly explain;
SQL> select /*+ all_rows */* from scott.emp a,scott.dept b
2 where a.deptno = a.deptno;
Execution Plan
----------------------------------------------------------
Plan hash value: 2034389985
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 52 | 3016 | 8 (0)| 00:00:01 |
| 1 | MERGE JOIN CARTESIAN| | 52 | 3016 | 8 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL | DEPT | 4 | 80 | 3 (0)| 00:00:01 |
| 3 | BUFFER SORT | | 13 | 494 | 5 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | EMP | 13 | 494 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("A"."DEPTNO" IS NOT NULL)
SQL> select /*+ first_rows(2) */* from scott.emp a,scott.dept b
2 where a.deptno = a.deptno;
Execution Plan
----------------------------------------------------------
Plan hash value: 4192419542
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 116 | 4 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 2 | 116 | 4 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL| DEPT | 2 | 40 | 2 (0)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| EMP | 2 | 76 | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("A"."DEPTNO" IS NOT NULL)
SQL> select /*+ first_rows(100) */* from scott.emp a,scott.dept b
2 where a.deptno = a.deptno;
Execution Plan
----------------------------------------------------------
Plan hash value: 2034389985
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 52 | 3016 | 8 (0)| 00:00:01 |
| 1 | MERGE JOIN CARTESIAN| | 52 | 3016 | 8 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL | DEPT | 4 | 80 | 3 (0)| 00:00:01 |
| 3 | BUFFER SORT | | 13 | 494 | 5 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | EMP | 13 | 494 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("A"."DEPTNO" IS NOT NULL)
SQL>
或者使用rule的hint,即RBO:
SQL> select /*+ rule */* from scott.emp a,scott.dept b
2 where a.deptno = a.deptno;
Execution Plan
----------------------------------------------------------
Plan hash value: 4192419542
-----------------------------------
| Id | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | NESTED LOOPS | |
| 2 | TABLE ACCESS FULL| DEPT |
|* 3 | TABLE ACCESS FULL| EMP |
-----------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("A"."DEPTNO"="A"."DEPTNO")
Note
-----
- rule based optimizer used (consider using cbo)
SQL>
也可以使用choose,讓優化器自動選擇,這也是預設的情況
SQL> select /*+ choose */* from scott.emp a,scott.dept b
2 where a.deptno = a.deptno;
Execution Plan
----------------------------------------------------------
Plan hash value: 2034389985
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 52 | 3016 | 8 (0)| 00:00:01 |
| 1 | MERGE JOIN CARTESIAN| | 52 | 3016 | 8 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL | DEPT | 4 | 80 | 3 (0)| 00:00:01 |
| 3 | BUFFER SORT | | 13 | 494 | 5 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | EMP | 13 | 494 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("A"."DEPTNO" IS NOT NULL)
SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16179598/viewspace-671829/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【sql調優之執行計劃】使用hint(四)Hints for JoinSQL
- 【sql調優之執行計劃】使用hint(三)Hints for Query TransformationsSQLORM
- 【sql調優之執行計劃】使用hint(二)Hints for Access PathsSQL
- 【sql調優之執行計劃】使用hint(五)Hint for parallelSQLParallel
- 【sql調優之執行計劃】使用hint(六) append and noappendSQLAPP
- 【sql調優之執行計劃】獲取執行計劃SQL
- 【sql調優之執行計劃】sort operationsSQL
- 【sql調優之執行計劃】estimator iSQL
- 【sql調優之執行計劃】hash joinSQL
- 【sql調優之執行計劃】query transformerSQLORM
- 【sql調優之執行計劃】temp table transformationSQLORM
- 【sql調優之執行計劃】in相關的operationSQL
- 【sql調優之執行計劃】merge sort joinSQL
- mysql調優之——執行計劃explainMySqlAI
- 使用hint改變執行計劃
- 【Oracle】-【索引-HINT,執行計劃】-帶HINT的索引執行計劃Oracle索引
- Oracle調優之看懂Oracle執行計劃Oracle
- 加hint改變執行計劃訪問順序優化sql優化SQL
- 【sql調優之執行計劃】merge join cartesian and buffer sortSQL
- 使用Oracle Hint提示來更改執行計劃Oracle
- 【sql調優之執行計劃】merge semi join and merge anti joinSQL
- 【sql調優之執行計劃】nested loops join and nested loop join outerSQLOOP
- 使用hint來調優sql語句SQL
- 控制執行計劃之-SQL Profile(一)SQL
- SQL調優(SQL TUNING)並行查詢提示(Hints)之pq_distribute的使用SQL並行
- 使用Oracle Hint提示來更改執行計劃 ZTOracle
- 使用leading(,)優化sql執行計劃優化SQL
- 使用USE_HASH Hint調優一個SQL語句SQL
- sql調優一例---索引排序hintSQL索引排序
- Oracle+高效能SQL引擎剖析:SQL優化與調優機制詳解-筆記之執行計劃(一)OracleSQL優化筆記
- 透過使用hint unnest調優sql語句SQL
- 通過使用hint unnest調優sql語句SQL
- 建立索引調整sql的執行計劃索引SQL
- oracle筆記整理14——效能調優之oracle執行計劃Oracle筆記
- Oracle中SQL調優(SQL TUNING)之最權威獲取SQL執行計劃大全OracleSQL
- 轉摘_使用leading(,)優化sql執行計劃優化SQL
- 使用sql profile固定執行計劃SQL
- sql 執行計劃SQL