時間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評論(1)
1、優(yōu)化器默認為CBO,OPTIMIZER_MODE默認值為ALL_ROWS。不再使用古老的RBO模式,但RULE、CHOOSE并沒有徹底消失,有些時候仍然可以作為我們調(diào)試的工具。
2、CPU Costing的計算方式現(xiàn)在默認為CPU+I/O兩者之和.可通過DBMS_XPLAN.DISPLAY_CURSOR觀察更為詳細的執(zhí)行計劃。
3、增加了幾個有用SQL Hints:
INDEX_SS[[@block] tabs [inds]],INDEX_SS_ASC,INDEX_SS_DESC;SS為SKIP SCAN的縮寫。skip scan以前討論的很多。
NO_USE_N[[@block] tabs],NO_USE_HAHS,NO_USE_MERGE,NO_INDEX_FFS,NO_INDEX_SS,NO_STAR_TRANSFORMATION,NO_QUERY_TRANSFORMATION.
這幾個HINT不用解釋,一看就知道目的是什么。
USE_NL_WITH_INDEX([@block] tabs [index]):這個提示和Nested Loops有關(guān),通過提示我們可以指定Nested Loops循環(huán)中的內(nèi)部表,也就是開始循環(huán)連接其他表的表。CBO是否會執(zhí)行取決于指定表是否有索引鍵關(guān)聯(lián)。
QB_NAME(@blockname) 這個提示可以給某個查詢定義一個name,并且可以在其他hints中使用這個name,并且將這個hints作用到這個name對應(yīng)的查詢中.其實從10G開始,Oracle對一些特定的查詢自動使用queryblockname
4、10G中支持在hint中使用queryblockname
select * from a1 where id in (select /*+ qb_name(sub1) */ id
from a1 where id in (2,10,12));
Execution Plan
----------------------------------------------------------
Plan hash value: 173249654
-----------------------------------------------------------------------------------------
| Id? | Operation | Name????? | Rows? | Bytes | Cost (%CPU)| Time???? |
-----------------------------------------------------------------------------------------
|?? 0 | SELECT STATEMENT????? |???? |???? 2 |??? 34 |???? 3? (34)| 00:00:01 |
|?? 1 |? TABLE ACCESS BY INDEX ROWID| A1? |???? 1 |??? 14 |???? 1?? (0)| 00:00:01 |
|?? 2 |?? NESTED LOOPS? |???? |???? 2 |??? 34 |???? 3? (34)| 00:00:01 |
|?? 3 |??? SORT UNIQUE? |???? |???? 2 |???? 6 |???? 1?? (0)| 00:00:01 |
|?? 4 |???? INLIST ITERATOR?? |???? | | |????? |??? |
|*? 5 |????? INDEX RANGE SCAN | IDX_A1_ID |???? 2 |???? 6 |???? 1?? (0)| 00:00:01 |
|*? 6 |??? INDEX RANGE SCAN?? | IDX_A1_ID |???? 1 | |???? 0?? (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
---------------
select * from a1 where id in (select /*+ qb_name(sub1) full(@sub1 a1) */ id
from a1 where id in (2,10,12));
Plan hash value: 1882950619
-----------------------------------------------------------------------------------------
| Id? | Operation | Name????? | Rows? | Bytes | Cost (%CPU)| Time???? |
-----------------------------------------------------------------------------------------
|?? 0 | SELECT STATEMENT????? |???? |???? 2 |??? 34 |??? 17?? (6)| 00:00:01 |
|?? 1 |? TABLE ACCESS BY INDEX ROWID| A1? |???? 1 |??? 14 |???? 1?? (0)| 00:00:01 |
|?? 2 |?? NESTED LOOPS? |???? |???? 2 |??? 34 |??? 17?? (6)| 00:00:01 |
|?? 3 |??? SORT UNIQUE? |???? |???? 2 |???? 6 |??? 15?? (0)| 00:00:01 |
|*? 4 |????? TABLE ACCESS FULL????? | A1? |???? 2 |???? 6 |??? 15?? (0)| 00:00:01 |
|*? 5 |??? INDEX RANGE SCAN?? | IDX_A1_ID |???? 1 | |???? 0?? (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
-----------
修改成錯誤的queryblockname
select * from a1 where id in (select /*+ qb_name(sub1) full(@sub2 a1) */ id from a1 where id in (2,10,12));
Execution Plan
----------------------------------------------------------
Plan hash value: 173249654
-----------------------------------------------------------------------------------------
| Id? | Operation | Name????? | Rows? | Bytes | Cost (%CPU)| Time???? |
-----------------------------------------------------------------------------------------
|?? 0 | SELECT STATEMENT????? |???? |???? 2 |??? 34 |???? 3? (34)| 00:00:01 |
|?? 1 |? TABLE ACCESS BY INDEX ROWID| A1? |???? 1 |??? 14 |???? 1?? (0)| 00:00:01 |
|?? 2 |?? NESTED LOOPS? |???? |???? 2 |??? 34 |???? 3? (34)| 00:00:01 |
|?? 3 |??? SORT UNIQUE? |???? |???? 2 |????
關(guān)鍵詞標(biāo)簽:Oracle,SQL優(yōu)化
相關(guān)閱讀
熱門文章 Oracle中使用alter table來增加,刪除,修改列的語法 oracle中使用SQL語句修改字段類型-oracle修改SQL語句案例 誤刪Oracle數(shù)據(jù)庫實例的控制文件 為UNIX服務(wù)器設(shè)置Oracle全文檢索
人氣排行 oracle中使用SQL語句修改字段類型-oracle修改SQL語句案例 Oracle中使用alter table來增加,刪除,修改列的語法 ORACLE SQL 判斷字符串是否為數(shù)字的語句 ORACLE和SQL語法區(qū)別歸納(1) oracle grant 授權(quán)語句 ORACLE修改IP地址后如何能夠使用 如何加速Oracle大批量數(shù)據(jù)處理 Oracle刪除表的幾種方法