SlideShare a Scribd company logo
1 of 56
Download to read offline
SAGE Computing Services
Customised Oracle Training Workshops and Consulting
The SQL and PL/SQL Results Cache
Is it a Dream Come True or Your Latest Nightmare?
Penny Cookson
Managing Director
penny@sagecomputing.com.au
Agenda
What it is?
How does it work?
What is it good for?
www.sagecomputing.com.au
It takes a long
time to fetch
stuff from
the shops
www.sagecomputing.com.au
So we keep stuff
in the fridge
ready to
cook
But it
still takes
time to cook it
www.sagecomputing.com.au
So why not store
it already
prepared
www.sagecomputing.com.au
Its much faster to
get data from the
SGA than from
disk
www.sagecomputing.com.au
But we still have
to process it
select col1, col2, pk1.func(col3),
sum(col8)
from table1, table2, table3
where col1=col2
and col3=col4
and col4 > (select col5 from table4
where col6 > col7)
group by col1, col2 , pk1.func(col3)
order by col1
www.sagecomputing.com.au
So why not store
it already
processedselect col1, col2, pk1.func(col3),
sum(col8)
from table1, table2, table3
where col1=col2
and col3=col4
and col4 > (select col5 from table4
where col6 > col7)
group by col1, col2 , pk1.func(col3)
order by col1
Results Cache
SGA
SQL Query
Results Cache
Results Cache
PL/SQL Function
Results Cache
populate
invalidate
populate
Query Results Cache
RESULT_CACHE_MODE MANUAL
FORCE
--+ result_cache
--+ no_result_cache
Will not cache if:-
Dictionary tables
Temporary tables
Sequences
Dates/times
Non deterministic PL/SQL
(AUTO is not supported)
DBMS_RESULT_CACHE
DBMS_RESULT_CACHE.STATUS
DBMS_RESULT_CACHE.FLUSH
DBMS_RESULT_CACHE. MEMORY_REPORT
DBMS_RESULT_CACHE. INVALIDATE
DBMS_RESULT_CACHE. BYPASS
Monitoring the Results Cache
SELECT * FROM v$result_cache_memory
SELECT * FROM v$result_cache_objects
SELECT * FROM v$result_cache_statistics
SELECT * FROM v$result_cache_dependency
Demo 1
Disk v Buffer Cache v Result Cache
Matching Criteria
Flushing the Shared Pool and Buffer Cache
Effect on Stats in the Shared Pool
SELECT * FROM v$parameter
WHERE name like 'result_cache%'
Initialisation Parameters
Trace Event - 43905
BEGIN DBMS_RESULT_CACHE.MEMORY_REPORT(true); END;
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 = 10M bytes (10K blocks)
Maximum Result Size = 10M bytes (10K blocks)
[Memory]
Total Memory = 103536 bytes [0.056% of the Shared Pool]
... Fixed Memory = 5140 bytes [0.003% of the Shared Pool]
....... Cache Mgr = 112 bytes
....... Memory Mgr = 128 bytes
....... Bloom Fltr = 2K bytes
....... State Objs = 2852 bytes
... Dynamic Memory = 98396 bytes [0.053% of the Shared Pool]
....... Overhead = 65628 bytes
........... Hash Table = 32K bytes (4K buckets)
........... Chunk Ptrs = 12K bytes (3K slots)
........... Chunk Maps = 12K bytes
........... Miscellaneous = 8284 bytes
....... Cache Memory = 32K bytes (32 blocks)
........... Unused Memory = 16 blocks
........... Used Memory = 16 blocks
............... Dependencies = 4 blocks (4 count)
............... Results = 12 blocks
................... SQL = 4 blocks (1 count)
................... Invalid = 8 blocks (2 count)
Explain Plan
So What Should We Use it For?
Demo 2
Single table – once
Single table – multiple
Join
More complex statement
Changing the Data
SELECT /*+ RESULT_CACHE */ o.org_id, o.name,e.description, b.comments, b.cost
FROM organisations o, events_large e, bookings_large b
WHERE o.org_id = e.org_id
AND e.event_no = b.event_no
AND b.cost >
(SELECT AVG(b10.cost) FROM bookings b10 WHERE b10.event_no = e.event_no)
AND o.org_id = 2264;
SELECT type, status, name, row_count, scan_count
FROM v$result_cache_objects;
Changing the Data
SELECT type, status, name, row_count, scan_count , invalidations
FROM v$result_cache_objects;
UPDATE events_large SET start_date = start_date -1;
COMMIT;
Changing the Data
SELECT * FROM
v$result_cache_statistics;
So What Should We Use it For?
Queries that are:
Frequently accessed
Are not simple (Involve joins /aggregates/
subqueries)
Are based on data which changes rarely
Have an acceptable response even without
the result cache
Which Products Should (NOT) Use It
SELECT type, status, name, row_count,
scan_count, invalidations FROM
v$result_cache_objects;
CREATE OR REPLACE view
bookings_large_vw
AS
SELECT /*+RESULT_CACHE */ *
FROM bookings_large
Execute Query
Second Form
Execute Query
Second Form
SELECT type, status, name, row_count,
scan_count, invalidations FROM
v$result_cache_objects;
and eventually after
_result_cache_timeout
Why the Wait?
SELECT wait_time, event, state
FROM v$session_wait
WHERE sid=138;
WAIT_TIME EVENT STATE
---------- --------------------------------------- ----------
0 enq: RC - Result Cache: Contention WAITING
SELECT event, total_waits, time_waited,
average_wait, time_waited_micro
FROM v$system_event
WHERE event like 'enq: RC%'
ORDER BY time_waited
EVENT TOTAL_WAITS TIME_WAITED AVERAGE_WAIT
----------------------------------- ----------- ----------- -----------
enq: RC - Result Cache: Contention 12 12014 1001.13
if _result_cache_timeout = 0 then no wait
Which Products Should Use It
Only those that fetch all the rows
So never set it as a default
PL/SQL Results Cache
CREATE OR REPLACE FUNCTION quantitybooked
(p_resource_code in resources.code%TYPE,p_event_date in date)
RETURN NUMBER
RESULT_CACHE RELIES_ON (BOOKINGS,EVENTS)
IS
v_total_booked number := 0;
BEGIN
SELECT sum(b.quantity)
INTO v_total_booked
FROM bookings b, events e
WHERE e.event_no = b.event_no
AND p_event_date between e.start_date and e.end_date
AND b.resource_code = p_resource_code;
book_pkg.add_one(v_total_booked, v_total_booked);
RETURN (v_total_booked);
END;
PL/SQL Results Cache
DECLARE
v_num number;
BEGIN
v_num := quantitybooked('VCR2',’06-NOV-2007’);
dbms_output.put_line(v_num);
END;
SELECT *
FROM v$result_cache_objects
9
PL/SQL Results Cache
UPDATE bookings SET quantity = quantity*2;
COMMIT;
DECLARE
v_num number;
BEGIN
v_num := quantitybooked('VCR2',’06-NOV-2007’);
dbms_output.put_line(v_num);
END;
17
PL/SQL Results Cache
CREATE OR REPLACE PACKAGE BODY book_pkg AS
PROCEDURE add_one (p_result IN NUMBER, p_result_out OUT NUMBER)
IS
BEGIN
p_result_out := p_result+10;
END add_one;
END book_pkg;
/
PL/SQL Results Cache
DECLARE
v_num number;
BEGIN
v_num := quantitybooked('VCR2',’06-NOV-2007’);
dbms_output.put_line(v_num);
END;
17
www.sagecomputing.com.au
PL/SQL Results Cache
CREATE OR REPLACE PACKAGE BODY book_pkg AS
PROCEDURE add_one (p_result IN NUMBER, p_result_out OUT NUMBER)
IS
BEGIN
p_result_out := p_result+10;
END add_one;
END book_pkg;
/
BEGIN
dbms_result_cache.invalidate('TRAIN1',’QUANTITYBOOKED');
END;
/
PL/SQL Results Cache
Don’t do stupid stuff
CREATE OR REPLACE FUNCTION non_determ
RETURN VARCHAR2 RESULT_CACHE
IS
BEGIN
RETURN
TO_CHAR(sysdate,'ddmmyyyy hh:mi:ss');
END;
PL/SQL Results Cache - Example
Demo 3
Create and execute a RESULT CACHE function
Using the Results Cache – Design Example
Using the Results Cache – Design Example
Demo 4
Designing a Results Cache Layer
Designing for the Cross Session Results Cache
Data Store
Result Cache – containing managed layer of data
PL/SQL functions
returning objects
Processing
SQL result sets
functions
returning
PL/SQL tables
SQL SQL PL/
SQL
www.sagecomputing.com.au
Writing it in 10g
FUNCTION qty_booked(p_resource IN VARCHAR2
,p_date IN DATE)
RETURN NUMBER
$IF dbms_db_version.ver_le_10 $THEN
$ELSE RESULT_CACHE $END
IS
li_total PLS_INTEGER := 0;
BEGIN
SELECT SUM(b.qty)
INTO li_total
FROM bookings b, events e
WHERE p_date BETWEEN e.start_date AND e.end_date
AND b.resource = p_resource;
RETURN li_total;
END qty_booked;
www.sagecomputing.com.au
Caching Mechanisms
Buffer Cache
PGA Memory
Coherence
Times Ten database
Results Cache
In memory database
Clustered caching services
Coded by developers
Store per user data in PGA
Shared
Results stored
Shared
Block level data stored
So What Should we Use it For?
(Battle of the Experts)
The feature was never
meant for access to
small simple data sets in
TPO applications, its for
aggregations of large
data sets into small
results – like a just in
time MV
The Results Cache causes
contention in TPO systems
So why does Oracle
use it for access to
Apex meta data?
www.sagecomputing.com.au
Result Cache v Materialized Views
Aggregate large amounts of data into small
results set
Store the results in a table
Aggregate large amounts of data into small
results set
Store the results in the SGA
Users accesses the table/buffer cache
User accesses results in the SGA -
maybe
Materialized View
Results cache
www.sagecomputing.com.au
Result Cache v Materialized Views
Materialized View
Results cache
Source
Data
www.sagecomputing.com.au
Monitoring Contention
SELECT name, gets, misses, sleeps,
immediate_gets, immediate_misses
FROM v$latch
WHERE name like '%Result Cache%';
NAME GETS MISSES SLEEPS IMMEDIATE_GETS IMMEDIATE_MISSES
--------------------- -------- -------- ------ -------------- ----------------
Result Cache: Latch 41980 0 0 0 0
Result Cache: SO Latch 16 0 0 0 0
SELECT event, total_waits, time_waited,
average_wait
FROM v$system_event
WHERE event like 'enq: RC%'
EVENT TOTAL_WAITS TIME_WAITED AVERAGE_WAIT
-------------------------------------- ----------- ----------- ------------
enq: RC - Result Cache: Contention 18 18019 1001.05
www.sagecomputing.com.au
A Personal Opinion (or six)
Leave
RESULT_CACHE_MODE
as MANUAL
If you need
aggregation use a
materialized view
not the results cache
Use the PL/SQL
result cache for a
managed layer of
frequently used
results, e.g
metadata
Do not use the result
cache when the time
taken to access the
data from the buffer
cache is unacceptable
(even for one user you
don’t like much)
or aggregates that
are just acceptable
but could be better
Add the
RESULT_CACHE
hint to selected
queries on
reference data
www.sagecomputing.com.au
So – To Complete the Metaphor
Don’t store a whole
load of
watermelons – they
will fill up your
fridge
Its going to take
too long to knock
up a roast if you run
out of them in the
freezer
The PL/SQL
results cache is
designed to
make fast food
even faster
SAGE Computing Services
Customised Oracle Training Workshops and Consulting
Information sources:
The Oracle doco
Vladimir Begun: http://vbegun.blogspot.com
Alex Fatkulin: http://www.pythian.com
Connor McDonald: OracleDBA.co.uk
(who took the p*ss at me using SQL*Developer – thank you for
getting me back to the command line, I promise not to lapse
again)
And a whole load of playing around with the features
SAGE Computing Services
Customised Oracle Training Workshops and Consulting
Questions and Answers?
Presentations are available from our website:
http://www.sagecomputing.com.au
enquiries@sagecomputing.com.au
penny@sagecomputing.com.au
Register for the Next
PL/SQL course:
18th – 20th November
Call in at the Sage Computing Services exhibition booth, or contact Penny
penny@sagecomputing.com.au
0419904458
SAGE Computing Services
(Unrepentant Marketing)

More Related Content

What's hot

Drilling Deep Into Exadata Performance
Drilling Deep Into Exadata PerformanceDrilling Deep Into Exadata Performance
Drilling Deep Into Exadata Performance
Enkitec
 
Trouble shooting apachecloudstack
Trouble shooting apachecloudstackTrouble shooting apachecloudstack
Trouble shooting apachecloudstack
Sailaja Sunil
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Guatemala User Group
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014Fatkulin hotsos 2014
Fatkulin hotsos 2014
Enkitec
 
Advanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache CassandraAdvanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache Cassandra
DataStax Academy
 

What's hot (20)

New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...
 
Drilling Deep Into Exadata Performance
Drilling Deep Into Exadata PerformanceDrilling Deep Into Exadata Performance
Drilling Deep Into Exadata Performance
 
Trouble shooting apachecloudstack
Trouble shooting apachecloudstackTrouble shooting apachecloudstack
Trouble shooting apachecloudstack
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Using AWR/Statspack for Wait Analysis
Using AWR/Statspack for Wait AnalysisUsing AWR/Statspack for Wait Analysis
Using AWR/Statspack for Wait Analysis
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
 
Troubleshooting PostgreSQL with pgCenter
Troubleshooting PostgreSQL with pgCenterTroubleshooting PostgreSQL with pgCenter
Troubleshooting PostgreSQL with pgCenter
 
Cache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From RubyCache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From Ruby
 
Advanced pg_stat_statements: Filtering, Regression Testing & more
Advanced pg_stat_statements: Filtering, Regression Testing & moreAdvanced pg_stat_statements: Filtering, Regression Testing & more
Advanced pg_stat_statements: Filtering, Regression Testing & more
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014Fatkulin hotsos 2014
Fatkulin hotsos 2014
 
PostgreSQL ile Zaman Serileri
PostgreSQL ile Zaman SerileriPostgreSQL ile Zaman Serileri
PostgreSQL ile Zaman Serileri
 
Developing on SQL Azure
Developing on SQL AzureDeveloping on SQL Azure
Developing on SQL Azure
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Caching and tuning fun for high scalability @ 4Developers
Caching and tuning fun for high scalability @ 4DevelopersCaching and tuning fun for high scalability @ 4Developers
Caching and tuning fun for high scalability @ 4Developers
 
Caching and tuning fun for high scalability @ LOAD2012
Caching and tuning fun for high scalability @ LOAD2012Caching and tuning fun for high scalability @ LOAD2012
Caching and tuning fun for high scalability @ LOAD2012
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
 
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and NagiosNagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
 
Beyond php it's not (just) about the code
Beyond php   it's not (just) about the codeBeyond php   it's not (just) about the code
Beyond php it's not (just) about the code
 
Advanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache CassandraAdvanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache Cassandra
 

Viewers also liked

Client coordinator perfomance appraisal 2
Client coordinator perfomance appraisal 2Client coordinator perfomance appraisal 2
Client coordinator perfomance appraisal 2
tonychoper4804
 
Top 8 retail store associate resume samples
Top 8 retail store associate resume samplesTop 8 retail store associate resume samples
Top 8 retail store associate resume samples
tonychoper4405
 
Siminoff_et_al-2014-Psycho?Oncology
Siminoff_et_al-2014-Psycho?OncologySiminoff_et_al-2014-Psycho?Oncology
Siminoff_et_al-2014-Psycho?Oncology
Hardin Brotherton
 
Làm Sao Chữa Bốc Hỏa Đảm Bảo
Làm Sao Chữa Bốc Hỏa Đảm BảoLàm Sao Chữa Bốc Hỏa Đảm Bảo
Làm Sao Chữa Bốc Hỏa Đảm Bảo
major502
 
Collaborate 2015 - Flex Accounting Presentation
Collaborate 2015 - Flex Accounting PresentationCollaborate 2015 - Flex Accounting Presentation
Collaborate 2015 - Flex Accounting Presentation
Ryan Maloney
 
Thoai Hoa Khop Dau Goi
Thoai Hoa Khop Dau GoiThoai Hoa Khop Dau Goi
Thoai Hoa Khop Dau Goi
amalia616
 
Fluorescent Light Business Case
Fluorescent Light Business CaseFluorescent Light Business Case
Fluorescent Light Business Case
Kim Brease
 

Viewers also liked (18)

Client coordinator perfomance appraisal 2
Client coordinator perfomance appraisal 2Client coordinator perfomance appraisal 2
Client coordinator perfomance appraisal 2
 
Top 8 retail store associate resume samples
Top 8 retail store associate resume samplesTop 8 retail store associate resume samples
Top 8 retail store associate resume samples
 
Siminoff_et_al-2014-Psycho?Oncology
Siminoff_et_al-2014-Psycho?OncologySiminoff_et_al-2014-Psycho?Oncology
Siminoff_et_al-2014-Psycho?Oncology
 
Whe listing book 2
Whe listing book 2Whe listing book 2
Whe listing book 2
 
Làm Sao Chữa Bốc Hỏa Đảm Bảo
Làm Sao Chữa Bốc Hỏa Đảm BảoLàm Sao Chữa Bốc Hỏa Đảm Bảo
Làm Sao Chữa Bốc Hỏa Đảm Bảo
 
Collaborate 2015 - Flex Accounting Presentation
Collaborate 2015 - Flex Accounting PresentationCollaborate 2015 - Flex Accounting Presentation
Collaborate 2015 - Flex Accounting Presentation
 
Gost r 53731 2009
Gost r 53731 2009Gost r 53731 2009
Gost r 53731 2009
 
Oracle XML DB - What's in it for me?
Oracle XML DB - What's in it for me?Oracle XML DB - What's in it for me?
Oracle XML DB - What's in it for me?
 
Rekap penyakit pasien rs hermina sukabumi
Rekap penyakit pasien rs hermina sukabumiRekap penyakit pasien rs hermina sukabumi
Rekap penyakit pasien rs hermina sukabumi
 
Interlock fabrics
Interlock fabricsInterlock fabrics
Interlock fabrics
 
6 sodium related terms infographic
6 sodium related terms infographic6 sodium related terms infographic
6 sodium related terms infographic
 
Whose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problemsWhose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problems
 
How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?
 
Thoai Hoa Khop Dau Goi
Thoai Hoa Khop Dau GoiThoai Hoa Khop Dau Goi
Thoai Hoa Khop Dau Goi
 
Title processor performance appraisal
Title processor performance appraisalTitle processor performance appraisal
Title processor performance appraisal
 
Seo starter-guide-equinet-academy
Seo starter-guide-equinet-academySeo starter-guide-equinet-academy
Seo starter-guide-equinet-academy
 
Pearl Academy, LBM : Trendbook
Pearl Academy, LBM : TrendbookPearl Academy, LBM : Trendbook
Pearl Academy, LBM : Trendbook
 
Fluorescent Light Business Case
Fluorescent Light Business CaseFluorescent Light Business Case
Fluorescent Light Business Case
 

Similar to Results cache

Oracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmastersOracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmasters
Kyle Hailey
 
Thomas+Niewel+ +Oracletuning
Thomas+Niewel+ +OracletuningThomas+Niewel+ +Oracletuning
Thomas+Niewel+ +Oracletuning
afa reg
 
200603ash.pdf Performance Tuning Oracle DB
200603ash.pdf Performance Tuning Oracle DB200603ash.pdf Performance Tuning Oracle DB
200603ash.pdf Performance Tuning Oracle DB
cookie1969
 
Adventures in Dataguard
Adventures in DataguardAdventures in Dataguard
Adventures in Dataguard
Jason Arneil
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and Architecture
Sidney Chen
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
Karam Abuataya
 

Similar to Results cache (20)

Oracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmastersOracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmasters
 
Analyzing and Interpreting AWR
Analyzing and Interpreting AWRAnalyzing and Interpreting AWR
Analyzing and Interpreting AWR
 
EKON22 Introduction to Machinelearning
EKON22 Introduction to MachinelearningEKON22 Introduction to Machinelearning
EKON22 Introduction to Machinelearning
 
The MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaThe MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS Schema
 
Thomas+Niewel+ +Oracletuning
Thomas+Niewel+ +OracletuningThomas+Niewel+ +Oracletuning
Thomas+Niewel+ +Oracletuning
 
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
 
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
 
Rmoug ashmaster
Rmoug ashmasterRmoug ashmaster
Rmoug ashmaster
 
Oracle result cache highload 2017
Oracle result cache highload 2017Oracle result cache highload 2017
Oracle result cache highload 2017
 
200603ash.pdf Performance Tuning Oracle DB
200603ash.pdf Performance Tuning Oracle DB200603ash.pdf Performance Tuning Oracle DB
200603ash.pdf Performance Tuning Oracle DB
 
Analyze database system using a 3 d method
Analyze database system using a 3 d methodAnalyze database system using a 3 d method
Analyze database system using a 3 d method
 
Adventures in Dataguard
Adventures in DataguardAdventures in Dataguard
Adventures in Dataguard
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and Architecture
 
Aspects of 10 Tuning
Aspects of 10 TuningAspects of 10 Tuning
Aspects of 10 Tuning
 
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should KnowOTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
 
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should KnowOTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Sherlock holmes for dba’s
Sherlock holmes for dba’sSherlock holmes for dba’s
Sherlock holmes for dba’s
 
Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
 

More from Sage Computing Services

More from Sage Computing Services (12)

Bind Peeking - The Endless Tuning Nightmare
Bind Peeking - The Endless Tuning NightmareBind Peeking - The Endless Tuning Nightmare
Bind Peeking - The Endless Tuning Nightmare
 
Back to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOABack to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOA
 
Vpd
VpdVpd
Vpd
 
Lost without a trace
Lost without a traceLost without a trace
Lost without a trace
 
Meet the CBO in Version 11g
Meet the CBO in Version 11gMeet the CBO in Version 11g
Meet the CBO in Version 11g
 
Take a load off! Load testing your Oracle APEX or JDeveloper web applications
Take a load off! Load testing your Oracle APEX or JDeveloper web applicationsTake a load off! Load testing your Oracle APEX or JDeveloper web applications
Take a load off! Load testing your Oracle APEX or JDeveloper web applications
 
The Cost Based Optimiser in 11gR2
The Cost Based Optimiser in 11gR2The Cost Based Optimiser in 11gR2
The Cost Based Optimiser in 11gR2
 
Transformations - how Oracle rewrites your statements
Transformations - how Oracle rewrites your statementsTransformations - how Oracle rewrites your statements
Transformations - how Oracle rewrites your statements
 
Application Express - A web development environment for the masses - and for ...
Application Express - A web development environment for the masses - and for ...Application Express - A web development environment for the masses - and for ...
Application Express - A web development environment for the masses - and for ...
 
OHarmony - How the Optimiser works
OHarmony - How the Optimiser worksOHarmony - How the Optimiser works
OHarmony - How the Optimiser works
 
Common Coding and Design mistakes (that really mess up performance)
Common Coding and Design mistakes (that really mess up performance)Common Coding and Design mistakes (that really mess up performance)
Common Coding and Design mistakes (that really mess up performance)
 
Oracle Discoverer is dead - Where to next for BI?
Oracle Discoverer is dead - Where to next for BI?Oracle Discoverer is dead - Where to next for BI?
Oracle Discoverer is dead - Where to next for BI?
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Recently uploaded (20)

Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Results cache

  • 1. SAGE Computing Services Customised Oracle Training Workshops and Consulting The SQL and PL/SQL Results Cache Is it a Dream Come True or Your Latest Nightmare? Penny Cookson Managing Director penny@sagecomputing.com.au
  • 2. Agenda What it is? How does it work? What is it good for?
  • 3. www.sagecomputing.com.au It takes a long time to fetch stuff from the shops
  • 4. www.sagecomputing.com.au So we keep stuff in the fridge ready to cook But it still takes time to cook it
  • 5. www.sagecomputing.com.au So why not store it already prepared
  • 6. www.sagecomputing.com.au Its much faster to get data from the SGA than from disk
  • 7. www.sagecomputing.com.au But we still have to process it select col1, col2, pk1.func(col3), sum(col8) from table1, table2, table3 where col1=col2 and col3=col4 and col4 > (select col5 from table4 where col6 > col7) group by col1, col2 , pk1.func(col3) order by col1
  • 8. www.sagecomputing.com.au So why not store it already processedselect col1, col2, pk1.func(col3), sum(col8) from table1, table2, table3 where col1=col2 and col3=col4 and col4 > (select col5 from table4 where col6 > col7) group by col1, col2 , pk1.func(col3) order by col1
  • 9. Results Cache SGA SQL Query Results Cache Results Cache PL/SQL Function Results Cache populate invalidate populate
  • 10. Query Results Cache RESULT_CACHE_MODE MANUAL FORCE --+ result_cache --+ no_result_cache Will not cache if:- Dictionary tables Temporary tables Sequences Dates/times Non deterministic PL/SQL (AUTO is not supported)
  • 12. Monitoring the Results Cache SELECT * FROM v$result_cache_memory SELECT * FROM v$result_cache_objects SELECT * FROM v$result_cache_statistics SELECT * FROM v$result_cache_dependency
  • 13. Demo 1 Disk v Buffer Cache v Result Cache
  • 14.
  • 15.
  • 16.
  • 18. Flushing the Shared Pool and Buffer Cache
  • 19. Effect on Stats in the Shared Pool
  • 20. SELECT * FROM v$parameter WHERE name like 'result_cache%' Initialisation Parameters
  • 21. Trace Event - 43905
  • 22. BEGIN DBMS_RESULT_CACHE.MEMORY_REPORT(true); END; 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 = 10M bytes (10K blocks) Maximum Result Size = 10M bytes (10K blocks) [Memory] Total Memory = 103536 bytes [0.056% of the Shared Pool] ... Fixed Memory = 5140 bytes [0.003% of the Shared Pool] ....... Cache Mgr = 112 bytes ....... Memory Mgr = 128 bytes ....... Bloom Fltr = 2K bytes ....... State Objs = 2852 bytes ... Dynamic Memory = 98396 bytes [0.053% of the Shared Pool] ....... Overhead = 65628 bytes ........... Hash Table = 32K bytes (4K buckets) ........... Chunk Ptrs = 12K bytes (3K slots) ........... Chunk Maps = 12K bytes ........... Miscellaneous = 8284 bytes ....... Cache Memory = 32K bytes (32 blocks) ........... Unused Memory = 16 blocks ........... Used Memory = 16 blocks ............... Dependencies = 4 blocks (4 count) ............... Results = 12 blocks ................... SQL = 4 blocks (1 count) ................... Invalid = 8 blocks (2 count)
  • 24. So What Should We Use it For? Demo 2 Single table – once Single table – multiple Join More complex statement
  • 25. Changing the Data SELECT /*+ RESULT_CACHE */ o.org_id, o.name,e.description, b.comments, b.cost FROM organisations o, events_large e, bookings_large b WHERE o.org_id = e.org_id AND e.event_no = b.event_no AND b.cost > (SELECT AVG(b10.cost) FROM bookings b10 WHERE b10.event_no = e.event_no) AND o.org_id = 2264; SELECT type, status, name, row_count, scan_count FROM v$result_cache_objects;
  • 26. Changing the Data SELECT type, status, name, row_count, scan_count , invalidations FROM v$result_cache_objects; UPDATE events_large SET start_date = start_date -1; COMMIT;
  • 27. Changing the Data SELECT * FROM v$result_cache_statistics;
  • 28. So What Should We Use it For? Queries that are: Frequently accessed Are not simple (Involve joins /aggregates/ subqueries) Are based on data which changes rarely Have an acceptable response even without the result cache
  • 29. Which Products Should (NOT) Use It SELECT type, status, name, row_count, scan_count, invalidations FROM v$result_cache_objects; CREATE OR REPLACE view bookings_large_vw AS SELECT /*+RESULT_CACHE */ * FROM bookings_large Execute Query
  • 31. Second Form SELECT type, status, name, row_count, scan_count, invalidations FROM v$result_cache_objects; and eventually after _result_cache_timeout
  • 32. Why the Wait? SELECT wait_time, event, state FROM v$session_wait WHERE sid=138; WAIT_TIME EVENT STATE ---------- --------------------------------------- ---------- 0 enq: RC - Result Cache: Contention WAITING SELECT event, total_waits, time_waited, average_wait, time_waited_micro FROM v$system_event WHERE event like 'enq: RC%' ORDER BY time_waited EVENT TOTAL_WAITS TIME_WAITED AVERAGE_WAIT ----------------------------------- ----------- ----------- ----------- enq: RC - Result Cache: Contention 12 12014 1001.13 if _result_cache_timeout = 0 then no wait
  • 33.
  • 34. Which Products Should Use It Only those that fetch all the rows So never set it as a default
  • 35. PL/SQL Results Cache CREATE OR REPLACE FUNCTION quantitybooked (p_resource_code in resources.code%TYPE,p_event_date in date) RETURN NUMBER RESULT_CACHE RELIES_ON (BOOKINGS,EVENTS) IS v_total_booked number := 0; BEGIN SELECT sum(b.quantity) INTO v_total_booked FROM bookings b, events e WHERE e.event_no = b.event_no AND p_event_date between e.start_date and e.end_date AND b.resource_code = p_resource_code; book_pkg.add_one(v_total_booked, v_total_booked); RETURN (v_total_booked); END;
  • 36. PL/SQL Results Cache DECLARE v_num number; BEGIN v_num := quantitybooked('VCR2',’06-NOV-2007’); dbms_output.put_line(v_num); END; SELECT * FROM v$result_cache_objects 9
  • 37. PL/SQL Results Cache UPDATE bookings SET quantity = quantity*2; COMMIT; DECLARE v_num number; BEGIN v_num := quantitybooked('VCR2',’06-NOV-2007’); dbms_output.put_line(v_num); END; 17
  • 38. PL/SQL Results Cache CREATE OR REPLACE PACKAGE BODY book_pkg AS PROCEDURE add_one (p_result IN NUMBER, p_result_out OUT NUMBER) IS BEGIN p_result_out := p_result+10; END add_one; END book_pkg; /
  • 39. PL/SQL Results Cache DECLARE v_num number; BEGIN v_num := quantitybooked('VCR2',’06-NOV-2007’); dbms_output.put_line(v_num); END; 17
  • 40. www.sagecomputing.com.au PL/SQL Results Cache CREATE OR REPLACE PACKAGE BODY book_pkg AS PROCEDURE add_one (p_result IN NUMBER, p_result_out OUT NUMBER) IS BEGIN p_result_out := p_result+10; END add_one; END book_pkg; / BEGIN dbms_result_cache.invalidate('TRAIN1',’QUANTITYBOOKED'); END; /
  • 41. PL/SQL Results Cache Don’t do stupid stuff CREATE OR REPLACE FUNCTION non_determ RETURN VARCHAR2 RESULT_CACHE IS BEGIN RETURN TO_CHAR(sysdate,'ddmmyyyy hh:mi:ss'); END;
  • 42. PL/SQL Results Cache - Example Demo 3 Create and execute a RESULT CACHE function
  • 43. Using the Results Cache – Design Example
  • 44. Using the Results Cache – Design Example Demo 4 Designing a Results Cache Layer
  • 45. Designing for the Cross Session Results Cache Data Store Result Cache – containing managed layer of data PL/SQL functions returning objects Processing SQL result sets functions returning PL/SQL tables SQL SQL PL/ SQL
  • 46. www.sagecomputing.com.au Writing it in 10g FUNCTION qty_booked(p_resource IN VARCHAR2 ,p_date IN DATE) RETURN NUMBER $IF dbms_db_version.ver_le_10 $THEN $ELSE RESULT_CACHE $END IS li_total PLS_INTEGER := 0; BEGIN SELECT SUM(b.qty) INTO li_total FROM bookings b, events e WHERE p_date BETWEEN e.start_date AND e.end_date AND b.resource = p_resource; RETURN li_total; END qty_booked;
  • 47. www.sagecomputing.com.au Caching Mechanisms Buffer Cache PGA Memory Coherence Times Ten database Results Cache In memory database Clustered caching services Coded by developers Store per user data in PGA Shared Results stored Shared Block level data stored
  • 48. So What Should we Use it For? (Battle of the Experts) The feature was never meant for access to small simple data sets in TPO applications, its for aggregations of large data sets into small results – like a just in time MV The Results Cache causes contention in TPO systems So why does Oracle use it for access to Apex meta data?
  • 49. www.sagecomputing.com.au Result Cache v Materialized Views Aggregate large amounts of data into small results set Store the results in a table Aggregate large amounts of data into small results set Store the results in the SGA Users accesses the table/buffer cache User accesses results in the SGA - maybe Materialized View Results cache
  • 50. www.sagecomputing.com.au Result Cache v Materialized Views Materialized View Results cache Source Data
  • 51. www.sagecomputing.com.au Monitoring Contention SELECT name, gets, misses, sleeps, immediate_gets, immediate_misses FROM v$latch WHERE name like '%Result Cache%'; NAME GETS MISSES SLEEPS IMMEDIATE_GETS IMMEDIATE_MISSES --------------------- -------- -------- ------ -------------- ---------------- Result Cache: Latch 41980 0 0 0 0 Result Cache: SO Latch 16 0 0 0 0 SELECT event, total_waits, time_waited, average_wait FROM v$system_event WHERE event like 'enq: RC%' EVENT TOTAL_WAITS TIME_WAITED AVERAGE_WAIT -------------------------------------- ----------- ----------- ------------ enq: RC - Result Cache: Contention 18 18019 1001.05
  • 52. www.sagecomputing.com.au A Personal Opinion (or six) Leave RESULT_CACHE_MODE as MANUAL If you need aggregation use a materialized view not the results cache Use the PL/SQL result cache for a managed layer of frequently used results, e.g metadata Do not use the result cache when the time taken to access the data from the buffer cache is unacceptable (even for one user you don’t like much) or aggregates that are just acceptable but could be better Add the RESULT_CACHE hint to selected queries on reference data
  • 53. www.sagecomputing.com.au So – To Complete the Metaphor Don’t store a whole load of watermelons – they will fill up your fridge Its going to take too long to knock up a roast if you run out of them in the freezer The PL/SQL results cache is designed to make fast food even faster
  • 54. SAGE Computing Services Customised Oracle Training Workshops and Consulting Information sources: The Oracle doco Vladimir Begun: http://vbegun.blogspot.com Alex Fatkulin: http://www.pythian.com Connor McDonald: OracleDBA.co.uk (who took the p*ss at me using SQL*Developer – thank you for getting me back to the command line, I promise not to lapse again) And a whole load of playing around with the features
  • 55. SAGE Computing Services Customised Oracle Training Workshops and Consulting Questions and Answers? Presentations are available from our website: http://www.sagecomputing.com.au enquiries@sagecomputing.com.au penny@sagecomputing.com.au
  • 56. Register for the Next PL/SQL course: 18th – 20th November Call in at the Sage Computing Services exhibition booth, or contact Penny penny@sagecomputing.com.au 0419904458 SAGE Computing Services (Unrepentant Marketing)