mysql数据库优化

来源:互联网 发布:湖北大学知行学院几本 编辑:程序博客网 时间:2024/05/16 04:45

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)查询。

0 0