RESULT_CACHE管理

本文详细介绍了SQL查询缓存的配置与管理,包括如何查看缓存信息、内存报告及清理缓存,并通过示例展示了如何利用结果缓存提高查询效率。重点探讨了表级缓存的使用与相关视图的查询,提供了SQL语句优化的实践指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SQL> select * from v$result_cache_statistics

        ID NAME                                               VALUE

---------- -------------------------------------------------- --------------------------------------------------
         1 Block Size (Bytes)                                 1024
         2 Block Count Maximum                                104864
         3 Block Count Current                                104864
         4 Result Size Maximum (Blocks)                       5243
         5 Create Count Success                               3921627
         6 Create Count Failure                               356
         7 Find Count                                         3049056
         8 Invalidation Count                                 484024
         9 Delete Count Invalid                               485725
        10 Delete Count Valid                                 3348069
        11 Hash Chain Length                                  16-26

11 rows selected.


查看CACHE具体信息,可以通过cache_id查看具体SQL的cache信息

SELECT ID, TYPE, CREATION_TIMESTAMP, BLOCK_COUNT, COLUMN_COUNT,
PIN_COUNT, ROW_COUNT
FROM V$RESULT_CACHE_OBJECTS


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  = 104864K bytes (104864 blocks)
Maximum Result Size = 5243K bytes (5243 blocks)
[Memory]
Total Memory = 107886464 bytes [1.256% of the Shared Pool]
... Fixed Memory = 164776 bytes [0.002% of the Shared Pool]
... Dynamic Memory = 107721688 bytes [1.254% of the Shared Pool]
....... Overhead = 340952 bytes
....... Cache Memory = 104864K bytes (104864 blocks)
........... Unused Memory = 0 blocks
........... Used Memory = 104864 blocks
............... Dependencies = 12247 blocks (1110 count)
............... Results = 92617 blocks
................... SQL     = 92617 blocks (87854 count)

PL/SQL procedure successfully completed.

EXECUTE DBMS_RESULT_CACHE.FLUSH;--清理缓存


相关HINTS:

SELECT /*+ RESULT_CACHE */ prod_id, SUM(amount_sold)
FROM sales
GROUP BY prod_id
ORDER BY prod_id;


SELECT /*+ NO_RESULT_CACHE */ prod_id, SUM(amount_sold)
FROM sales
GROUP BY prod_id
ORDER BY prod_id;


使用表级别result_cache

CREATE TABLE sales (...) RESULT_CACHE (MODE DEFAULT);


RESULT_CACHE相关视图:


V$RESULT_CACHE_STATISTICS Lists various server result cache settings and memory
usage statistics.
V$RESULT_CACHE_MEMORY Lists all the memory blocks in the server result cache and
their corresponding statistics.
V$RESULT_CACHE_OBJECTS Lists all the objects whose results are in the server result
cache along with their attributes.
V$RESULT_CACHE_DEPENDENCY Lists the dependency details between the results in the
server cache and dependencies among these results.
CLIENT_RESULT_CACHE_STATS$ Stores cache settings and memory usage statistics for the
client result caches obtained from the OCI client
processes. This statistics table has entries for each client
process that is using result caching. After the client
processes terminate, the database removes their entries
from this table. The client table lists information similar
to V$RESULT_CACHE_STATISTICS.
See Also: Oracle Database Reference for details about
CLIENT_RESULT_CACHE_STATS$
DBA_TABLES, USER_TABLES,ALL_TABLES

Includes a RESULT_CACHE column that shows the result
cache mode annotation for the table. If the table has not
been annotated, then this column shows DEFAULT. This
column applies to both server and client result caching.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值