DB2執行LOAD操作的同時進行統計資訊的收集
阿新 • • 發佈:2019-02-18
DB2 執行LOAD命令之後,資料會有改變,這時候需要使用RUNSTATS收集統計資訊,那麼有沒有辦法在LOAD的同時收集統計資訊呢?
答案是有的,需要使用到LOAD命令的下面這個選項:
收集表統計資訊概要檔案中指定的統計資訊。即使裝入操作本身的效能下降(特別是在指定 DETAILED INDEXES ALL 時),與在完成裝入操作後呼叫 RUNSTATS 實用程式相比,使用此引數來收集資料分佈和索引統計資訊更有效。為優化效能,應用程式需要儘可能最佳的資料分佈和索引統計資訊。一旦更新統計資訊,應用程式就可以根據最新的統計資訊使用新的表資料存取路徑。可通過使用 BIND
命令重新繫結應用程式包來建立新的表訪問路徑。通過執行帶有 SET PROFILE 選項的 RUNSTATS 命令來建立表統計資訊概要檔案。將資料裝入到大表中時,建議對 stat_heap_sz(統計資訊堆大小)資料庫配置引數指定較大的值。
按照上面的要求,需要先使用RUNSTATS命令建立統計資訊概要,這個操作是一次性的,一旦完成,之後所有的LOAD操作都可以按照這個概要檔案指定的選項來進行統計資訊的收集工作。
此外,對於LOAD的型別有限制:
在裝入過程中是否收集統計資訊。僅當以 REPLACE 方式執行裝入操作時,才支援此選項。根據為表定義的概要檔案收集統計資訊。必須在執行
LOAD 命令前使用 RUNSTATS 命令建立該概要檔案。如果不存在該概要檔案,但您指示裝入操作根據該概要檔案收集統計資訊,裝入操作就會失敗並返回錯誤訊息。
示例:
如果沒有設定統計資訊概要檔案的話,LOAD的時候會遇到一個SQL2315N的告警:$ db2 "RUNSTATS ON TABLE T2 AND DETAILED INDEXES ALL SET PROFILE ONLY" DB20000I The RUNSTATS command completed successfully. $ db2 "load from c:\t2.del of del replace into T2 STATISTICS USE PROFILE" SQL3109N The utility is beginning to load data from file "c:\t2.del". SQL3500W The utility is beginning the "LOAD" phase at time "2016-09-07 13:38:54.597265". SQL3519W Begin Load Consistency Point. Input record count = "0". SQL3520W Load Consistency Point was successful. SQL3110N The utility has completed processing. "2" rows were read from the input file. SQL3519W Begin Load Consistency Point. Input record count = "2". SQL3520W Load Consistency Point was successful. SQL3515W The utility has finished the "LOAD" phase at time "2016-09-07 13:38:54.769188". SQL3500W The utility is beginning the "BUILD" phase at time "2016-09-07 13:38:54.773675". SQL3213I The indexing mode is "REBUILD". SQL3515W The utility has finished the "BUILD" phase at time "2016-09-07 13:38:54.896751". Number of rows read = 2 Number of rows skipped = 0 Number of rows loaded = 2 Number of rows rejected = 0 Number of rows deleted = 0 Number of rows committed = 2
$ db2 "RUNSTATS ON TABLE T2 UNSET PROFILE"
DB20000I The RUNSTATS command completed successfully.
$ db2 "load from c:\t2.del of del replace into T2 STATISTICS USE PROFILE"
SQL3109N The utility is beginning to load data from file "c:\t2.del".
SQL3500W The utility is beginning the "LOAD" phase at time "2016-09-07
13:40:42.692386".
SQL3519W Begin Load Consistency Point. Input record count = "0".
SQL3520W Load Consistency Point was successful.
SQL2315N The RUNSTATS utility was called with the " USE PROFILE" option.
However, a statistics profile for this table does not exist.
SQL3110N The utility has completed processing. "2" rows were read from the
input file.
SQL3519W Begin Load Consistency Point. Input record count = "2".
SQL3520W Load Consistency Point was successful.
SQL3515W The utility has finished the "LOAD" phase at time "2016-09-07
13:40:42.812534".
SQL3500W The utility is beginning the "BUILD" phase at time "2016-09-07
13:40:42.814839".
SQL3213I The indexing mode is "REBUILD".
SQL3515W The utility has finished the "BUILD" phase at time "2016-09-07
13:40:42.928173".
SQL3107W At least one warning message was encountered during LOAD processing.
Number of rows read = 2
Number of rows skipped = 0
Number of rows loaded = 2
Number of rows rejected = 0
Number of rows deleted = 0
Number of rows committed = 2
參考資料: