awr_plan_change腳本中平均執行時間不正確淺析?

来源:https://www.cnblogs.com/kerrycode/archive/2023/10/09/17753052.html
-Advertisement-
Play Games

awr_plan_change.sql腳本是Kerry Osborne的一個腳本,這個腳本也是我非常喜歡並且經常使用的一個腳本。腳本如下所示 set lines 155col execs for 999,999,999col avg_etime for 999,999.999col avg_lio  ...


awr_plan_change.sql腳本是Kerry Osborne的一個腳本,這個腳本也是我非常喜歡並且經常使用的一個腳本。腳本如下所示

set lines 155
col execs for 999,999,999
col avg_etime for 999,999.999
col avg_lio for 999,999,999.9
col sql_id for a16
col begin_interval_time for a30
col node for 99999
break on plan_hash_value on startup_time skip 1
select ss.snap_id
     , ss.instance_number node
     , begin_interval_time
     , sql_id
     , plan_hash_value
     , nvl(executions_delta,0) execs
     ,(elapsed_time_delta/decode(nvl(executions_delta,0),0,1,executions_delta))/1000000 avg_etime
     ,(buffer_gets_delta/decode(nvl(buffer_gets_delta,0),0,1,executions_delta)) avg_lio
from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT SS
where sql_id = nvl('&sql_id','799tsyjq9p1r6')
and ss.snap_id = S.snap_id
and ss.instance_number = S.instance_number
and executions_delta > 0
order by 123
/

正常情況下,這個腳本並沒有什麼問題,但是這個腳本在某些場景下,它計算SQL語句的平均執行時間(avg_etime)是有問題的(avg_etime在有些場景是不准確的)。下麵以一個案例來簡單分析一下。如下所示,SQL_ID=799tsyjq9p1r6是數據倉庫中的一個SQL語句,使用awr_plan_change.sql分析這個SQL,發現它的平均執行時間(AVG_ETIME)有非常大的波動,如下所示,我們以2023-10-04為起點,如下所示,你會發現它的平均執行時間多的時候為1559.825秒,短的時侯為25.080秒,這個SQL並沒有使用綁定變數,它的執行計劃從2023-10-04號到2023-10-08號沒有變化過(PLAN_HASH_VALUE沒有變化),那麼這個SQL的平均執行時間為什麼有這麼大的波動呢?

其實,確切來說,就是awr_plan_change.sql中計算的平均執行時間(AVG_ETIME)有誤,首先要說明的是資料庫的快照間隔(SNAP_INTERVAL)是30分鐘,而這個SQL的執行時間超過AWR的快照間隔了。這個SQL的開始執行時間和結束時間,跨越了幾個snap_id,我們可以使用sqlstat.sql分析如下所示:

DBW1:SYS>select
  2  sql_id,
  3  plan_hash_value,
  4  TO_CHAR(BEGIN_INTERVAL_TIME,'yyyy-mm-dd hh24:mi:ss'AS BEGIN_INTERVAL_TIME,
  5  TO_CHAR(END_INTERVAL_TIME,'yyyy-mm-dd hh24:mi:ss'AS END_INTERVAL_TIME,
  6  executions_delta,
  7  ROUND(ELAPSED_TIME_DELTA/(nonzeroexecutions*1000000),1"Elapsed Average",
  8  ROUND(CPU_TIME_DELTA/(nonzeroexecutions*1000000),1"CPU Average",
  9  ROUND(IOWAIT_DELTA/(nonzeroexecutions*1000000),1"IO Average",
 10  ROUND(CLWAIT_DELTA/(nonzeroexecutions*1000000),1"Cluster Average",
 11  ROUND(APWAIT_DELTA/(nonzeroexecutions*1000000),1"Application Average",
 12  ROUND(CCWAIT_DELTA/(nonzeroexecutions*1000000),1"Concurrency Average",
 13  BUFFER_GETS_DELTA/nonzeroexecutions "Average buffer gets",
 14  DISK_READS_DELTA/nonzeroexecutions "Average disk reads",
 15  trunc(PHYSICAL_WRITE_BYTES_DELTA/(1024*1024*nonzeroexecutions)) "Average disk write megabytes",
 16  ROWS_PROCESSED_DELTA/nonzeroexecutions "Average rows processed"
 17  from
 18  (select
 19  ss.snap_id,
 20  ss.sql_id,
 21  ss.plan_hash_value,
 22  sn.BEGIN_INTERVAL_TIME,
 23  sn.END_INTERVAL_TIME,
 24  ss.executions_delta,
 25  case ss.executions_delta when 0 then 1 else ss.executions_delta end nonzeroexecutions,
 26  ELAPSED_TIME_DELTA,
 27  CPU_TIME_DELTA,
 28  IOWAIT_DELTA,
 29  CLWAIT_DELTA,
 30  APWAIT_DELTA,
 31  CCWAIT_DELTA,
 32  BUFFER_GETS_DELTA,
 33  DISK_READS_DELTA,
 34  PHYSICAL_WRITE_BYTES_DELTA,
 35  ROWS_PROCESSED_DELTA
 36  from DBA_HIST_SQLSTAT ss,DBA_HIST_SNAPSHOT sn
 37  where ss.sql_id = '&sql_id'
 38  and ss.snap_id=sn.snap_id
 39  and ss.INSTANCE_NUMBER=sn.INSTANCE_NUMBER)
 40  where ELAPSED_TIME_DELTA > 0
 41  order by snap_id,sql_id;
Enter value for sql_id: 799tsyjq9p1r6

SQL_ID             PLAN_HASH_VALUE BEGIN_INTERVAL_TIME                                       END_INTERVAL_TIME         EXECUTIONS_DELTA Elapsed Average CPU Average IO Average Cluster Average Application Average Concurrency Average Average buffer gets Average disk reads Average disk write megabytes Average rows processed
------------------ --------------- --------------------------------------------------------- ------------------------- ---------------- --------------- ----------- ---------- --------------- ------------------- ------------------- ------------------- ------------------ ---------------------------- ----------------------
799tsyjq9p1r6           1879238228 2023-09-24 14:00:37                                       2023-09-24 14:30:44                      0          1312.3        56.3     1283.1               0                   0                   0             2983520             621742                            0                      0
799tsyjq9p1r6           1879238228 2023-09-24 14:30:44                                       2023-09-24 15:00:50                      1           968.7        33.2        950               0                   0                  .1             2522751             328654                            0                  31635
799tsyjq9p1r6           1879238228 2023-09-25 14:30:16                                       2023-09-25 15:00:23                      0          1581.8        52.1     1556.6               0                   0                   0             2216777             523756                            0                      0
799tsyjq9p1r6           1879238228 2023-09-25 15:00:23                                       2023-09-25 15:30:30                      1          1238.1        49.7     1211.7               0                   0                   0             2457976             547253                            0                  26778
799tsyjq9p1r6           1879238228 2023-09-26 14:00:40                                       2023-09-26 14:30:47                      0             182         6.6      178.9               0                   0                   0              249644              63126                            0                      0
799tsyjq9p1r6           1879238228 2023-09-26 14:30:47                                       2023-09-26 15:00:54                      0          1806.2        61.5     1775.5               0                   0                   0             2761065             665285                            0                      0
799tsyjq9p1r6           1879238228 2023-09-26 15:00:54                                       2023-09-26 15:30:01                      1           421.8        18.2      411.3               0                   0                  .1             1123432             243842                            0                  23641
799tsyjq9p1r6           1879238228 2023-09-27 14:00:09                                       2023-09-27 14:30:16                      0           922.4        33.9      905.8               0                   0                   0             1579540             335758                            0                      0
799tsyjq9p1r6           1879238228 2023-09-27 14:30:16                                       2023-09-27 15:00:23                      1          1753.4          58     1722.9               0                   0                   0             3440756             593153                            0                  28687
799tsyjq9p1r6           1879238228 2023-09-28 14:00:39                                       2023-09-28 14:30:46                      0           948.9        32.6      933.9               0                   0                   0             1237907             301664                            0                      0
799tsyjq9p1r6           1879238228 2023-09-28 14:30:46                                       2023-09-28 15:00:53                      1          1794.8        61.5     1764.1               0                   0                   0             2946573             637203                            0                  23879
799tsyjq9p1r6           1879238228 2023-09-29 14:00:10                                       2023-09-29 14:30:18                      1           337.1        21.6      323.9               0                   0                   0             1693956             273991                            0                   9581
799tsyjq9p1r6           1879238228 2023-09-30 14:00:39                                       2023-09-30 14:30:46                      0          1034.6        39.3     1015.1               0                   0                   0             1833993             405250                            0                      0
799tsyjq9p1r6           1879238228 2023-09-30 14:30:46                                       2023-09-30 15:00:53                      0            1804        57.5     1771.7               0                   0                   0             4533708             541639                            0                      0
799tsyjq9p1r6           1879238228 2023-09-30 15:00:53                                       2023-09-30 15:31:00                      1            72.9         3.7       70.5               0                   0                   0              369115              31273                            0                  38389
799tsyjq9p1r6           1879238228 2023-10-01 14:00:09                                       2023-10-01 14:30:17                      0           118.9         4.3      116.8               0                   0                   0              179510              44841                            0                      0
799tsyjq9p1r6           1879238228 2023-10-01 14:30:17                                       2023-10-01 15:00:24                      0          1806.4        53.9     1780.9               0                   0                   0             2070104             543732                            0                      0
799tsyjq9p1r6           1879238228 2023-10-01 15:00:24                                       2023-10-01 15:30:31                      0          1806.2        56.2       1779               0                   0                  .1             2234512             470020                            0                      0
799tsyjq9p1r6           1879238228 2023-10-01 15:30:31                                       2023-10-01 16:00:38                      1          1027.9        33.4     1010.2               0                   0                   0             1920920             339045                            0                  36342
799tsyjq9p1r6           1879238228 2023-10-02 14:00:40                                       2023-10-02 14:30:47                      0          1447.3        46.4     1426.4               0                   0                   0             1699747             415567                            0                      0
799tsyjq9p1r6           1879238228 2023-10-02 14:30:47                                       2023-10-02 15:00:54                      0            1806        59.1     1775.6               0                   0                  .1             3280821             595508                            0                      0
799tsyjq9p1r6           1879238228 2023-10-02 15:00:54                                       2023-10-02 15:30:01                      1           221.6         9.1        216               0                   0                  .1              742730              96869                            0                  32297
799tsyjq9p1r6           1879238228 2023-10-03 14:00:10                                       2023-10-03 14:30:17                      0           720.1        26.9      706.8               0                   0                   0             1153872             262211                            0                      0
799tsyjq9p1r6           1879238228 2023-10-03 14:30:17                                       2023-10-03 15:00:24                      1          1399.9          47     1372.8               0                   0                   0             3553183             437388                            0                  26545
799tsyjq9p1r6           1879238228 2023-10-04 14:00:38                                       2023-10-04 14:30:45                      0          1146.6        47.3     1121.8               0                   0                   0             2332277             545996                            0                      0
799tsyjq9p1r6           1879238228 2023-10-04 14:30:45                                       2023-10-04 15:00:51                      1          1042.1        36.9     1020.6               0                   0                   0             2892948             368538                            0                  29540
799tsyjq9p1r6           1879238228 2023-10-05 14:00:05                                       2023-10-05 14:30:12                      0           939.4        35.5      921.7               0                   0                   0             1556583             360616                            0                      0
799tsyjq9p1r6           1879238228 2023-10-05 14:30:12                                       2023-10-05 15:00:19                      0          1802.9        59.5     1768.4               0                   0                  .1             4668380             553976                            0                      0
799tsyjq9p1r6           1879238228 2023-10-05 15:00:19                                       2023-10-05 15:30:26                      1            25.1         1.3       24.2               0                   0                   0              103952              11067                            0                  35528
799tsyjq9p1r6           1879238228 2023-10-06 14:00:31                                       2023-10-06 14:30:38                      0          1059.1          44     1036.6               0                   0      &nb
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 變數類型的轉化: 轉換原則 同類型的大的可以裝小的,小類型的裝大的就需要強制轉換。 隱式轉換: 同種類型的轉換: //有符號 long——>int——>short——>sbyte long l = 1; int i = 1; short s = 1; sbyte sb = 1; //隱式轉換 int ...
  • 讀取請求體流的demo public static async Task<string> GetBodyForm(this HttpContext http) { var content = string.Empty; var request = http.Request; try { reques ...
  • 支持.Net Core(2.0及以上)與.Net Framework(4.0及以上) 【目錄】 前言 Post請求 Get請求 與其它工具的比較 1【前言】 http請求調用是開發中經常會用到的功能。 在內,調用自有項目的Web Api等形式介面時會用到;在外,調用一些第三方功能介面時,也會用到,因 ...
  • 1、功能介紹 海量數據操作ORM性能瓶頸在實體轉換上面,並且不能使用常規的Sql去實現 當列越多轉換越慢,SqlSugar將轉換性能做到極致,並且採用資料庫最佳API 操作資料庫達到極限性能,當然你如果不用sqlsugar瞭解一下原理也可以使用其他ORM實現 BulkCopy BulkCopy是一種 ...
  • windows中好用的工具和瀏覽器插件 一、geek卸載軟體 軟體介紹 geek一款非常簡潔的卸載軟體,並且非常強大,強大到可以清理註冊表,用過的都說好。 下載地址: https://geekuninstaller.com 主要優點(官網中更詳細) 個人版免費 體積小,還相容win7和xp系統 能夠 ...
  • 【學習課程】:【【小白入門 通俗易懂】2021韓順平 一周學會Linux】 https://www.bilibili.com/video/BV1Sv411r7vd/?p=14&share_source=copy_web&vd_source=2c07d62293f5003c919b2df9b2e054 ...
  • ChatGPT4.0國內站點: https://www.weijiwangluo.com/talk 要查看nginx進程,可以使用以下命令: ps -ef | grep nginx 這個命令會列出當前系統中所有的進程,並通過管道符號|將它們傳遞給grep命令進行過濾,只顯示包含nginx關鍵字的進程 ...
  • PG
    PostgreSQL 教程 ​ — — — — —— 參考: 菜鳥教程 ORDBMS 術語 在我們開始學習 PostgreSQL 資料庫前,讓我們先瞭解下 ORDBMS 的一些術語: 資料庫: 資料庫是一些關聯表的集合。 數據表: 表是數據的矩陣。在一個資料庫中的表看起來像一個簡單的電子錶格。 列: ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...