11.07.2015 Views

Oracle Database 11 g - Online Public Access Catalog

Oracle Database 11 g - Online Public Access Catalog

Oracle Database 11 g - Online Public Access Catalog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 4 ■ PERFORMANCE MANAGEMENT 177Note that the force option means the database will cache the results of all SQL statements.By setting the result caching mode to manual, as shown here, you disable automatic querycaching by the database:SQL> alter system set result_cache_mode = manual;Once automatic query caching is disabled, you must use the result_cache hint in yourqueries to enforce query result caching.■Note You can add the result_cache hint to SQL queries, subqueries, and inline views.The result_cache_mode parameter helps you enable the query result cache at the databaselevel. You can enable just session-level caching by setting the parameter using the alter sessionstatement. You can override the setting of the result_cache_mode initialization parameter byspecifying the new optimizer hints result_cache and no_result_cache in order to turn SQLquery caching on and off. The hints will override both the auto and force settings of theresult_cache_mode parameter.If you set the result_cache_mode parameter to manual, you must then specify the result_cache hint in a query so the database can cache the query results. The result_cache hint tellsthe database to cache the current query’s results and to use those results for future executionsof the query or query fragment. If you set the result_cache_mode parameter to auto or force, onthe other hand, the database will try to cache the results of all the queries. If you don’t wantto cache the results of any query under these circumstances, you must specify the no_result_cache hint in the query. The no_result_cache hint, like the result_cache hint, overrides thevalue set for the result_cache_mode parameter.Here’s how you’d use the result_cache hint in a query to turn query caching on for that query:SQL> select /*+ result_cache */avg(income), regionfrom employeesgroup by region;Although the result_cache_mode initialization parameter determines whether the databasecaches the query results, the result_cache_max_size parameter determines the maximumamount of the SGA that the database can allocate to the result cache. Note that the result cachesize you set by using this parameter applies to both components of the server-side result cache—the SQL query result cache as well as the PL/SQL result cache.Even if you don’t set a specific size for the result cache, the result_cache_max_size parameteralways has a positive default size, derived mainly from the memory_target parameter (or thesga_target or shared_pool_size parameter, if you configure one of them). By default, the cachetakes 0.25 percent of the memory_target parameter’s value, 0.5 percent of the sga_target value, and1 percent of shared_pool_size, if you set it. However, the maximum allocation can’t exceed75 percent of the size of the shared pool. In the following example, we haven’t used the result_cache_max_size parameter in the parameter file. However, the database internally allocated adefault amount of 393,216 bytes for the parameter (Maximum Cache Size in the output). In theexample, we generate a server result cache usage report employing the DBMS_RESULT_CACHE package:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!