主にOracleでFUNCTIONの速度計測をした際の手順のメモです。
サンプル
FUNCTION ADJUST_MONTH_DAY( i_input_date DATE
, i_base_month NUMBER -- mm
, i_base_day NUMBER -- dd
) RETURN DATE
IS
o_year NUMBER;
o_month NUMBER;
o_day NUMBER;
o_last_day NUMBER;
o_last_date DATE;
o_output_date DATE;
BEGIN
IF i_input_date IS NULL THEN
RETURN (NULL);
END IF;
/* 入力年月日を分割 */
o_year := TO_NUMBER(TO_CHAR(i_input_date,'yyyy'));
IF i_base_month > 0 THEN
o_month := i_base_month;
ELSE
o_month := TO_NUMBER(TO_CHAR(i_input_date,'mm'));
END IF ;
IF i_base_day > 0 THEN
o_day := i_base_day;
ELSE
o_day := TO_NUMBER(TO_CHAR(i_input_date,'dd'));
END IF ;
/* 末日調整 */
o_last_date := LAST_DAY(TO_DATE(o_year||'/'||o_month||'/01','yyyy/mm/dd'));
o_last_day := TO_NUMBER(TO_CHAR(o_last_date,'dd'));
IF o_day > o_last_day THEN
o_day := o_last_day;
END IF;
/* 日付型変換 */
o_output_date := TO_DATE(o_year ||'/'|| o_month ||'/'|| o_day,'yyyy/mm/dd');
RETURN (o_output_date);
END;
などというFUNCTIONがあったとき。
SQLPlus
以下コマンド。
spool sql.log
set linesize 200
set tab off
set timing on
set autotrace on
set pages 0
SELECT ADJUST_MONTH_DAY(sysdate, 11, 30) from dual
spool off
出力
21-11-30
経過: 00:00:00.12
実行計画
----------------------------------------------------------
Plan hash value: 1388734953
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------
統計
----------------------------------------------------------
1 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
404 bytes sent via SQL*Net to client
197 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> spool off
Postgre用 PLProfiler
参考
マイグレーション時含めての、「速度計測」をした際の作業メモ。以上です。