博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[20160919]Result cache问题.txt
阅读量:6769 次
发布时间:2019-06-26

本文共 3168 字,大约阅读时间需要 10 分钟。

[20160919]Result cache问题.txt

--看了链接http://blog.dbi-services.com/result-cache-side-effects-on-number-of-calls/,重复测试:

SCOTT@book> @ &r/ver1

PORT_STRING                    VERSION        BANNER

------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SYS@book> grant execute on dbms_lock to scott;

Grant succeeded.

create or replace function F return number is

begin
dbms_lock.sleep(5);
dbms_output.put_line('Hello World');
return 255;
end;
/

SCOTT@book> set serveroutput on

SCOTT@book> set timing on

SCOTT@book> select f from dual;

         F
----------
       255

Hello World

Elapsed: 00:00:05.01

2.如果清除result_cache.

SCOTT@book> exec dbms_result_cache.flush;
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01

SCOTT@book> select /*+ result_cache */ f from dual;

         F
----------
       255

Hello World

Hello World
Elapsed: 00:00:10.01

--使用提示result_cache,显示2次,说明调用2次.时间上也能说明问题,需要10秒完成。

SCOTT@book> select id, type, status, name from v$result_cache_objects;

        ID TYPE                                     STATUS    NAME
---------- ---------------------------------------- --------- --------------------------------------------------
         0 Dependency                               Published SCOTT.F
         1 Result                                   Published select /*+ result_cache */ f from dual
Elapsed: 00:00:00.00

--//再次执行,很快完成。

SCOTT@book> select /*+ result_cache */ f from dual ;
         F
----------
       255
Elapsed: 00:00:00.01

3.Note that if the function is declared as deterministic, it is executed only once.

--//加入deterministic
create or replace function F return number deterministic is
begin
dbms_lock.sleep(5);
dbms_output.put_line('Hello World');
return 255;
end;
/
exec dbms_result_cache.flush;

SCOTT@book> select /*+ result_cache */ f from dual ;

         F
----------
       255

Hello World

Elapsed: 00:00:05.01
--使用提示result_cache,显示1次,说明调用1次.时间上也能说明问题,需要5秒完成。说明参数deterministic作用。

SCOTT@book> select /*+ result_cache */ f from dual ;

         F
----------
       255

Elapsed: 00:00:00.01

--//再次执行很快完成,因为结果已经result cache。
SCOTT@book> select id, type, status, name from v$result_cache_objects;
        ID TYPE                                     STATUS    NAME
---------- ---------------------------------------- --------- --------------------------------------------------
         0 Dependency                               Published SCOTT.F
         1 Result                                   Published select /*+ result_cache */ f from dual

Elapsed: 00:00:00.00

4.如果修改如下:

create or replace function F return number RESULT_CACHE is
begin
dbms_lock.sleep(5);
dbms_output.put_line('Hello World');
return 255;
end;
/

SCOTT@book> exec dbms_result_cache.flush;

PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01

SCOTT@book> select /*+ result_cache */ f from dual;

         F
----------
       255

Hello World

Elapsed: 00:00:05.01

SCOTT@book> select id, type, status, name from v$result_cache_objects;

        ID TYPE                                     STATUS    NAME
---------- ---------------------------------------- --------- --------------------------------------------------
         0 Dependency                               Published SCOTT.F
         2 Result                                   Published "SCOTT"."F"::8."F"#9689ba467a19cd19 #1
         1 Result                                   Published select /*+ result_cache */ f from dual

Elapsed: 00:00:00.01

SCOTT@book> select /*+ result_cache */ f from dual;

         F
----------
       255
Elapsed: 00:00:00.00

--仅仅做一个记录,实际上以前也做过类似测试。

转载地址:http://szgeo.baihongyu.com/

你可能感兴趣的文章
DB2日常运维之总结
查看>>
用hadoop中的libhdfs和fuse-dfs构建快速云存储
查看>>
ospf中创建末节区域
查看>>
Redis实战(6)数据类型四Sets
查看>>
Android Studio第八期 - 自定义布局无网有网状态
查看>>
Centos 6.4用源代码安装LAMP环境
查看>>
读《Go并发编程实战》第4章 流程控制方式
查看>>
Exchange Server2010系列之十五:Exchange磁盘压力测试
查看>>
IT168:数据库安全审计用户需求调查报告
查看>>
Exchange 2007 前端 IIS 内存占用过高
查看>>
利用Cocos2dx-3.0新物理特性模拟弹珠迷宫
查看>>
Lync Server 2010不同规模拓扑图详解
查看>>
QQ群排名优化:“小百度”大蓝海有搞头
查看>>
写在毕业季(四):是做IT?IT?还是IT呢?
查看>>
Gtk-WARNING **: 无法在模块路径中找到主题引擎:“pixmap”
查看>>
验证控件收藏
查看>>
安装配置Varnish3.0手记
查看>>
C#:根据年、月、日获取星期几
查看>>
舌尖上的职场(三)我来买单!
查看>>
Peter's Hobby
查看>>