Optimizer_mode引數

THANK_DBA發表於2013-12-04

optimizer_mode =choose

這個是Oracle的預設值。採用這個值時,Oracle即可以採用基於規則RBO,也可以採用基於代價的CBO,到底使用那個值,取決於當前SQL被訪問的表中是不是有可以使用的統計資訊。如果有多個被訪問的表,其中有一個或多個有統計資訊,那麼Oralce會對沒有統計資訊的表進行取樣統計(即不全部取樣),統計完成後,使用基於代價的優化方法CBO。如果所有被訪問的表都沒有統計資訊,Oracle就會採用基於規則的優化方法RBO

 

Optimizer_mode=First_rows

oracle 9i之後這一選項已經過時,出於向後相容的目的保留了這一選項,該選項的作用在於尋找能夠在最短的時間內返回結果集的第一行的執行計劃。這一規則傾向於促使優化器使用索引訪問路徑,偶爾會出現非常不恰當的訪問路徑。

設定為這種CBO模式以後,SQL語句返回結果的速度會盡可能的快,而不管系統全部的查詢是否會耗時較長或者耗系統資源過多。由於利用索引會使查詢速度加快,所以 first_rows 優化模式會在全表掃描上進行索引掃描。這種優化模式一般適合於一些OLTP系統,滿足使用者能夠在較短時間內看到較小查詢結果集的要求。

 

Optimizer_mode=all_rows

優化器將尋找能夠在最短的時間內完成語句的執行計劃。

設定為這種CBO模式以後,將保證消耗的所有計算資源最小,儘管有時查詢結束以後沒有結果返回。all_rows 的優化模式更傾向於全表掃描,而不是全索引掃描和利用索引排序,因此這種優化模式適合於資料檢視實時性不是那麼強的資料倉儲、決策支援系統和麵向批處理的 資料庫(batch-oriented databases)等。

 

Optimizer_mode=first_rows_N

N的值可以為1101001000,優化器首先通過徹底分析第一個連線順序來估計返回行的總數目。這樣就可以知道查詢可能獲得的整個資料集的片段,並重新啟動整個優化過程,其目標在於找到能夠以最小的資源消耗返回整個資料片段的執行計劃。

Oracle 9i 對一些預期返回結果集的資料量小的SQL語句優化模式進行了加強,增加了四個引數值:first_rows_1first_rows_10 first_rows_100first_rows_1000CBO通過first_rows_n 中的 n 值,決定了返回結果集數量的基數,我們可能僅僅需要查詢結果集中的一部分,CBO就根據這樣的 n 值來決定是否使用索引掃描。

 

optimizer_mode = rule

基於規則的優化器模式,RBO,是早期Oracle版本使用過的一種優化模式。由於 RBO不支援自1994Oracle版本的新特性,如 bitmap indexestable partitionsfunction-based indexes等,所以在以後Oracle版本中已經不再更新RBO,並且也不推薦使用者使用RBO這種優化模式了。

這是9i的文件:

CHOOSE

The optimizer chooses between a cost-based approach and a rule-based approach, depending

on whether statistics are available. This is the default value.

n If the data dictionary contains statistics for at least one of the accessed tables, then the

optimizer uses a cost-based approach and optimizes with a goal of best throughput.

n If the data dictionary contains only some statistics, then the cost-based approach is still

used, but the optimizer must guess the statistics for the subjects without any statistics.

This can result in suboptimal execution plans.

n If the data dictionary contains no statistics for any of the accessed tables, then the

optimizer uses a rule-based approach.

ALL_ROWS

The optimizer uses a cost-based approach for all SQL statements in the session regardless of

the presence of statistics and optimizes with a goal of best throughput (minimum resource use

to complete the entire statement).

FIRST_ROWS_n

 The optimizer uses a cost-based approach, regardless of the presence of statistics, and

optimizes with a goal of best response time to return the first n number of rows; n can equal 1,

10, 100, or 1000.

FIRST_ROWS

The optimizer uses a mix of cost and heuristics to find a best plan for fast delivery of the first

few rows. Note: Using heuristics sometimes leads the CBO to generate a plan with a cost that is

significantly larger than the cost of a plan without applying the heuristic. FIRST_ROWS is

available for backward compatibility and plan stability.

RULE

The optimizer chooses a rule-based approach for all SQL statements regardless of the presence of statistics.

而在10g的文件中,我們看到值被減少到3個,而描述也不盡相同。

ALL_ROWS

The optimizer uses a cost-based approach for all SQL statements in the session regardless of the presence of statistics and optimizes with a goal of best throughput (minimum resource use to complete the entire statement). This is the default value.

FIRST_ROWS_n

The optimizer uses a cost-based approach, regardless of the presence of statistics, and optimizes with a goal of best response time to return the first n number of rows; n can equal 1, 10, 100,

or 1000.

FIRST_ROWS

 The optimizer uses a mix of cost and heuristics to find a best plan for fast delivery of the first few rows. Note: Using heuristics sometimes leads the query optimizer to generate a plan with a cost that is significantly larger than the cost of a plan without applying the heuristic. FIRST_ROWS is

available for backward compatibility and plan stability; use FIRST_ROWS_n instead.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29366942/viewspace-1062237/,如需轉載,請註明出處,否則將追究法律責任。

相關文章