How to speed up a query with a lot of subqueries
2
votes
1
answer
2577
views
I have a query which uses a series of functions to return the status of each document for a loan.
SELECT loan_number,
borrower_name,
get_application_status(loan_number, date_application_ordered, date_application_verified),
get_appraisal_status(loan_number, date_appraisal_ordered, date_appraisal_verified),
get_endorsement_status(loan_number, date_endorsement_ordered, date_endorsement_verified),
get_waiver_status(loan_number, date_waiver_ordered, date_waiver_verified),
get_insurance_status(loan_number, date_insurance_ordered, date_insurance_verified)
FROM loans_table
WHERE loan_type IN ('A', 'B', 'C')
AND filing_date > TO_DATE('30-OCT-12')
AND filing_date = date_verified THEN
RETURN 'Not Verified Since Last Upload';
ELSE IF last_upload_date < date_verified THEN
RETURN 'Verified';
END IF;
END get_waiver_status;
How do I get the query to return faster? I have made indexes on loan_number and filing_date. I tried creating a trigger on documents_table to store the last upload_date of a document into a new table for the function to retrieve, but if a document is deleted, I need to be able to select the next latest upload_date from documents_table, which I can't do from within the trigger because I get a mutating table error. I am using PL/SQL on Oracle 10g R2.
Asked by Boric
(123 rep)
Nov 15, 2012, 04:32 PM
Last activity: Nov 15, 2012, 05:04 PM
Last activity: Nov 15, 2012, 05:04 PM