Oracle 11g Results Cache
Oracle 11g Results Cache
Oracle 11g Results Cache
Who Am I?
Senior DBA for Confio Software
[email protected]
20+ Years in Oracle, SQL Server 5+ Years in Oracle Consulting - SPG Specialize in Performance Tuning Review Performance of 100s of Databases for Customers and Prospects
Example
SELECT /*+ result_cache */ state, sum(order_total) FROM order_history WHERE order_date BETWEEN 1-JAN-09 AND 1-JAN-10 GROUP BY state 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 | -------------------------------------------------------------------------------------------------Result Cache Information (identified by operation id): -----------------------------------------------------1 - column-count=2; dependencies=(PROD.ORDER_HISTORY); parameters=(nls); name=SELECT /*+ result_cache */ state, sum(order_total) FROM order_history GROUP BY state
SELECT ID, TYPE, CREATION_TIMESTAMP, BLOCK_COUNT, COLUMN_COUNT, PIN_COUNT, ROW_COUNT FROM V$RESULT_CACHE_OBJECTS WHERE CACHE_ID = '7zvt0xan8bw0pgry071f7mt85s'; ID TYPE CREATION_ BLOCK_COUNT COLUMN_COUNT -- ------ ---------- ----------- -----------2 Result 06-JAN-10 1 2 4 PIN_COUNT ROW_COUNT --------- --------0 12
Cached Data is shared across executions Automatically marked stale if underlying data is changed Can Dramatically Increase Performance
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)
SQL> alter system set result_cache_mode=incorrect; alter system set result_cache_mode=incorrect * ERROR at line 1: ORA-00096: invalid value INCORRECT for parameter result_cache_mode, must be from among FORCE, MANUAL, AUTO
Many notes in blogs, etc that say AUTO mode is not supported and probably never will
Query Hint
select /*+ result_cache */ rep_name, sum(order_total) from orders group by rep_name
Session Mode
alter session set result_cache_mode = force
10
Restrictions
Query must retrieve the most current committed state of the data
No Active Transaction Against Objects in Current Session
11
DBMS_RESULT_CACHE
BYPASS FLUSH
Disables result cache database-wide Flushes all objects from result cache Note: flushing shared pool has no affect Nice report that shows usage of result cache ENABLED or NOT ENABLED Invalidate contents of the result cache Invalidates contents that rely on object passed in
MEMORY_REPORT STATUS
INVALIDATE
INVALIDATE_OBJECT
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 --1 2 3 4 5 6 7 8 9 10 11
15
NAME VALUE ------------------------------ -----Block Size (Bytes) 1024 Block Count Maximum 1856 Block Count Current 32 Result Size Maximum (Blocks) 92 Create Count Success 5 Create Count Failure 0 Find Count 3100016 Invalidation Count 0 Delete Count Invalid 0 Delete Count Valid 0 Hash Chain Length 1
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
create or replace function state_sales_totals (p_state in varchar2) return number result_cache as l_order_total number; begin select sum(order_total) into l_order_total from orders where to_number(order_date,'YYYYMM') between 200901 and 200903 and state = p_state; return l_order_total; end;
17
19
Must use an OCI driver that Supports Results Cache Must use 11g client and 11g server Shared by All Sessions in Client Process Subqueries and Query Blocks are not Cached Database will Invalidate Client Result Cache Independent of Server Result Cache
CLIENT_RESULT_CACHE_LAG
3000 ms (Default) Forces next statement execution to check for validations
20
Views
CLIENT_RESULT_CACHE_STATS$
One row for every client using Result Cache Cache Settings and Statistics
21
CLIENT_RESULT_CACHE_STATS$
NAME ------Block Size Block Count Max Block Count Current Hash Bucket Count Create Count Success Create Count Failure Find Count Invalidation Count Delete Count Invalid Delete Count Valid VALUE ----256 256 128 1024 10 0 12 8 0 0 CACHE_ID -------124 124 124 124 124 124 124 124 124 124
Look for high values of Find Count Look for low values
Create Count Failure Delete Count Valid
22
11g R1 vs. R2
R1 Memory Grows to Maximum Size but does not Automatically Free Memory
DBMS_RESULT_CACHE.FLUSH
Latching Issues in R1
R1 Result Cache controlled by one latch R2 controlled by many latches
23
Confio Software
Developer of Wait-Based Performance Tools Igniter Suite Web Based and Agentless
Ignite for Oracle, SQL Server, DB2, Sybase
Helps Identify Queries that may benefit from using Results Cache Based in Colorado, worldwide customers Free trial at www.confio.com
24
40% Improvement
25