Help me optimize the following sqls.
In my payroll database (Oracle 8i), when multiple update statement were issued in a single session the time for execution of the update statement gradually increases. There are trigger associated with the table which again calls other stored procedures. My updation script was run from backend and it follows,
<<
update mst_employee set basic_pay=6560,basic_eff_date='01-Jan-1997' where emp_code=21949;
commit;
update mst_employee set basic_pay=6890,basic_eff_date='11-Jul-1997' where emp_code=21949;
commit;
update mst_employee set basic_pay=7095,basic_eff_date='01-Jan-1998' where emp_code=21949;
commit;
update mst_employee set basic_pay=7310,basic_eff_date='01-Jan-1999' where emp_code=21949;
commit;
update mst_employee set basic_pay=7530,basic_eff_date='01-Jan-2000' where emp_code=21949;
commit;
update mst_employee set basic_pay=7755,basic_eff_date='01-Jan-2001' where emp_code=21949;
commit;
update mst_employee set basic_pay=7990,basic_eff_date='01-Jan-2002' where emp_code=21949;
commit;
update mst_employee set basic_pay=8230,basic_eff_date='01-Jan-2003' where emp_code=21949;
commit;
update mst_employee set basic_pay=8640,basic_eff_date='24-Sep-2003' where emp_code=21949;
commit;
update mst_employee set basic_pay=8940,basic_eff_date='01-Jan-2004' where emp_code=21949;
commit;
update mst_employee set basic_pay=9255,basic_eff_date='01-Jan-2005' where emp_code=21949;
commit;
update mst_employee set basic_pay=9580,basic_eff_date='01-Jan-2006' where emp_code=21949;
commit;
update mst_employee set basic_pay=9915,basic_eff_date='01-Jan-2007' where emp_code=21949;
commit;
<<
Initial statements were taking around 20 seconds but by the stage when last statement was reached it took around 5 minutes. It may be a tuning issue. Please help me out.
I have analysed the statements within the procedures and found the following statement taking maximum time during execution of the last update statement.
<<>>
<<>>>
UPDATE TEMP_CCADAPROJERP
SET old_amt = (
SELECT NVL(SUM(amount), 0)
FROM HIST_TRAN_MONTHLY
WHERE pay_class_code IN (20, 29)
and HIST_TRAN_MONTHLY.emp_code = TEMP_CCADAPROJERP.emp_code
and due_yymm = TEMP_CCADAPROJERP.effective_yymm
and recurring IN ('C', 'R')
)
WHERE from_date = (
SELECT MIN(T.from_date)
FROM TEMP_CCADAPROJERP T
WHERE T.effective_yymm = TEMP_CCADAPROJERP.effective_yymm
and T.emp_code = TEMP_CCADAPROJERP.emp_code
and T.session_id=TEMP_CCADAPROJERP.session_id
)
and session_id = spr_cca_da_proj_erp.sessn_id;
<<<<<>>>>
UPDATE TRAN_MONTHLY
SET amount = (
SELECT SUM(new_amt - old_amt)
FROM TEMP_CCADAPROJERP C
WHERE C.effective_yymm = TRAN_MONTHLY.due_yymm
and C.emp_code = TRAN_MONTHLY.emp_code
and C.session_id = spr_cca_da_proj_erp.sessn_id
),
recurring = 'C',
user_id = spr_cca_da_proj_erp.user_id,
current_date = spr_cca_da_proj_erp.process_date
WHERE due_yymm IN (
SELECT effective_yymm
FROM TEMP_CCADAPROJERP
WHERE TEMP_CCADAPROJERP.emp_code = TRAN_MONTHLY.emp_code
and session_id = spr_cca_da_proj_erp.sessn_id
)
and due_yymm < spr_cca_da_proj_erp.process_yymm
and TRAN_MONTHLY.emp_code IN (
SELECT emp_code
FROM TEMP_CCADAPROJERP
WHERE maxdate_bit = 1
and session_id = spr_cca_da_proj_erp.sessn_id
)
and pay_class_code = spr_cca_da_proj_erp.pcl
and recurring = 'C'
and adj_flag = 1;
<<
kindly help me out of the problem.