mysql数据库优化

时间:2022-06-28 06:53:10

in (select xxx)


优化前(用时0.8s)

update tb_statistics set count=count+1, created=now() where entity='User' and linked_id in (select action.user_id AS id from tb_action action where action.id=10686 and action.status=1) and linked_id<>1372 and (type = ('my_activity'));


优化后(用时0.05s)
update tb_statistics, (select action.user_id AS id from tb_action action where action.id=10686 and action.status=1) AS b set count=count+1, created=now() where entity='User' and linked_id=b.id and linked_id<>1372 and (type = ('my_activity'));


优化说明:请不用使用in (select xxx)查询。