I have select query which uses subquery to produce results:
SELECT
fu.user_name "User name"
, frt.responsibility_name "Responsibility Name"
, furg.start_date "Start Date"
, furg.end_date "End Date"
, fu.last_logon_date "Last Logon Date"
, fr.responsibility_key "Responsibility key"
, fu.email_address "Email Address"
, fu.description "Description"
, m.MANAGER_NAME
, m.MANAGER_EMAIL
FROM
fnd_user_resp_groups_direct furg
, fnd_user fu
, applsys.fnd_responsibility_tl frt
, applsys.fnd_responsibility fr
---------------- this subquery ------------------------
, (select distinct e.employee_number employee_id, e.full_name employee,e.EMAIL_ADDRESS employee_email,
m.employee_number manager_id, m.full_name manager_name, m.EMAIL_ADDRESS as manager_email
from EMPDATA_IMPORT_STG e
,EMPDATA_IMPORT_STG m
where m.employee_number=e.supervisor_name
) m
---------------------------------------
WHERE furg.user_id = fu.user_id
AND furg.responsibility_id = frt.responsibility_id
AND fr.responsibility_id = frt.responsibility_id
AND (to_char(fu.END_DATE) is null OR fu.END_DATE > sysdate)
and fu.email_address=m.EMPLOYEE_EMAIL
and not (frt.responsibility_name like '%iExpenses%' and frt.responsibility_name not like '%iExpenses Setup and Admin%')
and frt.responsibility_name not like '%Expenses Auditor%'
and frt.responsibility_name not like '%Notifications%'
and frt.responsibility_name not like '%Inquiry%' and frt.responsibility_name not like '%INQUIRY%'
and frt.responsibility_name not like '%Self-Service%' and frt.responsibility_name not like '%Self Service%'
and frt.responsibility_name not like '%(Read Only)%' and frt.responsibility_name not like '%Internet Expenses Help Desk%'
and frt.responsibility_name not like '%Employee Opportunities%'
My issue is that EMPDATA_IMPORT_STG table has over 2 millions records and it has non unique index created on its columns EMPLOYEE_NUMBER, FILE_TIMESTAMP. I have tried to execute this in production and it started execution, and i waited 4 minutes and killed my session. Just to mention in test environment same query executes in 10 sec.
How to speed this query execution in production?
Statistics are collected daily in prod and im thinking to create index on email column as well, would that give me faster response?
Thank you