From Zero to Hero : Using an assortment of caching techniques to improve performance of SQL containing PL/SQL calls. Tim Hall.

Slides:



Advertisements
Similar presentations
Analytic Functions : An Oracle Developer’s Best Friend
Advertisements

PL/SQL : Stop making the same performance mistakes
Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Copyright © SoftTree Technologies, Inc. DB Tuning Expert.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
© Bharati Vidyapeeths Institute of Computer Applications and Management, New Delhi © Bharati Vidyapeeths Institute of Computer Applications and.
Independent consultant Available for consulting In-house workshops Cost-Based Optimizer Performance By Design Performance Troubleshooting Oracle ACE Director.
Copyright © 200\8 Quest Software High Performance PL/SQL Guy Harrison Chief Architect, Database Solutions.
Clarity Educational Community Clarity Educational Community Creating and Tuning SQL Queries that Engage Users.
یا ذالامن و الامان. Virtual Private Database Mohammad Amin Sabbaghian.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
Advanced Package Concepts. 2 home back first prev next last What Will I Learn? Write packages that use the overloading feature Write packages that use.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Bruce Armstrong TeamSybase
PL/SQL Bulk Collections in Oracle 9i and 10g Kent Crotty Burleson Consulting October 13, 2006.
The powerhouse PL/SQL upgrade option: Edition-Based Redefinition (EBR)
Clonedb: The quick and easy cloning solution you never knew you had. Tim Hall Oracle ACE Director Oracle ACE of the Year 2006.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
11g New Features for PL/SQL Developers Tim Hall Oracle ACE Director Oracle ACE of the Year 2006 OCP DBA (7, 8, 8i, 9i, 10g,
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
PL/SQL: It’s all in the presentation! Tim Hall Oracle ACE Director Oracle ACE of the Year 2006 OCP DBA (7, 8, 8i, 9i, 10g, 11g)
SAGE Computing Services Customised Oracle Training Workshops and Consulting Are you making the most of PL/SQL? Hints and tricks and things you may have.
Chapter 6 Additional Database Objects
Oracle PL/SQL Programming Steven Feuerstein All About the (Amazing) Function Result Cache of Oracle Database 11g.
Short Introduction to the RDBMS Software Redundancy Proposal PROBLEM / GOAL: avoid any loosing of up-time service of an application using either commercial.
1 Robert Wijnbelt Health Check your Database A Performance Tuning Methodology.
RBO RIP George Lumpkin Director Product Management Oracle Corporation Session id:
Oracle Tuning Ashok Kapur Hawkeye Technology, Inc.
Oracle PL/SQL Practices. Critical elements of PL/SQL Best Practices Build your development toolbox Unit test PL/SQL programs Optimize SQL in PL/SQL programs.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
PL/SQLPL/SQL Oracle11g : PL/SQL Programming Chapter 6 Functions.
Oracle9i Performance Tuning Chapter 12 Tuning Tools.
Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9.
SEMANTEC 1 Oracle Performance Tuning - Part I Krasen Paskalev Oracle 8i Certified DBA.
SQL Performance and Optimization l SQL Overview l Performance Tuning Process l SQL-Tuning –EXPLAIN PLANs –Tuning Tools –Optimizing Table Scans –Optimizing.
11 Copyright © 2004, Oracle. All rights reserved. Dealing with Database Corruption.
Dynamic SQL. 2 home back first prev next last What Will I Learn? Recall the stages through which all SQL statements pass Describe the reasons for using.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
implicit and an explicit cursor
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Subqueries.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
Session id: Darrell Hilliard Senior Delivery Manager Oracle University Oracle Corporation.
Sorting and Joining.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
Oracle9i Developer: PL/SQL Programming Chapter 5 Functions.
1 Indexes ► Sort data logically to improve the speed of searching and sorting operations. ► Provide rapid retrieval of specified rows from the table without.
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
SQL Triggers, Functions & Stored Procedures Programming Operations.
5 Copyright © 2007, Oracle. All rights reserved. Implementing the Performance Improvements.
Execution Plans Detail From Zero to Hero İsmail Adar.
Caching for PL/SQL Performance Tim Hall Oracle ACE Director Oracle ACE of the Year 2006 OCP DBA (7, 8, 8i, 9i, 10g, 11g) OCA.
Preface IIntroduction Course Objectives I-2 Oracle Complete Solution I-3 Course Agenda I-4 Tables Used in This Course I-5 The Order Entry Schema I-6 The.
Exadata Distinctives 988 Bobby Durrett US Foods. What is Exadata? Complete Oracle database platform Disk storage system Unique to Exadata – intelligent.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Tim Hall Oracle ACE Director
COMP 430 Intro. to Database Systems
392-"JOIN" us on DataServers Journey
SQL Server 2000 and Access 2000 limits
The powerhouse PL/SQL upgrade option: Edition-Based Redefinition (EBR)
Clonedb: The quick and easy cloning solution you never knew you had.
Database Performance Tuning and Query Optimization
Chapter 11 Database Performance Tuning and Query Optimization
Handling Data in PL/SQL Blocks
Query Optimization Techniques
COSC 3480 Projects & Homeworks Fall 2003
Presentation transcript:

From Zero to Hero : Using an assortment of caching techniques to improve performance of SQL containing PL/SQL calls. Tim Hall Oracle ACE Director Oracle ACE of the Year 2006 OakTable Network OCP DBA (7, 8, 8i, 9i, 10g, 11g) OCP Advanced PL/SQL Developer Oracle Database: SQL Certified Expert Books Oracle PL/SQL Tuning Oracle Job Scheduling

What’s the problem? We sometimes need to call PL/SQL functions in the select list of queries.We sometimes need to call PL/SQL functions in the select list of queries. By default, the function may be called for each row returned.By default, the function may be called for each row returned. If the function is called repeatedly with the same input parameters, this can represent a massive waste of resources.If the function is called repeatedly with the same input parameters, this can represent a massive waste of resources. Sometimes we are able to change the query, but not the function. Sometimes we can change the function, but not the query. (setup.sql)Sometimes we are able to change the query, but not the function. Sometimes we can change the function, but not the query. (setup.sql)setup.sql

Scalar Subquery Caching Rewriting function calls as scalar subqueries allows Oracle to cache the results. SELECT (SELECT slow_function(id) FROM dual) FROM func_test;Rewriting function calls as scalar subqueries allows Oracle to cache the results. SELECT (SELECT slow_function(id) FROM dual) FROM func_test; Oracle sets up an in-memory hash table to cache results of scalar subqueries.Oracle sets up an in-memory hash table to cache results of scalar subqueries. The cache only last for the lifetime of the query.The cache only last for the lifetime of the query. The cached values are not reusable in the current session or in other sessions.The cached values are not reusable in the current session or in other sessions. (scalar.sql)(scalar.sql)scalar.sql

DETERMINISTIC Hint The DETERMINISTIC hint has been available for a long time, but didn’t seem to do much until 10g.The DETERMINISTIC hint has been available for a long time, but didn’t seem to do much until 10g. Oracle will optimize calls to functions marked as DETERMINISTIC to improve query performance.Oracle will optimize calls to functions marked as DETERMINISTIC to improve query performance. The caching is based on the array size of fetch, so mileage can vary.The caching is based on the array size of fetch, so mileage can vary. Cached return values only last for the lifetime of the call.Cached return values only last for the lifetime of the call. The cached values are not reusable in the current session or in other sessions.The cached values are not reusable in the current session or in other sessions. (deterministic.sql)(deterministic.sql)deterministic.sql

11g Result Cache 11g introduced two new caching features.11g introduced two new caching features. Both share the same pool of memory in the SGA, controlled using:Both share the same pool of memory in the SGA, controlled using: –RESULT_CACHE_% parameters. –DBMS_RESULT_CACHE package. –V$RESULT_CACHE_% views. ( result_cache.sql) result_cache.sql The Query Result Cache improves performance of complex queries that return small number of rows. (query_result_cache.sql)The Query Result Cache improves performance of complex queries that return small number of rows. (query_result_cache.sql)query_result_cache.sql The Cross-Session PL/SQL Function Result Cache improves performance of function calls by caching the return values. (plsql_result_cache.sql)The Cross-Session PL/SQL Function Result Cache improves performance of function calls by caching the return values. (plsql_result_cache.sql)plsql_result_cache.sql Cached results can be reused in the same session and in other sessions.Cached results can be reused in the same session and in other sessions.

Manual Caching Using PL/SQL Collections Caching of function calls is nothing new.Caching of function calls is nothing new. Caching using PL/SQL collections has been done for many years.Caching using PL/SQL collections has been done for many years. Collections are session-specific, but cached values can be reused in multiple queries.Collections are session-specific, but cached values can be reused in multiple queries. (collection.sql)(collection.sql)collection.sql Manually caching can cause problems for volatile data.Manually caching can cause problems for volatile data. Remember, collections use memory. Don’t go nuts!Remember, collections use memory. Don’t go nuts!

Manual Caching Using Contexts Manual caching using contexts is similar to using collections.Manual caching using contexts is similar to using collections. It shares many of the same drawbacks, but can allow a shared cache between sessions.It shares many of the same drawbacks, but can allow a shared cache between sessions. (context.sql)(context.sql)context.sql

Scalar Subquery Caching (Revisited) Q: Do other caching methods make scalar subquery caching irrelevant?Q: Do other caching methods make scalar subquery caching irrelevant? A: No. Alternative caching mechanisms don’t reduce context switching between SQL and PL/SQL.A: No. Alternative caching mechanisms don’t reduce context switching between SQL and PL/SQL. (plsql_result_cache_2.sql)(plsql_result_cache_2.sql)plsql_result_cache_2.sql You should always use scalar subquery caching, even when using other caching mechanisms.You should always use scalar subquery caching, even when using other caching mechanisms. Scalar Subquery Caching reduces context switches, but other methods have added benefits reuse between queries and sessions.Scalar Subquery Caching reduces context switches, but other methods have added benefits reuse between queries and sessions.

Is there anything relevant in 12c? Functions (and procedures) in the WITH clause. Reduces the context switching associated with PL/SQL calls, which improves performance. WITH FUNCTION slow_function(p_id IN NUMBER) IS BEGIN RETURN p_id; END slow_function; SELECT slow_function(id) FROM test_func;Functions (and procedures) in the WITH clause. Reduces the context switching associated with PL/SQL calls, which improves performance. WITH FUNCTION slow_function(p_id IN NUMBER) IS BEGIN RETURN p_id; END slow_function; SELECT slow_function(id) FROM test_func;

What about the FROM and WHERE clause? Function calls in the select list of an inline view follow the same rules as for the main select list.Function calls in the select list of an inline view follow the same rules as for the main select list. If you are using table functions, consider switching to pipelined table functions.If you are using table functions, consider switching to pipelined table functions. Use Scalar Subquery Caching for functions in the WHERE clause if possible.Use Scalar Subquery Caching for functions in the WHERE clause if possible. Avoid functions on indexed columns, or consider function-based indexes. (fbi.sql)Avoid functions on indexed columns, or consider function-based indexes. (fbi.sql)fbi.sql

What did we cover? Scalar Subquery CachingScalar Subquery Caching DETERMINISTIC HintDETERMINISTIC Hint Cross-Session PL/SQL Function Result CacheCross-Session PL/SQL Function Result Cache Manual Caching Using PL/SQL CollectionsManual Caching Using PL/SQL Collections Manual Caching Using ContextsManual Caching Using Contexts Function calls in the FROM and WHERE clauseFunction calls in the FROM and WHERE clause

The End… Slides and Demos: and Demos: Questions?Questions?