[20160919]Result cache问题.txt

简介: [20160919]Result cache问题.txt --看了链接http://blog.dbi-services.com/result-cache-side-effects-on-number-of-calls/,重复测试: SCOTT@book> @ &r...

[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

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

目录
相关文章
|
1月前
|
SQL 数据库
Result Set
【11月更文挑战第02天】
33 1
|
6月前
|
关系型数据库 MySQL Linux
FATAL ERROR: Could not find my_print_defaults
FATAL ERROR: Could not find my_print_defaults
168 0
|
资源调度
error This module isn‘t specified in a package.json file.
error This module isn‘t specified in a package.json file.
|
Oracle 关系型数据库 数据库管理
[odb-users] query results not being cached?
Burton, Craig crburton at tnsi.com Wed Jun 6 13:58:03 EDT 2012   Previous message: [odb-users] query results not being cached? Next message: [odb...
1199 0
|
Oracle 关系型数据库 Linux
[20151207]filter( IS NULL).txt
[20151207]filter( IS NULL).txt --前一阵子别人问的问题,filter (IS NOT NULL)是什么意思? -- http://www.
795 0