gpt4 book ai didi

oracle - Oracle 中的性能独立过程与打包过程

转载 作者:行者123 更新时间:2023-12-03 22:16:59 24 4
gpt4 key购买 nike

独立程序和打包程序在性能上有什么区别?哪个是明智的表现,为什么?两者的执行有什么区别吗?

最佳答案

汤姆 says :

Always use a package.
Never use a standalone procedure except for demos, tests and standalone utilities (that call nothing and are called by nothing)

在那里你还可以找到关于他们表现的非常好的讨论。只需在该页面上搜索“性能”即可。
如果仍然有严重的疑问,您可以随时测试自己哪个更快。这样做您一定会学到新东西。

我对你的问题的看法:虽然在某些情况下调用包过程/函数确实比调用独立过程/函数慢,但使用包时可用的附加功能所提供的优势远远超过性能损失。所以,就像 Tom 所说的那样,使用包。


链接:http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:7452431376537


测试代码(2000万调用,runstats_pkg是我根据runstats package by Tom Kyte写的一个包):

CREATE OR REPLACE PACKAGE testperf AS
FUNCTION pow(i INT) RETURN INT;
END;
/

CREATE OR REPLACE PACKAGE BODY testperf AS
FUNCTION pow(i int) RETURN INT AS
BEGIN
RETURN i * i;
END;
END;
/

CREATE OR REPLACE FUNCTION powperf(i INT) RETURN INT AS
BEGIN
RETURN i * i;
END;
/

DECLARE
I INT;
S INT DEFAULT 0;
BEGIN
runstats_pkg.start1;
FOR I IN 1 .. 20000000 LOOP
s := s + (powperf(i) / i);
END LOOP;
runstats_pkg.stop1;

dbms_output.put_line(s);
s := 0;

runstats_pkg.start2;
FOR I IN 1 .. 20000000 LOOP
s := s + (testperf.pow(i) / i);
END LOOP;
runstats_pkg.stop2;

dbms_output.put_line(s);

runstats_pkg.show;
END;

结果(甲骨文 XE):

Run1 latches total versus runs -- difference and pct
Run1 Run2 Diff Pct
2,491 2,439 -52 102.13%

Run1 ran in 2304 hsecs
Run2 ran in 2364 hsecs
run 1 ran in 97.46% of the time

结果(Oracle 11g R1,不同的机器):

Run1 latches total versus runs -- difference and pct
Run1 Run2 Diff Pct
2,990 3,056 66 97.84%

Run1 ran in 2071 hsecs
Run2 ran in 2069 hsecs
run 1 ran in 100.1% of the time

所以,你去吧。真的没有太大区别。想要更复杂且涉及 SQL DML 的数据吗?你得自己测试一下。

关于oracle - Oracle 中的性能独立过程与打包过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1812049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com