Oracle 11g Results Cache: Dean Richards Senior DBA, Confio Software
Oracle 11g Results Cache: Dean Richards Senior DBA, Confio Software
Dean Richards
Senior DBA, Confio Software
1
Who Am I?
2
Example
First Execution
Elapsed: 00:03:42.96
Statistics
----------------------------------------------------------
824825 consistent gets
824791 physical reads
Second Execution
Elapsed: 00:00:00.10
Statistics
----------------------------------------------------------
0 consistent gets
0 physical reads
3
Execution Plan
Execution Plan
----------------------------------------------------------
Plan hash value: 47235625
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 44 | 396 | 6854 (2)| 00:01:23 |
| 1 | RESULT CACHE | 7zvt0xan8bw0pgry071f7mt85s | | | | |
| 2 | HASH GROUP BY | | 44 | 396 | 6854 (2)| 00:01:23 |
| 3 | TABLE ACCESS FULL| T | 1739K| 14M| 6802 (1)| 00:01:22 |
--------------------------------------------------------------------------------------------------
4
Oracle 11g Result Caches
5
Server Result Caches
6
Parameters
RESULT_CACHE_MODE
• MANUAL (default) – requires a query hint or table annotation
• FORCE – every result set is cached. Not recommended
because it can create significant performance and latching
overhead
• AUTO??? – more about this option
RESULT_CACHE_MAX_SIZE
• Amount of memory allocated to server result cache
• 0 (Disabled), 0.25% (memory_target), 0.5% (sga_target)
and ~1% (shared_pool_size)
RESULT_CACHE_MAX_RESULT
• Amount of memory for a single result set
• 5% (Default)
7
AUTO Mode Not Supported
8
Using Result Cache
Database Setting
result_cache_mode = FORCE (not recommended)
Query Hint
select /*+ result_cache */ rep_name, sum(order_total)
from orders
group by rep_name
Table Annotation Mode
alter table order_history result_cache (mode force)
Session Mode
alter session set result_cache_mode = force
9
Queries that Benefit
10
Restrictions
11
DBMS_RESULT_CACHE
BYPASS
• Disables result cache database-wide
FLUSH
• Flushes all objects from result cache
• Note: flushing shared pool has no affect
MEMORY_REPORT
• Nice report that shows usage of result cache
STATUS
• ENABLED or NOT ENABLED
INVALIDATE
• Invalidate contents of the result cache
INVALIDATE_OBJECT
• Invalidates contents that rely on object passed in
12
MEMORY_REPORT
SET SERVEROUTPUT ON
EXECUTE DBMS_RESULT_CACHE.MEMORY_REPORT
Result Cache Memory Report
[Parameters]
Maximum Cache Size = 950272 bytes (928 blocks)
Maximum Result Size = 47104 bytes (46 blocks)
[Memory]
Total Memory = 46340 bytes [0.048% of the Shared Pool]
... Fixed Memory = 10696 bytes [0.011% of the Shared Pool]
... State Object Pool = 2852 bytes [0.003% of the Shared Pool]
... Cache Memory = 32792 bytes (32 blocks) [0.034% of the Shared Pool]
....... Unused Memory = 30 blocks
....... Used Memory = 2 blocks
........... Dependencies = 1 blocks
........... Results = 1 blocks
............... SQL = 1 blocks
13
System Views
V$RESULT_CACHE_STATISTICS
• How well is the cache doing?
• Monitor CREATES vs. FINDS
V$RESULT_CACHE_MEMORY
• Memory components and statistics
V$RESULT_CACHE_OBJECTS
• Objects that are in the cache along with attributes
V$RESULT_CACHE_DEPENDENCY
• Dependencies of the results in cache
14
V$RESULT_CACHE_STATISTICS
ID NAME VALUE
--- ------------------------------ ------
1 Block Size (Bytes) 1024
2 Block Count Maximum 1856
3 Block Count Current 32
4 Result Size Maximum (Blocks) 92
5 Create Count Success 5
6 Create Count Failure 0
7 Find Count 3100016
8 Invalidation Count 0
9 Delete Count Invalid 0
10 Delete Count Valid 0
11 Hash Chain Length 1
15
Remote Result Sets
RESULT_CACHE_REMOTE_EXPIRATION
• Expiration time (minutes) for results that depend
on remote database objects
• 0 (Default, Disabled)
DML on Remote Database does not Invalidate
the local results cache
Must be Careful of Stale Results
16
PL/SQL Function Result Cache
17
Benefits and Restrictions
18
OCI Client Cache
CLIENT_RESULT_CACHE_SIZE
• Maximum size of client result cache
• 0 – 32767 (Disabled)
CLIENT_RESULT_CACHE_LAG
• 3000 ms (Default)
• Forces next statement execution to check for validations
Optional Client Parameter File (SQLNET.ORA)
Overrides Database Parameters
• OCI_RESULT_CACHE_MAX_SIZE
• OCI_RESULT_CACHE_MAX_RSET_SIZE (bytes)
• OCI_RESULT_CACHE_MAX_RSET_ROWS
20
Views
CLIENT_RESULT_CACHE_STATS$
• One row for every client using Result Cache
• Cache Settings and Statistics
DBA_TABLES, ALL_TABLES, USER_TABLES
• Column to show if FORCE has been used
21
CLIENT_RESULT_CACHE_STATS$
22
11g R1 vs. R2
23
Confio Software
24
Ignite for Oracle
40%
Improvement
25