vdo_alarmattach(接近150万条记录) 表根据 alarmguid 进行分组统计,获取到的行数更新到VDO_PRESAFEALARM(近50万条) 中的upcount字段
update VDO_PRESAFEALARM t set t.upcount = (
select upcount
from (SELECT Count(t.alarmguid) as upcount, t.alarmguid
FROM vdo_alarmattach t
GROUP BY alarmguid) K
where K.alarmguid = t.alarmguid
)
以上的语法是否存在问题,执行时间太久。有没有办法进行优化改写
2张表索引 alarmguid 已经添加
这样试试
UPDATE VDO_PRESAFEALARM t,
(
SELECT
Count(t.alarmguid) AS upcount,
t.alarmguid
FROM
vdo_alarmattach t
GROUP BY
alarmguid
) K
SET t.upcount = k.upcount
WHERE
t.alarmguid = K.alarmguid