update trade a set name=(select name from cust where id=a.id);最主要是id=a.id这两个字段是否建立有索引, 把id=a.id这两个字段都用上索引就快了。 不错,但name先不要索引。不知道有没有办法让oracle不写日志。
update trade a set name=(select name from cust where id=a.id) where exists (select * from cust b where a.id=b.id)
update trade a set name=(select name from cust where id=a.id) where exists (select id from cust b where a.id=b.id)
建了索引、加上条件可以大大提高你的性能。 如果没有索引,楼主的sql语句实际工作是这样的: 全表扫描trade表,发现有满足条件的(没有条件则全表更新)则更新,每次更新时又做全表扫描cust表,把记录内容找出来。 实际你作了1.3万×1.3万次扫描。 trade、cust都建索引id,再加上条件判断, update trade a set name=(select name from cust where id=a.id) where exists (select id from cust b where a.id=b.id) 你的速度会快很多
把id=a.id这两个字段都用上索引就快了。
不错,但name先不要索引。不知道有没有办法让oracle不写日志。
(select * from cust b where a.id=b.id)
(select id from cust b where a.id=b.id)
如果没有索引,楼主的sql语句实际工作是这样的:
全表扫描trade表,发现有满足条件的(没有条件则全表更新)则更新,每次更新时又做全表扫描cust表,把记录内容找出来。
实际你作了1.3万×1.3万次扫描。
trade、cust都建索引id,再加上条件判断,
update trade a set name=(select name from cust where id=a.id) where exists
(select id from cust b where a.id=b.id)
你的速度会快很多