Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 http://www.oracle-base.com 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 PL/SQL Developer http://www.oracle-base.com Oracle PL/SQL Tuning (Rampant) Oracle Job Scheduling (Rampant)

2 http://www.oracle-base.com Caching for PL/SQL Performance Using arrays for lookup tables.Using arrays for lookup tables. Cross-Session PL/SQL Function Result CacheCross-Session PL/SQL Function Result Cache Query Result CacheQuery Result Cache

3 http://www.oracle-base.com Using arrays for lookup tables Many systems have lots of small lookup tables.Many systems have lots of small lookup tables. Most of these lookup tables contain static data.Most of these lookup tables contain static data. Data loads/extracts often access lookup tables for each row processed.Data loads/extracts often access lookup tables for each row processed. The overhead of these static lookups can be reduce significantly by caching the data in associative arrays.The overhead of these static lookups can be reduce significantly by caching the data in associative arrays. setup.sqlsetup.sqlsetup.sql lookup_api.sqllookup_api.sqllookup_api.sql lookup_test.sqllookup_test.sqllookup_test.sql Using other collection types doesn’t work so well.Using other collection types doesn’t work so well. lookup_api_incorrect.sqllookup_api_incorrect.sqllookup_api_incorrect.sql lookup_test.sqllookup_test.sqllookup_test.sql

4 http://www.oracle-base.com Considerations when caching data Data Volatility – Only cache static data, or data you expect to be static during the lifetime of your process. *Data Volatility – Only cache static data, or data you expect to be static during the lifetime of your process. * Memory Usage – Collections are held in memory, so lots of cached tables will waste lots of memory. Also, the caching is session-specific, so lots of sessions means lots of memory used. *Memory Usage – Collections are held in memory, so lots of cached tables will waste lots of memory. Also, the caching is session-specific, so lots of sessions means lots of memory used. * Initialization Time – The data must be cached before processing starts, which takes time. *Initialization Time – The data must be cached before processing starts, which takes time. * * - Clever implementation can offset some of these issues.* - Clever implementation can offset some of these issues. Lookup Type – This method is restricted to lookups using a single “index” column. Prior to 9i R2, it is limited to number based indexes.Lookup Type – This method is restricted to lookups using a single “index” column. Prior to 9i R2, it is limited to number based indexes. Bad Implementation – Test to make sure you are actually seeing improvements.Bad Implementation – Test to make sure you are actually seeing improvements.

5 http://www.oracle-base.com PL/SQL Function Result Cache The cross-session PL/SQL function result cache boosts the performance of PL/SQL functions by caching results in the SGA.The cross-session PL/SQL function result cache boosts the performance of PL/SQL functions by caching results in the SGA. The cache is accessible to any session calling the same function with the same parameters.The cache is accessible to any session calling the same function with the same parameters. Caching clause results in significant performance improvements when functions are called for each row in an SQL query, or within a loop in PL/SQL.Caching clause results in significant performance improvements when functions are called for each row in an SQL query, or within a loop in PL/SQL. The RESULT_CACHE clause indicates a function is available for caching.The RESULT_CACHE clause indicates a function is available for caching. pfrc_setup.sql & pfrc_test.sqlpfrc_setup.sql & pfrc_test.sqlpfrc_setup.sqlpfrc_test.sqlpfrc_setup.sqlpfrc_test.sql The optional RELIES_ON clause is used to specify dependent tables and views so the result cache can be invalidated if the dependent objects are modified.The optional RELIES_ON clause is used to specify dependent tables and views so the result cache can be invalidated if the dependent objects are modified. relies_on.sql & pfrc_test.sqlrelies_on.sql & pfrc_test.sqlrelies_on.sqlpfrc_test.sqlrelies_on.sqlpfrc_test.sql Performance improvements depend on the nature of the work being done.Performance improvements depend on the nature of the work being done.

6 http://www.oracle-base.com SQL Result Cache The query result cache stores the result of queries in the SGA.The query result cache stores the result of queries in the SGA. The cache is accessible to any session calling the same query.The cache is accessible to any session calling the same query. The RESULT_CACHE hint indicates the results of a query should be cached.The RESULT_CACHE hint indicates the results of a query should be cached. qrc_setup.sql, qrc_test_1.sql & qrc_test_2.sqlqrc_setup.sql, qrc_test_1.sql & qrc_test_2.sqlqrc_setup.sqlqrc_test_1.sqlqrc_test_2.sqlqrc_setup.sqlqrc_test_1.sqlqrc_test_2.sql The result cache is controlled by the RESULT_CACHE_MODE parameter. Settings:The result cache is controlled by the RESULT_CACHE_MODE parameter. Settings: –MANUAL – (default) Query must include the RESULT_CACHE hint to be cached. –FORCE – Caching can be prevented using the NO_RESULT_CACHE hint. qrc_force.sqlqrc_force.sqlqrc_force.sql

7 http://www.oracle-base.com Cache Administration The query result cache and PL/SQL Function result cache use same result cache memory pool.The query result cache and PL/SQL Function result cache use same result cache memory pool. The pool is configured using the RESULT_CACHE_% parameters.The pool is configured using the RESULT_CACHE_% parameters. rc_params.sqlrc_params.sqlrc_params.sql –result_cache_mode - MANUAL or FORCE control what and how caching takes place. –result_cache_max_size - Amount of SGA used for the cache. Zero disables the feature. –result_cache_max_result - The percentage of total cache any single query can use. –result_cache_remote_expiration - The number of minutes remote objects remain valid. Zero means remote objects are not cached.

8 http://www.oracle-base.com Cache Administration The DBMS_RESULT_CACHE package provides some cache management (invalidations, flushing, bypass, memory usage).The DBMS_RESULT_CACHE package provides some cache management (invalidations, flushing, bypass, memory usage). Performance information about the cache is displayed using the V$RESULT_CACHE_% views.Performance information about the cache is displayed using the V$RESULT_CACHE_% views. rc_views.sqlrc_views.sqlrc_views.sql –V$RESULT_CACHE_DEPENDENCY - Displays dependencies between cached results and database objects. –V$RESULT_CACHE_MEMORY - Displays result cache memory usage. –V$RESULT_CACHE_OBJECTS - Displays attributes of cached results and dependencies. –V$RESULT_CACHE_STATISTICS - Displays various result cache settings and usage statistics. The result cache memory pool is part of the SGA, so you need free memory to make use of it.The result cache memory pool is part of the SGA, so you need free memory to make use of it.

9 http://www.oracle-base.com Summary Caching lookup tables in arrays can improve performance for batch operations.Caching lookup tables in arrays can improve performance for batch operations. Manually caching volatile data is dangerous.Manually caching volatile data is dangerous. Caching data requires memory, so be careful.Caching data requires memory, so be careful. The query result cache and PL/SQL function cache automate caching for us in 11g.The query result cache and PL/SQL function cache automate caching for us in 11g. Always test to make sure the improvements are worth the effort!Always test to make sure the improvements are worth the effort! Example code:Example code: http://www.oracle-base.com/workshops/caching_for_plsql_performance/scripts.ziphttp://www.oracle-base.com/workshops/caching_for_plsql_performance/scripts.ziphttp://www.oracle-base.com/workshops/caching_for_plsql_performance/scripts.zip


Download ppt "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."

Similar presentations


Ads by Google