Loading....

Oracle 21c introduces the ability to improve the performance of queries executed on the read-only active Standby Database by enabling the use of the Result Cache feature to store query results for recurring use- so not just enabled on the Primary database, but the Standby database as well.

The new Oracle 21c clause RESULT_CACHE (STANDBY ENABLE) can be used as part of both CREATE as well as ALTER TABLE statements.

###########################################################################################
Create the Table and Function to test Result Cache

Credit to Tim Hall from Oracle-Base for the function code!
###########################################################################################

SQL> CREATE TABLE demo.tab1 (
  id  NUMBER
);

INSERT INTO demo.tab1 VALUES (1);
INSERT INTO demo.tab1 VALUES (2);
INSERT INTO demo.tab1 VALUES (3);
INSERT INTO demo.tab1 VALUES (4);
INSERT INTO demo.tab1 VALUES (5);

CREATE OR REPLACE FUNCTION demo.fn_tab1(p_id  IN  demo.tab1.id%TYPE)
  RETURN demo.tab1.id%TYPE DETERMINISTIC AS
BEGIN
  DBMS_LOCK.sleep(1);
  RETURN p_id;
END;
/


Table created.

SQL> SQL>
1 row created.

SQL>
1 row created.

SQL>
1 row created.

SQL>
1 row created.

SQL>
1 row created.

SQL> SQL>  

Function created.


###########################################################################################
First execution of the function - takes 5 seconds as expected 
###########################################################################################

SQL> set timing on
SQL> SELECT demo.fn_tab1(id) FROM qrc_tab;

DEMO.FN_TAB1(ID)
----------------
               1
               2
               3
               4
               5

Elapsed: 00:00:05.04



###########################################################################################
Now add RESULT_CACHE hint 

First execution still takes 5 seconds

Subsequent executions takes .01 of a second as Result Cache is being used
###########################################################################################

SQL> select /*+ result_cache */ demo.fn_tab1(id) FROM qrc_tab;

DEMO.FN_TAB1(ID)
----------------
               1
               2
               3
               4
               5

Elapsed: 00:00:05.00

SQL> select /*+ result_cache */ demo.fn_tab1(id) FROM qrc_tab;

DEMO.FN_TAB1(ID)
----------------
               1
               2
               3
               4
               5

Elapsed: 00:00:00.01


###########################################################################################
Enable the Result Cache for ADG Standby Database
###########################################################################################

SQL> alter table demo.tab1 RESULT_CACHE (STANDBY ENABLE);

Table altered.


###########################################################################################
Now on Active Data Guard Standby Database Result Cache is also being used 
###########################################################################################

SQL> select database_role,open_mode from v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY

SQL> select /*+ result_cache */ demo.fn_tab1(id) FROM demo.tab1;

DEMO.FN_TAB1(ID)
----------------
               1
               2
               3
               4
               5

Elapsed: 00:00:05.08

SQL> select /*+ result_cache */ demo.fn_tab1(id) FROM demo.tab1;

DEMO.FN_TAB1(ID)
----------------
               1
               2
               3
               4
               5

Elapsed: 00:00:00.00



Please follow and like us:

Last Update: January 12, 2021  

January 12, 2021 346 Gavin Soorma
Total 1 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Add A Knowledge Base Question !

You will receive an email when your question will be answered.

+ = Verify Human or Spambot ?

, , , , ,

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*

Social media & sharing icons powered by UltimatelySocial
Back To Top

Add A Knowledge Base Question !

You will receive an email when your question will be answered.

+ = Verify Human or Spambot ?