oracle動態取樣_optimizer_dynamic_sampling
SQL> show parameter optimizer_dynamic_sam
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_dynamic_sampling integer 2
SQL> create table t_sample(a int);
------------------------------------ ----------- ------------------------------
optimizer_dynamic_sampling integer 2
SQL> create table t_sample(a int);
表已建立。
SQL> insert into t_sample select level from dual connect by level<=2e6;
已建立2000000行。
SQL> commit;
提交完成。
SQL> explain plan for select count(a) from t_sample;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Plan hash value: 3712214945
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 548 (3)| 00:00:07 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | TABLE ACCESS FULL| T_SAMPLE | 2435K| 30M| 548 (3)| 00:00:07 |
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 548 (3)| 00:00:07 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | TABLE ACCESS FULL| T_SAMPLE | 2435K| 30M| 548 (3)| 00:00:07 |
-------------------------------------------------------------------------------
Note
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----
- dynamic sampling used for this statement (level=2)
- dynamic sampling used for this statement (level=2)
已選擇13行。
SQL> alter session set optimizer_dynamic_sampling=3;
會話已更改。
SQL> explain plan for select count(a) from t_sample;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Plan hash value: 3712214945
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 548 (3)| 00:00:07 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | TABLE ACCESS FULL| T_SAMPLE | 2435K| 30M| 548 (3)| 00:00:07 |
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 548 (3)| 00:00:07 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | TABLE ACCESS FULL| T_SAMPLE | 2435K| 30M| 548 (3)| 00:00:07 |
-------------------------------------------------------------------------------
Note
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----
- dynamic sampling used for this statement (level=3)
- dynamic sampling used for this statement (level=3)
已選擇13行。
SQL> alter session set optimizer_dynamic_sampling=0;
會話已更改。
SQL> explain plan for select count(a) from t_sample;
已解釋。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Plan hash value: 3712214945
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | TABLE ACCESS FULL| T_SAMPLE | 82 | 1066 | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | TABLE ACCESS FULL| T_SAMPLE | 82 | 1066 | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------------
已選擇9行。
SQL>
小結:1,如無收集統計資訊,會啟用動態取樣
2,動態取樣由引數optimizer_dynamic_sampling控制
3,如設定其為0,關閉動態取樣
4,關閉動態取樣,oracle自資料字典評估統計資訊,如上述最後執行計劃,t_sample
rows僅為82,其實記錄為幾百萬,
5,動態取樣會減緩sql解析速度,增加sql解析時間,所以要及時收集統計資訊
小結:1,如無收集統計資訊,會啟用動態取樣
2,動態取樣由引數optimizer_dynamic_sampling控制
3,如設定其為0,關閉動態取樣
4,關閉動態取樣,oracle自資料字典評估統計資訊,如上述最後執行計劃,t_sample
rows僅為82,其實記錄為幾百萬,
5,動態取樣會減緩sql解析速度,增加sql解析時間,所以要及時收集統計資訊
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-751534/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle動態取樣_optimizer_dynamic_sampling(二)Oracle
- Oracle 動態取樣Oracle
- Oracle動態取樣分析Oracle
- Oracle 分析及動態取樣Oracle
- Oracle動態取樣學習Oracle
- Oracle 分析及動態取樣(轉帖)Oracle
- Oracle 執行計劃 分析和動態取樣Oracle
- 【原創】ORACLE 資料分析和動態取樣Oracle
- 【sql調優】動態取樣SQL
- sql profile禁用oracle動態取樣dynamic samplingSQLOracle
- 9i,10g 優化器動態取樣級別引數 -- optimizer_dynamic_sampling (統計優化)優化
- CBO與動態統計量取樣
- 如何找出使用動態取樣的SQLSQL
- oracle動態取樣dynamic sampling hint為何不生效一點思考Oracle
- 對於沒有任何統計資訊的表,ORACLE可能會動態取樣。Oracle
- 如何檢視哪些SQL使用了動態取樣?SQL
- 示例說明動態取樣的作用,並演示動態取樣對有內在關係的多列查詢的影響
- oracle隨機取樣Oracle隨機
- 臨時表(GLOBAL TEMPORARY TABLE)及統計資訊收集,動態取樣
- lit動態修改樣式
- 【AWR】測試AWR手動取樣對系統自動取樣的影響
- dbms_stats.lock_table_stats與動態取樣(Dynamic Sampling)
- Oracle 動態SQLOracleSQL
- [Oracle] Oracle收集統計資訊的取樣比例Oracle
- php動態獲取常量PHP
- 動態變更vue樣式Vue
- javascript 動態修改css樣式JavaScriptCSS
- oracle 監聽 靜態 動態Oracle
- Oracle動態遊標Oracle
- ferret 爬取動態網頁網頁
- 動態網站的爬取網站
- Vue 動態繫結CSS樣式VueCSS
- JavaScript動態更改引入樣式表JavaScript
- 微課sql最佳化(6)、統計資訊收集(4)-關於動態取樣SQL
- 逆機率取樣-接受拒絕取樣-MCMC取樣
- oracle procedure plsql 動態sql之動態傳遞表OracleSQL
- oracle listener 靜態和動態註冊Oracle
- oracle動態和靜態監聽listenerOracle