I have a query that will be put into a procedure, and it will create a report of id’s. The WHERE clause for my query (not the one in the inner view) is the cause of the long run time. This query takes about twelve minutes, and I was wondering if you guys had any tips on shortening the run time. Or even if there is a way to not show records/rows if the balance = 0 in the pl/sql code of the procedure, rather than in the query.
SELECT x.arp_person_id AS student_id,
xf_ar_charges(x.arp_person_id, '2008FL') as charges,
xf_ar_pymts(x.arp_person_id,'2008FL') as payment,
(xf_ar_charges(x.arp_person_id, '2008FL')
- (xf_ar_pymts(x.arp_person_id,'2008FL')) AS balance
FROM (select distinct arp_person_id
from ar_payments
WHERE arp_fa_transmittal IS NOT NULL
AND ('N' = 'N' OR arp_date BETWEEN TO_DATE('11/01/2008','MM/DD/YYYY')
AND TO_DATE('12/31/2008','MM/DD/YYYY'))
AND ('Y' = 'N' OR arp_term IN ('2008FL', 'N')) ) x
WHERE (xf_ar_charges(x.arp_person_id, '2008FL')
- (xf_ar_pymts(x.arp_person_id,'2008FL')) != 0;
Assuming that you are correct and that the majority of the time is being spent executing the two functions
xf_ar_chargesandxf_ar_pymts(note that this is the logical implication of the implication that it is the outerWHEREclause that is creating the performance problem) the two most likely approaches to improve performance would be to optimize the code behind those procedures or to move the logic out of those procedures and embed it in the SQL statement itself. Without knowing more about your data and your code, it’s hard to suggest which of these would be more likely to improve performance or how to go about optimizing the functions (nor, of course, is it possible for anyone to confirm that it really is the outerWHEREclause that is causing the performance problem).