oracle 11g 之 result cache
oracle 11g 之 result cache
今天是2013-10-12,打算最近时间研究一下shared pool的相关原理以及awr报告分析。今天学习一下在oracle 11g shared pool中新增的一个cache 那就是result cache。
从上图可以看出在oracle 11g 的shared pool中存有对sql进行存储、存储sql执行计划、sql解析树等信息的library cache可以通过查看v$librarycahe视图了解其分配情况,以及row CACHE(data dictionary cache)可以查看v$rowcache视图了解其分配情况,对于这两部分内容咱不讨论,但是可以看一下如下这个图,大体明白这两个component的作用原理。
现在开始研究一下result cache,对于oracle 11g 分为client result cache以及server result cache,前者在client进行内存的分配,后者对于数据库server进行内存分配,现在看一下server result cache(如下皆是server result cache内容)。说白了,result cache 就是为了缓存结果集的一块区域,主要是缓存sql 查询结果集以及pl/sql function结果集。
对于 result cache存在几个参数,如下:
result_cache_max_result integer
result_cache_max_size big integer
result_cache_mode string MANUAL(AUTO、FORCE)
1)、result_cache_max_result 表示对于单个的缓存结果占整个result cache 大小的百分比。
2)、result_cache_max_size 参数用于设置该result cache 的大小,是一个动态参数,该参数为0 则说明result cache 功能禁用了。
3)、result_cache_mode,表示result cache的模式,其中有manual、force。manual 表示只有使用hints(result_cache)才可以对其结果进行缓存且当从result cache中获取结果集的时候也必须使用hints(result cache)参数;force表示强制对结果集进行缓存 oracle对该参数的设置不建议,如下:
FORCE mode is not recommended because the database and clients will attempt to cache all queries, which may create significant performance and latching overhead. Moreover, because queries that call non-deterministic PL/SQL functions are also cached, enabling the result cache in such a broad-based manner may cause material changes to the results.
如果需要不对操作进行缓存可以使用hints(no_result_cache)进行设置。
如下是练习过程:
一、
设置result cache 大小为20M,模式为manual,每个结果集占用总的cache比例为50%(为了测试方便);
SQL> alter system set result_cache_mode=manual; System altered. SQL> alter system set result_cache_max_result=50; System altered. SQL> show parameter result_cache NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
client_result_cache_lag big integer 3000
client_result_cache_size big integer 0
result_cache_max_result integer 50
result_cache_max_size big integer 20M
result_cache_mode string MANUAL
result_cache_remote_expiration integer 0
SQL>
那么启用result cache 与不启用的效果在那呢?如下测试见证分晓!
eg:
SQL> set autotrace trace
SQL> select count(*) from rhys.amy; Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 -------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------- Statistics
----------------------------------------------------------
61 recursive calls
0 db block gets
1271 consistent gets
1246 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
5 sorts (memory)
0 sorts (disk)
1 rows processed SQL> r
1* select count(*) from rhys.amy Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 -------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------- Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1248 consistent gets
1246 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed SQL> r
1* select count(*) from rhys.amy Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 -------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------- Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1248 consistent gets
1246 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed SQL> SQL>
SQL>
首先看到查看rhys下的amy这张表在稳定下来的时候一致性读为1248,物理读为1246(万源之恶)。
现在使用result cache 功能。
SQL> select /*+result_cache*/ count(*) from rhys.amy; Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 ------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | RESULT CACHE | 6tux55tbcpqfj66980yb24pfbh | | | |
| 2 | SORT AGGREGATE | | 1 | | |
| 3 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------------------------------ Result Cache Information (identified by operation id):
------------------------------------------------------ 1 - column-count=1; dependencies=(RHYS.AMY); attributes=(single-row); name="select /*+result_cache*/ count(*) from rhys.amy" Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1248 consistent gets
1246 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
第一次执行该语句并将其缓存到result cache中,一致性读以及物理 读没有变化。
如下使用hints(result_cache)进行在此查询该结果集。如下:
SQL> select /*+result_cache*/ count(*) from rhys.amy; Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 ------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | RESULT CACHE | 6tux55tbcpqfj66980yb24pfbh | | | |
| 2 | SORT AGGREGATE | | 1 | | |
| 3 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------------------------------ Result Cache Information (identified by operation id):
------------------------------------------------------ 1 - column-count=1; dependencies=(RHYS.AMY); attributes=(single-row); name="select /*+result_cache*/ count(*) from rhys.amy" Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed SQL>
可见物理读和一致性读都没有了,直接获得了结果集。这是好事啊。呵呵。
对于mode为force模式演示如下:
SQL> alter system set result_cache_mode=force; System altered. SQL>
SQL> set autotrace trace
SQL> select count(*) from rhys.amy; Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 ------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | RESULT CACHE | 6tux55tbcpqfj66980yb24pfbh | | | |
| 2 | SORT AGGREGATE | | 1 | | |
| 3 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------------------------------ Result Cache Information (identified by operation id):
------------------------------------------------------ 1 - column-count=1; dependencies=(RHYS.AMY); attributes=(single-row); name="select count(*) from rhys.amy" Statistics
----------------------------------------------------------
63 recursive calls
8 db block gets
1327 consistent gets
1246 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
10 sorts (memory)
0 sorts (disk)
1 rows processed SQL> r
1* select count(*) from rhys.amy Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 ------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | RESULT CACHE | 6tux55tbcpqfj66980yb24pfbh | | | |
| 2 | SORT AGGREGATE | | 1 | | |
| 3 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------------------------------ Result Cache Information (identified by operation id):
------------------------------------------------------ 1 - column-count=1; dependencies=(RHYS.AMY); attributes=(single-row); name="select count(*) from rhys.amy" Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed SQL>
另外在联机手册中并没提及到result_cache_mode 存在auto模式,但是我在不经意输错的是否发现了这个值。
SQL> alter system set result_cache_mode=false;
alter system set result_cache_mode=false
*
ERROR at line 1:
ORA-00096: invalid value FALSE for parameter result_cache_mode, must be from among FORCE, MANUAL, AUTO
查看资料发现auto,是只有使用hints的时候才能起作用,但是当再次查询结果的时候没必要在使用hints了,而是直接把结果取出来。测试如下:
SQL> set autotrace off
SQL> execute dbms_result_cache.flush; PL/SQL procedure successfully completed. SQL> alter system set result_cache_mode=auto; System altered. SQL> set autotrace trace
SQL> select /*+result_cache*/ count(*) from rhys.amy; Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 ------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | RESULT CACHE | 6tux55tbcpqfj66980yb24pfbh | | | |
| 2 | SORT AGGREGATE | | 1 | | |
| 3 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------------------------------ Result Cache Information (identified by operation id):
------------------------------------------------------ 1 - column-count=1; dependencies=(RHYS.AMY); attributes=(single-row); name="select /*+result_cache*/ count(*) from rhys.amy" Statistics
----------------------------------------------------------
49 recursive calls
0 db block gets
1275 consistent gets
1246 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
5 sorts (memory)
0 sorts (disk)
1 rows processed SQL> r
1* select /*+result_cache*/ count(*) from rhys.amy Execution Plan
----------------------------------------------------------
Plan hash value: 2204613761 ------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 348 (1)| 00:00:05 |
| 1 | RESULT CACHE | 6tux55tbcpqfj66980yb24pfbh | | | |
| 2 | SORT AGGREGATE | | 1 | | |
| 3 | TABLE ACCESS FULL| AMY | 87260 | 348 (1)| 00:00:05 |
------------------------------------------------------------------------------------------ Result Cache Information (identified by operation id):
------------------------------------------------------ 1 - column-count=1; dependencies=(RHYS.AMY); attributes=(single-row); name="select /*+result_cache*/ count(*) from rhys.amy" Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
二、
result cache 管理
对于11g中新增了result cache 那么也新增了4个视图以及一个包。
相关视图如下:
- v$result_cache_dependency
- v$result_cache_memory
- v$result_cache_objects
- v$result_cache_statistics
就不在介绍了,可以参考联机手册进行分析以及学习:
http://www.oracle.com/pls/db112/search?word=v$result_cache_
现在看一个dbms_result_cache包:
存在有6个subprograms,
Subprogram Description Sets the bypass mode for the Result Cache
Attempts to remove all the objects from the Result Cache, and depending on the arguments retains or releases the memory and retains or clears the statistics
Invalidates all the result-set objects that dependent upon the specified dependency object
Invalidates the specified result-set object(s)
Produces the memory usage report for the Result Cache
Checks the status of the Result Cache
演示二个:
其他参考:
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_result_cache.htm#CHDJCFJG
SQL> set serveroutput on
SQL> execute dbms_result_cache.memory_report;
R e s u l t C a c h e M e m o r y R e p o r t
[Parameters]
Block Size = 1K bytes
Maximum Cache Size = 20M bytes (20K blocks)
Maximum Result Size = 10M bytes (10K blocks)
[Memory]
Total Memory = 168264 bytes [0.134% of the Shared Pool]
... Fixed Memory = 5352 bytes [0.004% of the Shared Pool]
... Dynamic Memory = 162912 bytes [0.129% of the Shared Pool]
....... Overhead = 130144 bytes
....... Cache Memory = 32K bytes (32 blocks)
........... Unused Memory = 30 blocks
........... Used Memory = 2 blocks
............... Dependencies = 1 blocks (1 count)
............... Results = 1 blocks
................... SQL = 1 blocks (1 count) PL/SQL procedure successfully completed. SQL> execute dbms_result_cache.memory_report(true);
R e s u l t C a c h e M e m o r y R e p o r t
[Parameters]
Block Size = 1K bytes
Maximum Cache Size = 20M bytes (20K blocks)
Maximum Result Size = 10M bytes (10K blocks)
[Memory]
Total Memory = 168264 bytes [0.134% of the Shared Pool]
... Fixed Memory = 5352 bytes [0.004% of the Shared Pool]
....... Memory Mgr = 200 bytes
....... Cache Mgr = 208 bytes
....... Bloom Fltr = 2K bytes
....... State Objs = 2896 bytes
... Dynamic Memory = 162912 bytes [0.129% of the Shared Pool]
....... Overhead = 130144 bytes
........... Hash Table = 64K bytes (4K buckets)
........... Chunk Ptrs = 24K bytes (3K slots)
........... Chunk Maps = 12K bytes
........... Miscellaneous = 130144 bytes
....... Cache Memory = 32K bytes (32 blocks)
........... Unused Memory = 30 blocks
........... Used Memory = 2 blocks
............... Dependencies = 1 blocks (1 count)
............... Results = 1 blocks
................... SQL = 1 blocks (1 count) PL/SQL procedure successfully completed.SQL> execute dbms_result_cache.flush; PL/SQL procedure successfully completed. SQL> execute dbms_result_cache.memory_report(true);
R e s u l t C a c h e M e m o r y R e p o r t
[Parameters]
Block Size = 0 bytes
Maximum Cache Size = 0 bytes (0 blocks)
Maximum Result Size = 0 bytes (0 blocks)
[Memory]
Total Memory = 5352 bytes [0.004% of the Shared Pool]
... Fixed Memory = 5352 bytes [0.004% of the Shared Pool]
....... Memory Mgr = 200 bytes
....... Cache Mgr = 208 bytes
....... Bloom Fltr = 2K bytes
....... State Objs = 2896 bytes
... Dynamic Memory = 0 bytes [0.000% of the Shared Pool] PL/SQL procedure successfully completed. SQL>
oracle 11g 之 result cache的更多相关文章
- [20190214]11g Query Result Cache RC Latches补充.txt
[20190214]11g Query Result Cache RC Latches补充.txt --//上午测试链接:http://blog.itpub.net/267265/viewspace- ...
- [20190214]11g Query Result Cache RC Latches.txt
[20190214]11g Query Result Cache RC Latches.txt --//昨天我重复链接http://www.pythian.com/blog/oracle-11g-qu ...
- Oracle 11g新特性
文章转自网络 Oracle 11g于2007年7月11日美国东部时间11时(北京时间11日22时)正式发布,11g是甲骨文公司30年来发布的最重要的数据库版本,根据用户的需求实现了信息生命周期管理(I ...
- 11G新特性 -- Result Cache
共享池存放sql语句的解析和编译版本,以便数据库能快速执行频繁执行的sql语句和plsql. 在11g中,数据库使用result cache来存放sql和plsql的执行结果. result cach ...
- Oracle 11g OCM 考试大纲
考试大纲共分9部分. 一.Server Configuration 服务器配置 1 Create the database 创建数据库 2 Determine and set sizing p ...
- Oracle 11g Articles
发现一个比较有意思的网站,http://www.oracle-base.com/articles/11g/articles-11g.php Oracle 11g Articles Oracle Dat ...
- Oracle 11g后台进程一览表
Background Processes Table F-1 describes Oracle Database background processes. In this context, a ba ...
- orace result cache解析
(1) orace 11.2.0.4 在RAC数据库Dataguard切换时,出现少量数据丢失: 解决方案:关闭result cache 功能 或升级数据库版本并安装补丁: ...
- RHEL6.4 + Oracle 11g DG测试环境快速搭建参考
环境现状: 两台虚拟主机A和B: 1. A机器已安装ASM存储的Oracle 11g 实例 参考:http://www.cnblogs.com/jyzhao/p/4332410.html 2 ...
随机推荐
- Topcoder SRM 630 (500 floyed 暴力 _builtin_popcount())
题意:给n个点,保证图联通,给点相连的距离,求一个最多的点,这些点之间的距离都是相同的. 分析: 下面的代码是我们房间第一的大神的,写的很简洁,我的思路和他的一样,但是我不知道错哪了. 思路是暴力枚举 ...
- Android开发性能优化大总结
1. 采用硬件加速,在androidmanifest.xml中application添加android:hardwareAccelerated="true".不过这个需要在and ...
- bzoj4046
分组赛的题……madan原题,考试想不出来真是SB得不行 首先,从大往小加边,每次加边如果成环必然弹出环上最大边 考虑询问[x,y],如果边权在[x,y]的边弹出了小于等于y的边j,说明j不在最小生成 ...
- Spring 使用注解方式进行事务管理
转载:http://www.cnblogs.com/younggun/archive/2013/07/16/3193800.html 使用步骤: 步骤一.在spring配置文件中引入<tx:&g ...
- PHPnow 升级后 PHP不支持GD、MySQL
来自http://tunps.com/php-unsupport-gd-and-mysql-after-upgrade-phpnow 最近磁盘格式化误操作后,最近两天都在忙于数据恢复,现在才恢复正常. ...
- css动画集合地址
CSS3 UI Lib库是由腾讯AlloyTeam前端开发团队建立,主要收集国内外友好体验和创意的界面组件Demo. 它除了使用CSS3技术外,还使用了HTML5,JS,JX,jQuery等技术,来达 ...
- HDU 4638 Group ★(树状数组)
题意 询问一段区间里的数能组成多少段连续的数. 思路 先考虑从左往右一个数一个数添加,考虑当前添加了i - 1个数的答案是x,那么可以看出添加完i个数后的答案是根据a[i]-1和a[i]+1是否已经添 ...
- 数学语言和程序语言的对比:面向过程与面向集合&命题
共同之处:都使用字符串或数值来引用一个客观实体.当然数字和字符串也可以作为实体对象,这取决于人的解释. 不同之处:数学语句每一行都给出了一个结论, 程序语句的每一行都定义了一个过程.注意这里所指的程序 ...
- RMAN 备份详解
一.数据库备份与RMAN备份的概念 1.数据库完全备份:按归档模式分为归档和非归档 归档模式 打开状态,属于非一致性备份 关闭状态,可以分为一致性和非一致性 非归档模式 打开状态,非一致 ...
- IIS应用程序池回收图文详解
转:http://blog.sina.com.cn/s/blog_8677fcaa010138uf.html 什么是应用程序池呢?这是微软的一个全新概念:应用程序池是将一个或多个应用程序链接到一个或多 ...