设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 百科 > 正文

oracle – Pragma inline没有显示出明显的改善?

发布时间:2021-01-21 14:17 所属栏目:128 来源:网络整理
导读:我已经了解了PRAGMA INLINE 11g功能,但我无法区分它是如何实际优化我的代码的. 我写了一段代码. create or replace package test12is procedure getdata (p_job IN emp.job%TYPE,p_total OUT number);end test12;/create or replace package body test12is P

我已经了解了PRAGMA INLINE 11g功能,但我无法区分它是如何实际优化我的代码的.

我写了一段代码.

create or replace package test12
is 

procedure getdata (p_job    IN emp.job%TYPE,p_total OUT number);

end test12;
/

create or replace package body  test12
is 

PROCEDURE total(p_empno IN EMP.EMPNO%TYPE,p_total OUT integer)

IS

BEGIN

 select sal into p_total from emp where empno=p_empno;

END total;

procedure getdata (p_job    IN emp.job%TYPE,p_total OUT number)
IS 

type cur is ref cursor;
v_cur cur;
v_emp emp.empno%TYPE;
v_total integer:=0;
BEGIN

for i in 1..100000 
loop
 open v_cur for select empno from emp where job=p_job;
  loop
  fetch v_cur into v_emp;
  exit when v_cur%notfound;
  --PRAGMA INLINE(total,'YES');
  total(v_emp,v_total);
  p_total:=p_total+v_total;
  end loop;
 close v_cur;
 end loop;
END getdata;                 

end test12;
/


declare
v_total integer;
v_start integer;
v_end integer;
begin
v_start:=DBMS_UTILITY.GET_TIME;
test12.getdata('CLERK',v_total);
v_end :=DBMS_UTILITY.GET_TIME;
v_total:=v_end-v_start;
dbms_output.put_line('time is '||v_total);
end;
/

现在,如果我在没有内联编译的情况下运行它会给我以下时间

First Run : time is 3573
Second Run: time is 3571
Third Run : time is 3554

现在,如果我使用pragma inline运行它会给我以下时间

First Run : time is 3471
Second Run: time is 3489
Third Run : time is 3482

但在这里我没有看到两者之间有任何显着差异.可能是什么原因?

解决方法

调用程序所花费的时间几乎为0.这里优化的很少.我很惊讶你看到了任何进步. 99.9%的执行时间可能花在SQL上,而不是PL / SQL上.

--Procedure that does almost nothing
create or replace procedure total(p_empno IN number,p_total OUT integer) is
begin
    p_total := p_empno + 1;
end;
/

--Disable optimiziations
alter session set PLSQL_OPTIMIZE_LEVEL = 0;

--Only time the procedure calls
declare
    v_test_out number;
    v_start number;
    v_end number;
begin
    v_start:=DBMS_UTILITY.GET_TIME;

    for i in 1 .. 100000 loop
        total(i,v_test_out);
    end loop;

    v_end :=DBMS_UTILITY.GET_TIME;
    dbms_output.put_line('time is '||to_char(v_end-v_start));
end;
/

time is 5

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读