Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a PL/SQL pragma similar to DETERMINISTIC, but for the scope of one single SQL SELECT?

In a SQL SELECT statement, I'd like to execute a function that is deterministic for the scope of that SELECT statement (or transaction would be ok, too):

select t.x, t.y, my_function(t.x) from t

Many values of t.x are the same so Oracle could omit calling the same function again and again, to speed things up. But if I label the function as DETERMINISTIC, the results may be cached between several executions of this query. The reason why I can't use DETERMINISTIC is because my_function uses a configuration parameter that is changed from time to time.

Is there any other keyword I could use? Are there any catches that I should be aware of (memory issues, concurrency, etc)? Or maybe any other tricks, such as analytic functions to call the function only once per t.x value (without major performance impact)?

like image 749
Lukas Eder Avatar asked Sep 01 '11 12:09

Lukas Eder


1 Answers

If you do this:

select t.x, t.y, (select my_function(t.x) from dual)
from t

then Oracle can use subquery caching to achieve reduced function calls.

like image 170
Tony Andrews Avatar answered Nov 12 '22 10:11

Tony Andrews