读书人

update更新为什么这么慢

发布时间: 2012-01-19 20:57:58 作者: rapoo

求助:update更新为什么这么慢?
表中per_amount的计算根据该记录以前月份的s_menge减去h_menge的总计,
我用如下的update语句来更新某月份的该字段值,如果数据量大的话速度
非常慢,不知道大家有没有更好的方式?
update yg_mxledger t01
set per_amount = (select sum(s_menge - h_menge) BB
from yg_mxledger t02
where substr(t02.budat, 1, 6) < substr(t01.budat, 1, 6)
and t01.hkont = t02.hkont
and t01.matnr = t02.matnr
and substr(t02.budat,1,6) < '200608 ')
where substr(t01.budat,1,6) = '200608 ';

[解决办法]
update yg_mxledger t01
set per_amount = (select sum(s_menge - h_menge) BB
from yg_mxledger t02
where
t01.hkont = t02.hkont
and t01.matnr = t02.matnr
and substr(t02.budat,1,6) < '200608 ')
where substr(t01.budat,1,6) = '200608 ';

并在substr(yg_mxledger,1,6)上加索引。

[解决办法]
表的索引可能建的有问题,你单独查询速度如何
[解决办法]
性能
1 select sum(s_menge - h_menge) BB
from yg_mxledger t02
where substr(t02.budat, 1, 6) < substr(t01.budat, 1, 6)
and t01.hkont = t02.hkont
and t01.matnr = t02.matnr);
子查需要多少?

2
where substr(t01.budat,1,6) = '200608 ';
是否造成全表描?
=200608 量有多少?

3
per_amount
字段上可有索引?
[解决办法]
好象用substr会降低效率.
[解决办法]
where substr(t01.budat,1,6) = '200608 ';
是否造成全表扫描
[解决办法]
1. 猜测yg_mxledger.budat字段类型为VARCHAR2?
where substr(t01.budat,1,6) = '200608 ';
更新条件由于使用了substr函数,导致无法使用索引
yg_mxledger表budat字段上建立索引,并改成like查询调用索引,where t01.budat like '200608% ';
2. 尝试在表yg_mxledger的hkont和matnr 字段上建立索引,希望能够提高更新速度
3. 尽量少在查询表的字段上使用substr等函数,避免查询时耗费太多的时间

update yg_mxledger t01
set per_amount = (select sum(s_menge - h_menge) BB
from yg_mxledger t02
where substr(t02.budat,1,6) < '200608 '
and t01.hkont = t02.hkont
and t01.matnr = t02.matnr )
where t01.budat like '200608% ';
[解决办法]
update
多少条记录?

夺得话,可以分段commit;
[解决办法]
使用where exists替换括号中的where 关键字


[解决办法]
表数据情况?
索引情况?
执行计划?

读书人网 >oracle

热点推荐