Hi
Using below option will show you in the log what Oracle SQL syntax actually gets sent to the DB.
options sastrace=',,,d' sastraceloc=saslog nostsuffix;
from:
http://support.sas.com/documentation/cdl/en/acreldb/63647/HTML/default/viewer.htm#a000433982.htm
You're joining 6 tables (one of it a left join). Depending of what path Oracle takes this could be quite inefficient.
It sometimes helps to just re-order the joins a bit. What I like to do in such a case is to use a tool like SQL developer, write my SQL query in Oracle syntax and then use explain - and also look at the "Costs". This makes tweaking the code much easier.
If you don't have this possibility then one way worth trying could be to identify tables where an inner join reduces volumes the most and then reformulate your query accordingly. I.e. let's say the inner join of account and patient:
select fs.sender_name "Specialty Pharmacy",
pat.drc_case_id "DRC CASE ID",
ship.most_recent_ship_date "Milestone_Date",
ship.ndc_nbr "Product",
'Ship' as "Milestone_Type"
bi.num_of_days_supplied "Days of Therapy"
from
(
cld_account_cooked acct,
cld_benefit_cooked bi,
received_files rf,
cload.file_senders fs,
(select
pat.drc_case_id "DRC CASE ID",pat.received_file_id
from
cld_account_cooked acct,
cld_patient_cooked pat
where acct.cld_account_cooked_id = pat.cld_account_cooked_id
) pat
)
left join cld_detail_cooked ship on ship.cld_patient_cooked_id = pat.cld_patient_cooked_id
where rf.file_date_of_report lt;= '01-Jan-2010'
and fs.sender_name = 'SDI CuraScript'
and rf.received_file_id = pat.received_file_id
and bi.cld_patient_cooked_id = pat.cld_patient_cooked_id
and fs.file_sender_id = rf.file_sender_id
As inner joins perform normally much better than left joins you could also try to have all the inner joins in such a sub-select bracket and only then add the left join.
Make also sure that the table for the left join has a 1 to zero or one cardinality or else you might end up with much more resulting rows than expected (and this would be a reason for the long running query).
By the way: Should the date end with a 'd': '01-Jan-2010'd
HTH
Patrick
Message was edited by: Patrick