9i,10g 優化器動態取樣級別引數 -- optimizer_dynamic_sampling (統計優化)
我們經常會碰到由於一些表沒有分析導致執行計劃錯誤的情況,但是Oracle9.2 中dynamic sampling的出現一定程度的減少了錯誤的產生。dynamic sampling針對沒有分析過的表可以取樣估計表的選擇性,對於生產正確的執行計劃有一定的幫助。
優化器動態取樣級別引數 optimizer_dynamic_sampling ,是在Oracle9.2.0 版本之後才有的。設定級別可以由0到10, 0表示不進行動態取樣, 10 表示取樣級別最高。 Oracle9.2或以上(9i)下引數 optimizer_dynamic_sampling 預設值是1,Oracle10g 下預設值是2 。
Level 0: Do not dynamically sample the table(s) 不進行動態取樣 。
Level 1: Sample tables that have not been analyzed if there is more than one table in the query,the table in question has not been analyzed and it has no indexes,and the optimizer determines that the query plan would be affected based on the size of this objects
Level 2: Sample all unanalyzed tables referenced in teh query using default sampling amounts(small sample)
Level 3 -- Level 10 更詳細的sample 。
如果一個表沒有統計資訊,那麼,CBO優化器將採用預設的統計資料,這樣是很不準確的, 會直接導致錯誤的執行計劃 。利用optimizer_dynamic_sampling引數,CBO優化器可收集引用物件上足夠的統計資訊得出更加準確的執行計劃。 不過在Oracle9中需要有多表關聯的時候optimizer_dynamic_sampling才會起作用,單個表不起作用。在10g中在optimizer_dynamic_sampling >=2 (10g預設是2) 的時候單個表就能實現優化器動態取樣 。
我們知道,在Oracle9i, 10g中如果選擇的是CHOOSE優化模式,那麼在沒有分析統計資訊的時候,Oracle會選擇使用RULE 方式,Oracle9i中,如果使用HINT強制用CBO的話,系統會讀取一點資訊來模擬實際的統計資訊。當然Oracle10g 預設的優化模式是CBO ,所以除非人為更改,一般不會走RULE模式。
Oracle9i中如果關聯的兩個表都沒有分析,那麼 optimizer_dynamic_sampling 不起作用(可以sql trace 測試一下) , 關聯的表中有一個分析過了,那麼優化器動態取樣就起作用了。
但是Oracle10g中如果兩個表都沒有分析,optimizer_dynamic_sampling 也會起作用。 以上應該都是由於Oracle10g中已經沒有了基於RULE的優化器,在9i中如果一個查詢中所有的表都沒有分析,那麼它會選擇rule優化器,而忽略掉 dynamic sampling 。10g中已經沒有了rule , 沒有選擇,只有 dynamic sampling。
---------------------------------------------------------------------------------
以下的解釋還在理解中,有朋友能很好理解關於取樣資料塊的請幫忙解釋一下 :
Level 1: Sample all tables that have not been analyzed if the following criteria are met: (1) there is at least 1 unanalyzed table in the query; (2) this unanalyzed table is joined to another table or appears in a subquery or non-mergeable view; (3) this unanalyzed table has no indexes; (4) this unanalyzed table has more blocks than the number of blocks that would be used for dynamic sampling of this table. The number of blocks sampled is the default number of dynamic sampling blocks (32).
Level 2: Apply dynamic sampling to all unanalyzed tables. The number of blocks sampled is the default number of dynamic sampling blocks.
-----------------------------------------------------------------------------------------------
更加詳細的Level :
-----------------------------------------------------------------------------------------------
Level 0: Do not use dynamic sampling.
Level 1: Sample all tables that have not been analyzed if the following criteria are met: (1) there is at least 1 unanalyzed table in the query; (2) this unanalyzed table is joined to another table or appears in a subquery or non-mergeable view; (3) this unanalyzed table has no indexes; (4) this unanalyzed table has more blocks than the number of blocks that would be used for dynamic sampling of this table. The number of blocks sampled is the default number of dynamic sampling blocks (32).
Level 2: Apply dynamic sampling to all unanalyzed tables. The number of blocks sampled is the default number of dynamic sampling blocks.
Level 3: Apply dynamic sampling to all tables that meet Level 2 criteria, plus all tables for which standard selectivity estimation used a guess for some predicate that is a potential dynamic sampling predicate. The number of blocks sampled is the default number of dynamic sampling blocks.
Level 4: Apply dynamic sampling to all tables that meet Level 3 criteria, plus all tables that have single-table predicates that reference 2 or more columns. The number of blocks sampled is the default number of dynamic sampling blocks.
Level 5: Apply dynamic sampling to all tables that meet the Level 4 criteria using 2 times the default number of dynamic sampling blocks.
Level 6: Apply dynamic sampling to all tables that meet the Level 5 criteria using 4 times the default number of dynamic sampling blocks.
Level 7: Apply dynamic sampling to all tables that meet the Level 6 criteria using 8 times the default number of dynamic sampling blocks.
Level 8: Apply dynamic sampling to all tables that meet the Level 7 criteria using 32 times the default number of dynamic sampling blocks.
Level 9: Apply dynamic sampling to all tables that meet the Level 8 criteria using 128 times the default number of dynamic sampling blocks.
Level 10: Apply dynamic sampling to all tables that meet the Level 9 criteria using all blocks in the table.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-592375/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 效能優化之快取引數優化MySql優化快取
- 【SQL優化器】初始化引數SQL優化
- MySQL 資料庫效能優化之快取引數優化MySql資料庫優化快取
- MySQL資料庫效能優化之快取引數優化(轉)MySql資料庫優化快取
- MySQL 配置InnoDB配置非持久優化器統計資訊引數MySql優化
- ActiveMQ 引數優化MQ優化
- Mysql優化系列(1)--Innodb重要引數優化MySql優化
- 使用預計算分割槽優化引數化優化
- 【sql調優】動態取樣SQL
- 10g升級至11g需要考慮的引數優化優化
- Laravel 數量統計優化Laravel優化
- Myisam & InnoDB 優化引數優化
- MySQL引數配置優化MySql優化
- 利用Oracle 10g SQL優化器(STA)優化語句Oracle 10gSQL優化
- oracle動態取樣_optimizer_dynamic_samplingOracle
- MySQL優化之系統變數優化MySql優化變數
- 優化-瀏覽器快取和壓縮優化優化瀏覽器快取
- Sklearn GridSearchCV 引數優化優化
- 動態Lambda(2):優化優化
- oracle動態取樣_optimizer_dynamic_sampling(二)Oracle
- Oracle控制優化器偏好--optimizer_mode引數Oracle優化
- Oracle查詢優化器的相關引數Oracle優化
- IT優化級別的選擇優化
- java優化程式設計-靜態變數Java優化程式設計變數
- SQL Server SQL效能優化之引數化SQLServer優化
- 【調優篇基本原理】優化器相關引數配置優化
- Linux系統優化部分核心引數調優中文註釋Linux優化
- TensorFlow筆記(5)——優化手寫數字識別模型之優化器筆記優化模型
- swoole優化核心引數調整優化
- Nginx實戰(六) 引數優化Nginx優化
- Linux 核心引數優化(for oracle)Linux優化Oracle
- Elasticsearch效能優化引數註解Elasticsearch優化
- spark job執行引數優化Spark優化
- OpenCV中的SVM引數優化OpenCV優化
- Mysql 效能優化--基礎引數MySql優化
- 【SQL 效能優化】引數設定SQL優化
- Oracle可變引數的優化Oracle優化
- weblogic幾個優化引數Web優化