ちょうど不思議なことに、現在シードされている関数FND_GLOBAL.USER_ID
が、現在ログインしているユーザーのUser_IDを返していて、束を更新するカスタムパッケージ(質問の終わりに表dmlとddl)。関数を複数回呼び出してローカル変数に代入したときの結果
1つの手順がFND_GLOBAL.USER_ID
に単一の呼び出しを行い、ローカル変数に代入し、他はFND_GLOBAL.USER_ID
に複数の呼び出しを行う:個別のセッションで
create or replace package call_pkg_var is
procedure call_once (p_trx_no number);
procedure call_multi (p_trx_no number);
end call_pkg_var;
/
create or replace package body call_pkg_var is
procedure call_once (p_trx_no number)
is
l_user_id number := fnd_global.user_id;
begin
update table_a
set user_id = l_user_id
where trx_no = p_trx_no;
update table_b
set user_id = l_user_id
where trx_no = p_trx_no;
update table_c
set user_id = l_user_id
where trx_no = p_trx_no;
end call_once;
procedure call_multi (p_trx_no number)
is
begin
update table_a
set user_id = FND_GLOBAL.USER_ID
where trx_no = p_trx_no;
update table_b
set user_id = FND_GLOBAL.USER_ID
where trx_no = p_trx_no;
update table_c
set user_id = FND_GLOBAL.USER_ID
where trx_no = p_trx_no;
end call_multi;
end call_pkg_var;
/
は、私がcall_pkg_var.call_once
を使用してテーブルを更新するには、以下のスクリプトを実行しました:
set timing on;
begin
for i in 1 .. 10000 loop
call_pkg_var.call_once(i);
end loop;
commit;
end;
とcall_pkg_var.call_multi
を使用して、この1:
set timing on;
begin
for i in 1 .. 10000 loop
call_pkg_var.call_multi(i);
end loop;
commit;
end;
の
結果:
Run# call_pkg_var.call_once
------- -----------------------
1 00:00:02.248
2 00:00:02.100
3 00:00:02.101
4 00:00:02.069
5 00:00:02.136
6 00:00:02.113
------ -------------
Average 00:00:02.128
Run# call_pkg_var.call_multi
------- -----------------------
1 00:00:02.051
2 00:00:02.047
3 00:00:02.054
4 00:00:02.071
5 00:00:02.054
6 00:00:02.051
------ -------------
Average 00:00:02.055
が、これは何とか機能を複数回呼び出すことがちょうどそれを変数に割り当てるよりも優れていると言うことでしょうか? そうでない場合は、どのような方法が最適ですか?私は、現在のユーザーを取得するためSYS_CONTEXTを使用することができブライアンのpoint.Alwaysが希望outputs.Youを取得するために、オラクルの組み込み関数での使用を試みる同意し、私はありません
表のDMLとDDLの
create table table_a
(
user_id number,
trx_no number
);
create table table_b
(
user_id number,
trx_no number
);
create table table_c
(
user_id number,
trx_no number
);
insert into table_a (trx_no, user_id) values (1, null);
insert into table_b (trx_no, user_id) values (1, null);
insert into table_c (trx_no, user_id) values (1, null);
コール10000回ループ内でこれらの手順や平均時間を比較します。この測定を3〜5回繰り返す。次に、この評価の結果を質問に追加してください。 – krokodilko
ループを追加してテストを6回実行しました。複数の呼び出しがまだより速いようです。思考? @krokodilko –
あなたは質問から最初のテストの結果を削除しました。私が覚えているように、1回の呼び出しで約90msの差があったのは約200msと300ms(ms =ミリ秒)でした。 2回目のテスト - 2秒間128ミリ秒2秒55ミリ秒 - 差は10000秒で88ミリ秒です。はい、それは絶対に速く、1回の呼び出しにつき約8,8マイクロ秒(数CPUサイクル)ですが、これは非常に衝撃的な業績です。 – krokodilko