I have a performance issue with the Oracle select statement that I use in the cursor. In the statement, one of the terms in the sentence is SELECTexpensively evaluated (this is a call to the PL / SQL procedure, which pretty much accesses the database). However, the proposals WHEREand ORDER BYare simple.
I expected Oracle to first execute the sentence WHEREto identify the set of records matching the query, then execute the sentence ORDER BYto sort them, and finally evaluate each of the conditions in the sentence SELECT, since I use this operator in the cursor, from which I then retrieve the results , I expected that an expensive member evaluation SELECTwould only be performed as needed, when each result is queried using the cursor.
However, I found that this is not the sequence that Oracle uses. Instead, it evaluates the terms in the sentence SELECTfor each record that matches the WHERE clause before sorting. In this regard, a procedure that is expensive to call is called for each result result in the result set before any results are returned from the cursor.
I want to get the first results from the cursor as quickly as possible. Can someone tell me how to convince Oracle not to evaluate the procedure call in the SELECT statement until sorting is done?
This is probably easier described in the code example:
For a table examplewith columns a, b, cand dI have a statement like:
select a, b, expensive_procedure(c)
from example
where <the_where_clause>
order by d;
, expensive_procedure() , WHERE, .
:
select a, b, expensive_procedure(c)
from example, (select example2.rowid, ROWNUM
from example example2
where <the_where_clause>
order by d)
where example.rowid = example2.rowid;
ROWNUM SELECT Oracle . . , , .
, , , . , , . , , , , , .
Oracle , Oracle PL/SQL , ?