Sunday, November 30, 2014

Using Result Cache in Oracle 11g Database.

From Oracle 11g we can use result cache in function and query, these results is a faster response time. The cached results stored become invalid when data in the dependent database objects is changed. Result cache is instance specific. The Result Cache Memory pool consists of the SQL Query Result Cache and PL/SQL Function Result Cache, which stores the values returned by PL/SQL functions.

The RESULT_CACHE_MODE parameter determines the SQL query result cache behavior. This parameter contain MANUAL and FORCE. If you set manual you need to specify result_cache hint in your query. If set FORCE  all results use the cache, you can use no_result_cache hint to bypass the cache.

SQL> SET TIMING ON;
SQL> CREATE OR REPLACE FUNCTION RESULT_CASHE_TEST
  2  RETURN NUMBER
  3  RESULT_CACHE
  4  IS
  5  V_RETVALUE NUMBER:=0;
  6  BEGIN
  7
  8  FOR I IN 1 .. 5 LOOP
  9  DBMS_LOCK.sleep(1);
 10  V_RETVALUE:=V_RETVALUE*I;
 11  END LOOP;
 12
 13  RETURN V_RETVALUE;
 14  END ;
 15  /
Function created.
Elapsed: 00:00:00.01
SQL> SELECT RESULT_CASHE_TEST FROM DUAL;
RESULT_CASHE_TEST
-----------------
                0
Elapsed: 00:00:05.02
SQL> SELECT RESULT_CASHE_TEST FROM DUAL;
RESULT_CASHE_TEST
-----------------
                0
Elapsed: 00:00:00.00
SQL>
SQL> CREATE TABLE RESULT_CACHE( ID NUMBER, NAME VARCHAR2(300), SALARY NUMBER);
Table created.
Elapsed: 00:00:00.03
SQL> INSERT INTO RESULT_CACHE VALUES(10,'RAJIB.PRADHAN',5000);
1 row created.
Elapsed: 00:00:00.00
SQL> SELECT /*+ result_cache */  SALARY
  2  FROM RESULT_CACHE
  3  WHERE ID=10;
    SALARY
----------
      5000
Elapsed: 00:00:00.00
SQL>

1 comment:

  1. Caching & Data Streaming Platform (Genex data base)

    Caching for a long term memory to retrieve back and streaming on smooth service platform, all you need is Genex DB, which also is a all time king that deals and safe gaurds your data on a premium level and you don't have to worry about it.Remote Database Support


    We utilize industry best enterprise technologies to help create a content delivery network that accelerates content delivery. Now deliver multimedia content on multiple devices seamlessly. monitored by our professional technicians 24/7. Eliminate bottleneck for data access & processing to gain predictable latency & fast response time as your reach grows.
    We help your applications perform dramatically faster & cost significantly less to scale. Our range of support services for all leading caching systems will help you reduce complexity & cut technical and business risks, efficiently. Be assured that Our engineers work side-by-side with your development, DevOps, Ops, and management teams to assist with design, optimization, upgrades, audits, monitoring, training, and troubleshooting.

    ReplyDelete