在MySQL更新數據的時候要避免子查詢post
之前更新表數據SQL,包含子查詢,這樣在MySQL執行中,若是數據多的話執行會十分的緩慢,並且不是通常的慢優化
UPDATE oa_asset oa SET oa.asset_status=3 WHERE oa.asset_id IN( SELECT oac.asset_id FROM oa_assets_clear oac WHERE oac.dispose_type=28 AND oac.check_status=2 AND oac.is_post=1 AND oac.is_del=0 );
優化以下:spa
UPDATE oa_asset oa INNER JOIN (SELECT oac.asset_id FROM oa_assets_clear oac WHERE oac.dispose_type=28 AND oac.check_status=2 AND oac.is_post=1 AND oac.is_del=0) ob ON oa.asset_id=ob.asset_id SET oa.asset_status=3
基本上秒執行成功.net
參考地址code
http://blog.csdn.net/dagailv/article/details/72803203blog