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.

180 CHAPTER 4 ■ PERFORMANCE MANAGEMENTSQL> select status,name,namespacefrom v$result_cache_objects wherecache_id='4t7p9c4m3xty05wpjas75taw9j';STATUS NAME NAMESPACE---------- ----------------------------------------------------- ---------Published select /*+ result_cache +*/ department_id,avg(salary) SQLSQL>The STATUS column’s value (Published) in the V$RESULT_CACHE_OBJECTS view revealsthat the result for this query is available for use. The other possible values for the STATUS column arenew (result under construction), bypass, expired, and invalid. The NAMESPACE column showsthat this is a SQL statement. The other value for the NAMESPACE column is PLSQL.Examples of Query Result CachingWe’ll use a simple example to show how the SQL query result cache feature works. First specifyresult caching for your query using the result_cache hint. Before you create the newly cachedSQL query, flush the server result cache as well as the shared pool so you start fresh with thenew query whose results you want to store in the server result cache.SQL> exec dbms_result_cache.flushPL/SQL procedure successfully completed.SQL> alter system flush shared_pool;System altered.SQL>The DBMS_RESULT.CACHE_FLUSH procedure purges the server result cache. In this example,we used a simple invocation of the flush procedure, but you can also specify that the databaseretain the free memory in the cache as well as the existing cache statistics. Alternately, insteadof flushing the entire contents of the server result cache, you can execute the invalidate procedureinstead to specify only those results that depend on a specified database object or areowned by a specific user. You most likely are familiar with the alter system flush shared_poolstatement, which flushes the shared pool, so you have no prior executions of the test SQLqueries in the shared pool already.Here’s the test SQL query, with the result_cache hint:SQL> select /*+ result_cache q_name(Query1) */last_name,salaryfrom emporder by salary;

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

Saved successfully!

Ooh no, something went wrong!