mysql 中,一百万条记录,根据如下语句更新?还能继续优化吗
- SQL code
update a set identity=(select identity from b where id='002512' ORDER BY identity desc limit 1 ) where msgidentify='002512' and (identity is null or identity='') ;
------解决方案--------------------------------------------------------
语句上没什么可优化了。
不过如果有如下索引会提高这个SQL语句的速度。
b(id,identity)
a(msgidentify,identity)
------解决方案--------------------------------------------------------
语句好像没能呢,加索引试试
------解决方案--------------------------------------------------------
如果你的msgidentify是主键或索引的话,那就已经没有优化空间了
------解决方案--------------------------------------------------------
select identity from b where id='002512'
ORDER BY identity desc limit 1
生成临时表,再替换