我的查询中有一个性能问题,执行时间超过 2 分钟。目前主表 f_trans 有 300 万条记录。
我在 where 子句和连接条件中索引了列。
询问 :
SELECT f.no AS refno,
f.v_date AS v_date,
(SELECT fnbalance
(
f.acnt_code,
f.v_date,
)
FROM DUAL) AS balance,
FROM f_trans f JOIN glr_temp glr
ON f.acnt_code = glr.acnt_code
AND ftr.v_date >= '24-Aug-2014'
AND ftr.v_date <= '27-Aug-2014'
JOIN glm_gl_mast glm
ON f.acnt_code = glm.acnt_code
AND glr.acnt_code = glm.acnt_code;
功能:
CREATE OR REPLACE function fnbalance (
p_glcode in number,p_dtdate in date,
)
return number
as
openbal number;
dramt number;
cramt number;
begin
dramt := 0;
cramt := 0;
balamt := 0;
select nvl (sum (f.dr_amt), 0), nvl (sum (f.cr_amt), 0)
into dramt, cramt
from ftrans ftr
where f.v_source <> 'FFT'
and f.acnt_code = p_glcode
and ftr.ftr_vou_date < p_dtdate;
select nvl(( dramt - cramt),0) into balamt from dual;
return balamt;
end
Plan hash value: 1037159964
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 53 | 1537 | 23581 (1)| 00:04:43 |
| 1 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
|* 2 | HASH JOIN | | 53 | 1537 | 23581 (1)| 00:04:43 |
|* 3 | HASH JOIN | | 7342 | 73420 | 12 (9)| 00:00:01 |
| 4 | INDEX FAST FULL SCAN| IND_GLR_ACC | 5214 | 26070 | 5 (0)| 00:00:01 |
| 5 | INDEX FAST FULL SCAN| GLM_AC_INDEX | 7342 | 36710 | 6 (0)| 00:00:01 |
|* 6 | TABLE ACCESS FULL | F_TRANS | 181K| 3364K| 23568 (1)| 00:04:43 |
-------------------------------------------------------------------------------------------
可以帮助我将功能重新组织到选择子句中吗?