Is it possible for Oracle to reuse the result of a function when it is called in the same query (transaction?) Without using the function's result cache?
The application I'm working with is heavily dependent on Oracle features. Many queries end up performing the same functions multiple times.
A typical example would be:
SELECT my_package.my_function(my_id), my_package.my_function(my_id) / 24, my_package.function_also_calling_my_function(my_id) FROM my_table WHERE my_table.id = my_id;
I noticed that Oracle always performs each of these functions, not realizing that the same function was called just a second ago in the same query. It is possible that some elements in the function are cached, which results in a slightly faster return. This does not apply to my question, since I want to avoid the entire second or third performance.
Assume that the functions are resource-intensive enough and that these functions can call more functions based on their results on tables that are quite large and frequently found (a million records, updates with 1000 updates per hour). For this reason, it is not possible to use Oracle Result Cache.
Despite the fact that data changes frequently, I expect that the result of these functions will be the same when they are called from the same query.
Is it possible for Oracle to reuse the result of these functions and how? I am using Oracle11g and Oracle12c.
The following is an example (just a random non-sensory function to illustrate the problem):
-- Takes 200 ms SELECT test_package.testSpeed('STANDARD', 'REGEXP_COUNT') FROM dual; -- Takes 400ms SELECT test_package.testSpeed('STANDARD', 'REGEXP_COUNT') , test_package.testSpeed('STANDARD', 'REGEXP_COUNT') FROM dual;
Functions Used:
CREATE OR REPLACE PACKAGE test_package IS FUNCTION testSpeed (p_package_name VARCHAR2, p_object_name VARCHAR2) RETURN NUMBER; END; / CREATE OR REPLACE PACKAGE BODY test_package IS FUNCTION testSpeed (p_package_name VARCHAR2, p_object_name VARCHAR2) RETURN NUMBER IS ln_total NUMBER; BEGIN SELECT SUM(position) INTO ln_total FROM all_arguments WHERE package_name = 'STANDARD' AND object_name = 'REGEXP_COUNT'; RETURN ln_total; END testSpeed; END; /
performance function sql oracle
jmuntingh
source share