Oracle 11gR2 Result CacheOracle 11gR2 Result … 11gR2 Result CacheOracle 11gR2 Result Cache Feature...

Post on 04-Apr-2018

268 views 1 download

Transcript of Oracle 11gR2 Result CacheOracle 11gR2 Result … 11gR2 Result CacheOracle 11gR2 Result Cache Feature...

Oracle 11gR2 Result CacheOracle 11gR2 Result CacheOracle 11gR2 Result Cache Oracle 11gR2 Result Cache Feature in RACFeature in RAC

Sangam11Sangam11(Bangalore India)(Bangalore India)

Murali Vallathmurali.vallath@summersky.biz

About me…Independent Oracle Consultant - Summersky Enterprisesp y pe-mail: murali.vallath@summersky.biz

Oracle Instance Memory Structure

Shared PoolDatabase

Private SQL Area

Data Library

Database Buffer Cache

SQL Area

Dictionary Cache

Cache

Redo Log Buffer

Cursors

Java Pool Large Pool Miscellaneous

SQL AreaStreams

P lg Pool

Oracle Real Application Cluster | Murali Vallath | Slide: 3

Database Buffer CacheBuffer Header BuffersBuffers

MR

U

Buf

fer

M

Insertion Point

Hot

er

LRU

Col

d B

uffe

Dirty Buffers

db Block Size

C

DataFiles

Oracle Real Application Cluster | Murali Vallath | Slide: 4

Oracle Instance Memory StructureSGASGA

Shared PoolDatabase Buffer

PGA

Cursor

ry C

ache

y C

ache

Database Buffer Cache

SQL

r State

Cac

he

Priv

ate

SQL

Are

a

PoolSor

a D

ictio

nar

Libr

aryL W

orkA

reaUs

Res

ult

Redo Log BufferSh

ared

SQ

L A

rea

Res

erve

d

rt Area

Dat

asser Session D

Latches Enqueues Others

Checkpoint Queue LRU List

Oracle Real Application Cluster | Murali Vallath | Slide: 5

Java Pool Large Pool Fixed SGA

Data

Streams Pool

SGAPGA3

Result Cache OverviewSGA

Shared Pool

PGA

Private SQL Area

2

Data Library

SQL Area

Result 1

Database Buffer Cache

Dictionary Cache

yCache

Redo LogBuffer

Cursors Cache

Buffer

Mi llSQL Area

Streams

Oracle Real Application Cluster | Murali Vallath | Slide: 6

Java Pool Large Pool MiscellaneousStreams Pool

Database Storage

Result Cache Overview

Explain Plan on a SQL Query shows a new ID called as CACHE_ID

--------------------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |--------------------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 150 | 4950 | | 126K (1)| 00:25:17 || 1 | RESULT CACHE | 8fbjhchhd9zwh7uhn4mv7dhvga | | | | | || 2 | HASH GROUP BY | | 150 | 4950 | | 126K (1)| 00:25:17 || 2 | HASH GROUP BY | | 150 | 4950 | | 126K (1)| 00:25:17 ||* 3 | HASH JOIN | | 20M| 649M| 45M| 125K (1)| 00:25:09 || 4 | INDEX FAST FULL SCAN| ORDERS_I2 | 2063K| 21M| | 2743 (1)| 00:00:33 || 5 | INDEX FAST FULL SCAN| IORDL | 20M| 432M| | 87415 (1)| 00:17:29 |--------------------------------------------------------------------------------------------------------------

Result Cache Parameters

• client_result_cache_lag• client result cache size• client_result_cache_size• result_cache_max_result

lt h i• result_cache_max_size• result_cache_mode

l h i i• result_cache_remote_expiration

Enable Result Cache

• Parameter– result cache moderesult_cache_mode

• MANUAL (default)• AUTO

• Hint– /*+ RESULT CACHE *// RESULT_CACHE /

Control Result Cache

• Parameters– result cache max result_ _ _– result_cache_max_size

• DDL– DBMS_RESULT_CACHE.FLUSH;

Data Dictionary Views

• V$RESULT_CACHE_OBJECTS

• V$RESULT_CACHE_STATISTICS

• V$RESULT_CACHE_MEMORY

• V$RESULT CACHE DEPENDENCYV$RESULT_CACHE_DEPENDENCY

Data Dictionary Views

SQL> SELECT id, TYPE, creation_timestamp, block_count, column_count, pin_count, row_count

FROM v$result_cache_objects WHERE cache_id = '8fbjhchhd9zwh7uhn4mv7dhvga';

ID TYPE CREATION_ BLOCK_COUNT COLUMN_COUNT PIN_COUNT ROW_COUNT-- ---------- --------- ----------- ------------ ---------- ----------2 Result 19-JAN-10 1 3 0 3002 Result 19 JAN 10 1 3 0 300

Data Dictionary Views

• V$RESULT CACHE STATISTICSV$RESULT_CACHE_STATISTICS

(Displays settings and statistics)ID St ti ti N b– ID Statistics Number

– NAME Name of StatisticV l f h i i– VALUE Value of the statistics

Data Dictionary Views

• V$RESULT_CACHE_MEMORY(displays all memory blocks and their status)( p y y )

– ID– CHUNK– OFFSET– FREE– OBJECT_ID– POSITION

Data Dictionary Views

• V$RESULT_CACHE_DEPENDENCY

(Displays dependency relationship between(Displays dependency relationship between cached results)– RESULT IDRESULT_ID– DEPEND_ID

OBJECT NO– OBJECT_NO

What is RAC?• Many instances of Oracle running on many nodes• Many instances of Oracle running on many nodes• Many instances sharing a single physical database• All instances having common data and control filesAll instances having common data and control files• Each instance has individual log files and undo segments• All instances can simultaneously execute transactions against the

single physical database• Cache synchronization using cluster interconnect

E h d i VIP d f i i• Each node contains a VIP used for user sessions connecting to database

• Cluster maintains a single SCAN for dynamically connecting to theCluster maintains a single SCAN for dynamically connecting to the least loaded server

Oracle Real Application Cluster | Murali Vallath | Slide: 16

Public Network

ArchitectureDNS

SCAN

ORADB2ORADB1

Cluster Interconnect

ORADB4ORADB3VIPVIPVIPVIP VIPVIPVIPVIP

SCAN

SSKY1SSKY1 SSKY2SSKY2 SSKY4SSKY4SSKY3SSKY3

IPC

Comm. Layer

IPC

Comm. Layer

IPC

Comm. Layer

IPC

Comm. Layer

Listeners | Monitors-----------------------Clusterware

SAN switch

Operating System

Listeners | Monitors-----------------------Clusterware

Operating System

Listeners | Monitors-----------------------Clusterware

Operating System

Listeners | Monitors-----------------------Clusterware

Operating System

Shared Storage

SSKYDBSSKYDB

Data Access Patterns

• Locally accessedLocally accessed

P ll l E i• Parallel Execution

• Result Cache

Example Query

SELECT OL_W_ID, OL_D_ID, OL_NUMBER, sum(OL_AMOUNT),sum(OL_QUANTITY) FROMORDER LINE OL, ORDERS ORD WHEREORDER_LINE OL, ORDERS ORD WHERE

OL.OL_O_ID = ORD.O_ID AND OL.OL_W_ID = ORD.O_W_ID AND OL.OL_D_ID = ORD.O_D_ID

GROUP BY OL NUMBER OL W ID OL D IDGROUP BY OL_NUMBER, OL_W_ID,OL_D_ID

Local Access 10g RACI t 1

Logical I/O remains same

call count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------Parse 1 0.00 0.01 0 0 0 0

Instance 1

Execute 1 0.00 0.00 0 0 0 0Fetch 21 248.08 288.49 214682 42907485 0 300------- ------ -------- ---------- ---------- ---------- ---------- ----------total 23 248.09 288.51 214682 42907485 0 300

call count cpu elapsed disk query current rows

Instance 2

------- ------ -------- ---------- ---------- ---------- ---------- ----------Parse 1 0.00 0.01 0 0 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 21 246.53 271.06 3 42907483 0 300------- ------ -------- ---------- ---------- ---------- ---------- ----------total 23 246.54 271.07 3 42907483 0 300

Physical I/O

Local Accessed 10g RAC

• Logical I/O remains the sameI t 2 h d th f ll i t k l t d it t

• No physical I/O on the second instanceInstance 2 had the following network related wait events..

gc cr multi block request 38621

• Interconnect traffic.. Data transferred over SQL*Net message from client 21gc remaster 9gcs drm freeze in enter server mode 8

the interconnect.ggc cr block 2-way 2 gc current block 2-way 192925 gc current block 3 way 3124gc current block 3-way 3124

Locally AccessedI t 1call count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------Parse 1 0.01 0.01 0 0 0 0

Instance 1

Execute 1 0.00 0.00 0 0 0 0Fetch 21 31.74 74.34 345361 345447 0 300------- ------ -------- ---------- ---------- ---------- ---------- ----------total 23 31.76 74.36 345361 345447 0 300

call count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------

Instance 2

Parse 1 0.01 0.01 0 0 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 21 31.74 74.34 345361 345447 0 300------- ------ -------- ---------- ---------- ---------- ---------- ----------

l 23 31 76 74 36 345361 345447 0 300total 23 31.76 74.36 345361 345447 0 300

Bypass Readers Algorithm

In Oracle 11g release 2 the new ‘bypass readers’ algorithmIn Oracle 11g release 2 the new bypass readers algorithm used in the cache fusion technology will bypass data transfer when large number of rows are being read and will instead

l l I/O b f h i iuse local I/O subsystem from the requesting instance to retrieve data.

Parallel Execution

call count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------Parse 11 0.01 0.02 0 0 0 0Execute 11 19.17 86.67 181238 190696 0 0Fetch 21 0.03 8.34 0 0 0 300------- ------ -------- ---------- ---------- ---------- ---------- ----------total 43 19.23 95.04 181238 190696 0 300

•New algorithm for parallel operations in 11g•Data collected by slaves are retained on respective instances•Oracle uses adaptive parallelismOracle uses adaptive parallelism

3

Result Cache in RAC

SGAShared Pool

e

3

2SGA

Shared Pool

e Database

ctio

nary

Cac

he

rary

Cac

he

Redo Loglt C

ache

Database Buffer Cache

ctio

nary

Cac

he

rary

Cac

he

Redo Loglt C

ache

Database Buffer Cache

Dat

a D

ic

Libr Redo Log

Buffer

S

Res

u

1 Dat

a D

ic

Libr Redo Log

Buffer

S

Res

u

Java Pool Large Pool MiscellaneousStreams Pool

Java Pool Large Pool MiscellaneousStreams Pool

Database Storage4

Result Cache Buffer allocationSQL>SET SERVEROUTPUT ON;SQL>execute DBMS RESULT CACHE MEMORY REPORT(TRUE);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 = 251680K bytes (251680 blocks)Maximum Result Size = 12584K bytes (12584 blocks) [Memory] Total Memory = 12784 bytes [0 000% of the Shared Pool]Total Memory = 12784 bytes [0.000% of the Shared Pool] ... Fixed Memory = 12784 bytes [0.000% of the Shared Pool] ....... Memory Mgr = 200 bytes ....... Bloom Fltr = 2K bytes ....... = 2088 bytes ....... Cache Mgr = 5552 bytes ....... State Objs = 2896 bytes....... State Objs 2896 bytes ... Dynamic Memory = 0 bytes [0.000% of the Shared Pool]

Result Cache in Shared pool

SQL> SELECT * FROM gv$sgastat WHERE POOL='shared pool' AND NAME LIKE 'Result%' AND INST_ID =1;

INST_ID POOL NAME BYTES ------- ------------ ---------------------------------- ----------

1 shared pool Result Cache: State Objs 2896 1 shared pool Result Cache: Memory Mgr 2001 shared pool Result Cache: Memory Mgr 200 1 shared pool Result Cache: 2088 1 shared pool Result Cache: Cache Mgr 5552 1 shared pool Result Cache: Bloom Fltr 2048

Initial Allocation

Query Using Hint

SELECT /*+ RESULT_CACHE */ OL_W_ID, OL_D_ID, OL_NUMBER, sum(OL_AMOUNT),sum(OL_QUANTITY) FROMFROMORDER_LINE OL, ORDERS ORD WHERE OL.OL_O_ID =

ORD.O_ID AND OL.OL_W_ID = ORD O W ID AND OL OL D ID ORD O D IDORD.O_W_ID AND OL.OL_D_ID = ORD.O_D_ID

GROUP BY OL_NUMBER, OL_W_ID, OL_D_ID

ll l d di kcall count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------Parse 1 0.01 0.02 0 0 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 21 33.85 97.00 346671 346755 0 300------- ------ -------- ---------- ---------- ---------- ---------- ----------total 23 33.86 97.03 346671 346755 0 300

Query Plan with Result Cache

Rows Row Source Operation------- ---------------------------------------------------

300 RESULT CACHE 8fbjhchhd9zwh7uhn4mv7dhvga (cr=346755 pr=346671 pw=0 time=1046 us)pr=346671 pw=0 time=1046 us)

300 HASH GROUP BY (cr=346755 pr=346671 pw=0 time=299 us cost=126413 size=4950 card=150)21541174 HASH JOIN (cr=346755 pr=346671 pw=0 time=84263640 us cost=125703 size=680920944 card=20633968)cost=125703 size=680920944 card=20633968)2153881 INDEX FAST FULL SCAN ORDERS_I2 (cr=11664 pr=11635 pw=0 time=566756 us cost=2743 size=22694870 card=2063170)(object id 86234)21541174 INDEX FAST FULL SCAN IORDL (cr=335091 pr=335036 pw=021541174 INDEX FAST FULL SCAN IORDL (cr=335091 pr=335036 pw=0 time=62691616 us cost=87415 size=453947296 card=20633968)(object id 86202)

SQL>SET SERVEROUTPUT ON;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 bytesBlock Size 1K bytes Maximum Cache Size = 251680K bytes (251680 blocks) Maximum Result Size = 12584K bytes (12584 blocks) [Memory] Total Memory = 207000 bytes [0.004% of the Shared Pool]

Fi d M 12784 b t [0 000% f th Sh d P l]... Fixed Memory = 12784 bytes [0.000% of the Shared Pool] ....... Memory Mgr = 200 bytes ....... Bloom Fltr = 2K bytes ....... = 2088 bytes ....... Cache Mgr = 5552 bytes ....... State Objs = 2896 bytes ... Dynamic Memory = 194216 bytes [0.004% of the Shared Pool]....... Overhead = 161448 bytes ........... Hash Table = 64K bytes (4K buckets)

Chunk Ptrs = 62920 bytes (7865 slots)........... Chunk Ptrs = 62920 bytes (7865 slots) ........... Chunk Maps = 31460 bytes ........... Miscellaneous = 1532 bytes ....... Cache Memory = 32K bytes (32 blocks)........... Unused Memory = 23 blocks ........... Used Memory = 9 blocks............... Dependencies = 2 blocks (2 count) ............... Results = 7 blocks ................... SQL = 7 blocks (1 count)

Second Instancecall count cpu elapsed disk query current rowscall count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------Parse 1 0.01 0.02 0 0 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 21 0.00 0.00 0 0 0 300------- ------ -------- ---------- ---------- ---------- ---------- ----------total 23 0.02 0.03 0 0 0 300

Misses in library cache during parse: 1O ti i d ALL ROWSOptimizer mode: ALL_ROWSParsing user id: 89 Rows Row Source Operation------- ---------------------------------------------------

300 RESULT CACHE 8fbjhchhd9zwh7uhn4mv7dhvga (cr=5 pr=0 pw=0 time=299 us)0 HASH GROUP BY (cr=0 pr=0 pw=0 time=0 us cost=126413 size=4950

card=150)0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us cost=125703 size=680920944

card=20633968)0 INDEX FAST FULL SCAN ORDERS I2 (cr=0 pr=0 pw=0 time=0 us cost=27430 INDEX FAST FULL SCAN ORDERS_I2 (cr=0 pr=0 pw=0 time=0 us cost=2743

size=22694870 card=2063170)(object id 86234)0 INDEX FAST FULL SCAN IORDL (cr=0 pr=0 pw=0 time=0 us cost=87415

size=453947296 card=20633968)(object id 86202)

GV$RESULT_CACHE_OBEJCTS

SQL> SELECT INST_ID INT, ID, TYPE, STATUS, NAME, OBJECT_NO OBJNO,CACHE_ID,INVALIDATIONS INVALS FROM GV$RESULT_CACHE_OBJECTS;

INT ID TYPE STATUS NAME OBJNO CACHE_ID INVALS--- -- ---------- --------- ---------------------------------- ------ --------------------------- ------3 1 Dependency Published TPCC.ORDERS 86209 TPCC.ORDERS 03 0 Dependency Published TPCC.ORDER_LINE 86201 TPCC.ORDER_LINE 03 2 Result Published SELECT /*+ RESULT CACHE */ OL W ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 03 2 Result Published SELECT / + RESULT_CACHE / OL_W_ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 0

,OL_D_ID,OL_NUMBER,sum(OL_AMOUNT),sum(OL_QUANTITY) FROM ORDER_LINE OL, ORDERS ORD WHERE OL.OL_

1 1 Dependency Published TPCC.ORDERS 86209 TPCC.ORDERS 01 0 Dependency Published TPCC.ORDER_LINE 86201 TPCC.ORDER_LINE 01 2 Result Published SELECT /*+ RESULT_CACHE */ OL_W_ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 0_ _ _

,OL_D_ID,OL_NUMBER,sum(OL_AMOUNT),sum(OL_QUANTITY) FROM ORDER_LINE OL, ORDERS ORD WHERE OL.OL_

6 rows selected.

Identical CACHE_ID

Result Cache Invalidation

INT ID TYPE STATUS NAME OBJNO CACHE_ID INVALS--- -- ---------- --------- ---------------------------------- ------ -------------------------- ------1 1 Dependency Published TPCC.ORDERS 86209 TPCC.ORDERS 01 0 Dependency Published TPCC.ORDER_LINE 86201 TPCC.ORDER_LINE 11 2 Result Invalid SELECT /*+ RESULT_CACHE */ OL_W_ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 0

OL D ID OL NUMBER sum(OL AMOUNT),OL_D_ID,OL_NUMBER,sum(OL_AMOUNT),sum(OL_QUANTITY) FROM ORDER_LINE OL, ORDERS ORD WHERE OL.OL_

3 1 Dependency Published TPCC.ORDERS 86209 TPCC.ORDERS 03 0 Dependency Published TPCC.ORDER_LINE 86201 TPCC.ORDER_LINE 13 2 Result Invalid SELECT /*+ RESULT_CACHE */ OL_W_ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 0

,OL D ID,OL NUMBER,sum(OL AMOUNT),_ _ _ _sum(OL_QUANTITY) FROM ORDER_LINE OL, ORDERS ORD WHERE OL.OL_

New Execution

INT ID TYPE STATUS NAME OBJNO CACHE_ID INVALS--- -- ---------- --------- ---------------------------------- ------ -------------------------- ------1 1 Dependency Published TPCC.ORDERS 86209 TPCC.ORDERS 01 0 Dependency Published TPCC.ORDER_LINE 86201 TPCC.ORDER_LINE 11 9 Result Published SELECT /*+ RESULT_CACHE */ OL_W_ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 0

,OL_D_ID,OL_NUMBER,sum(OL_AMOUNT),sum(OL_QUANTITY) FROM ORDER_LINE OL, ORDERS ORD WHERE OL.OL_

1 2 Result Invalid SELECT /*+ RESULT CACHE */ OL W ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 01 2 Result Invalid SELECT /*+ RESULT_CACHE */ OL_W_ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 0,OL_D_ID,OL_NUMBER,sum(OL_AMOUNT),sum(OL_QUANTITY) FROM ORDER_LINE OL, ORDERS ORD WHERE OL.OL_

3 1 Dependency Published TPCC.ORDERS 86209 TPCC.ORDERS 03 0 Dependency Published TPCC.ORDER_LINE 86201 TPCC.ORDER_LINE 13 2 Result Invalid SELECT /*+ RESULT CACHE */ OL W ID 0 8fbjhchhd9zwh7uhn4mv7dhvga 0_ _ _ j g

,OL_D_ID,OL_NUMBER,sum(OL_AMOUNT),sum(OL_QUANTITY) FROM ORDER_LINE OL, ORDERS ORD WHERE OL.OL_

Limitations

• Loss of result from cache during instance failure

• Not all operations supported– CURRENT DATE CURRENT TIMESTAMPCURRENT_DATE, CURRENT_TIMESTAMP,

etc• Tables in SYS and SYSTEM schema• Tables in SYS and SYSTEM schema• Sequences CURRVAL and NEXTVAL

• References– Oracle DocumentationOracle Documentation– ‘Using 11gR2 Result Cache Feature in a RAC

environment – White Paper, Jan’11 – Murali p ,Vallath available at OTN

– ‘Parallel Execution Fundamentals in Oracle Database 11g Release 2’ – White Paper - OTN

Q U E S T I O N SQ U E S T I O N SA N S W E R SA N S W E R SA N S W E R SA N S W E R S

murali.vallath@summersky.biz

Thanks for listeningg

| Murali Vallath | Slide: 38