oracle實驗記錄 (sort_area_size與 cpu_time)
基於成本優化書上介紹 說 workarea manual時候
sort_area_size越大 其cpU_time越長 佔用的CPU越多,理由總結為sort機制為2叉樹 ,樹高度為log2(行數),記憶體越大,放的行數越多,高度越高,cpu遍歷起來越費時間(有可能現在最近版本已經用heap機制sort了)
特此驗證下
cpu_time/1000000 = (s)單位
分別實驗 sort_area_size 1M,5M,10M, 30M(optimial sort)
workarea_size_policy string MANUAL
sort_area_size integer 1048576
分別用2個session一個執行,一個查SQL語句的cpu_time
SQL> set autotrace traceonly statistics;
SQL> select sortcode from t1 order by sortcode;
1048576 rows selected.
Elapsed: 00:00:14.17
另一個session查
SQL> select cpu_time,elapsed_time,sql_id from v$sqlarea where sql_text='select s
ortcode from t1 order by sortcode';
CPU_TIME ELAPSED_TIME SQL_ID
---------- ------------ -------------
5351684 6713273 fasuzt0qcxhcx
SQL> alter system flush shared_pool;
System altered.
SQL> alter system flush buffer_cache;
System altered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
SQL> alter session set sort_area_size = 5242880;
SQL> set autotrace traceonly statistics;
SQL> select sortcode from t1 order by sortcode;
1048576 rows selected.
Elapsed: 00:00:12.86
SQL> select cpu_time,elapsed_time,sql_id from v$sqlarea where sql_text='select s
ortcode from t1 order by sortcode';
CPU_TIME ELAPSED_TIME SQL_ID
---------- ------------ -------------
3746109 5152772 fasuzt0qcxhcx
SQL> alter system flush shared_pool;
System altered.
SQL> alter system flush buffer_cache;
System altered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL> alter session set sort_area_size =10485760 ;
Session altered.
Elapsed: 00:00:00.00
SQL> set autotrace traceonly statistics;
SQL> select sortcode from t1 order by sortcode;
Elapsed: 00:00:12.89
SQL> select cpu_time,elapsed_time,sql_id from v$sqlarea where sql_text='select s
ortcode from t1 order by sortcode';
CPU_TIME ELAPSED_TIME SQL_ID
---------- ------------ -------------
7947986 10131213 fasuzt0qcxhcx
SQL> alter system flush shared_pool;
System altered.
SQL> alter system flush buffer_cache;
System altered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL> set autotrace off;
SQL> alter session set sort_area_size = 31457280;
Session altered.
Elapsed: 00:00:00.00
SQL> set autotrace traceonly statistics;
SQL> select sortcode from t1 order by sortcode;
Elapsed: 00:00:12.96
2 sorts (memory)
0 sorts (disk)~~~~~~~~~~~~~~~已經是最優sort了
SQL> select cpu_time,elapsed_time,sql_id from v$sqlarea where sql_text='select s
ortcode from t1 order by sortcode';
CPU_TIME ELAPSED_TIME SQL_ID
---------- ------------ -------------
12538560 15271482 fasuzt0qcxhcx
SQL> alter system flush shared_pool;
System altered.
SQL> alter system flush buffer_cache;
System altered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL> alter session set sort_area_size = 5242880;
Session altered.
Elapsed: 00:00:00.00
SQL> set autotrace traceonly statistics;
SQL> select sortcode from t1 order by sortcode;
1048576 rows selected.
Elapsed: 00:00:11.81
SQL> select cpu_time,elapsed_time,sql_id from v$sqlarea where sql_text='select s
ortcode from t1 order by sortcode';
CPU_TIME ELAPSED_TIME SQL_ID
---------- ------------ -------------
3753378 4312063 fasuzt0qcxhcx~~~~~~~~~~~~~~~~~~~~~~~~~~~~~為 5M時候 cpu time 最小
SQL> alter system flush shared_pool;
System altered.
SQL> alter system flush buffer_cache;
System altered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL> set autotrace off;
SQL> alter session set sort_area_size =10485760 ;
Session altered.
Elapsed: 00:00:00.00
SQL> set autotrace traceonly statistics;
SQL> select sortcode from t1 order by sortcode;
SQL> select cpu_time,elapsed_time,sql_id from v$sqlarea where sql_text='select s
ortcode from t1 order by sortcode';
CPU_TIME ELAPSED_TIME SQL_ID
---------- ------------ -------------
7935026 9117286 fasuzt0qcxhcx
SQL> alter system flush shared_pool;
System altered.
SQL> alter system flush buffer_cache;
System altered.
很奇怪,經過反覆測試~有時候sort_area_size變大cpu_time會變大 但有時候也會變小,總體來說 還是基本隨著sort_area_size變大而變大,尤其在最優sort時明顯
也許測試方法不正確,也許版本有BUG,也許oracle改變了sort機制不用2叉數了~那樣就不存在高度了.結論:在R2之前 肯定是用2叉數,切cpu_time會佔用長時間.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12020513/viewspace-608740/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Oracle】排序與sort_area_sizeOracle排序
- 大資料實驗記錄大資料
- mysql load 相關實驗記錄MySql
- Oracle實驗8--Merge與歸檔Oracle
- STM32F207DAC實驗記錄
- SEO 經驗記錄
- overlay網路隔離實驗失敗記錄
- 《learn to count everything》論文閱讀、實驗記錄
- Oracle實驗(04):floatOracle
- 個人實驗程式碼記錄 | 數字影像處理實驗3·影像直方圖與均衡化處理直方圖
- WebView與APP互動實戰記錄WebViewAPP
- STM32F207串列埠實驗記錄串列埠
- Oracle實驗(01):字元 & 位元組Oracle字元
- Oracle實驗(03):number的使用Oracle
- Python使用ClickHouse的實踐與踩坑記錄Python
- oracle awr快照點不記錄問題Oracle
- 專案重構經驗記錄
- Laravel 使用個人經驗記錄Laravel
- Oracle實驗(02):轉換 & 轉譯Oracle
- Oracle實驗(05):時間型別Oracle型別
- 【Oracle 恢復表空間】 實驗Oracle
- 實驗 20:備忘錄模式模式
- Oracle遊標遍歷%rowtype中的記錄Oracle
- Oracle 41億資料量表建立索引記錄Oracle索引
- 【BUFFER】Oracle buffer cache之 latch 學習記錄Oracle
- 很漂亮的Python驗證碼(記錄)Python
- Laravel unique驗證 排除當前記錄Laravel
- oracle 主外來鍵關係及實驗Oracle
- 使用ogg 從oracle 同步mysql遇到問題記錄OracleMySql
- 11.21實驗 20:備忘錄模式模式
- 使用DBUA升級 Oracle 11.2.0.4到Oracle 19C的問題記錄Oracle
- Git命令實操記錄Git
- 委派模式與策略模式記錄模式
- Oracle實驗6--掌握Oracle資料庫的日誌操作Oracle資料庫
- Oracle之多行記錄變一行記錄,行變列,並排序(wmsys.wm_concat)Oracle排序
- 【記錄】KgCaptcha滑動拼圖驗證碼GCAPT
- Laravel——驗證碼認證學習記錄Laravel
- html5經驗記錄持續更新HTML
- vue學習記錄-01 vue初體驗Vue