1. mysql in和exist的用法区别
(1)IN()查询适合B表数据比A表数据小的情况,IN()查询是从缓存中取数据
SQL优化:
对于where xxx in 子句效率极其低下问题,经过in的子句外包装一层select xxx from( … )as tmp 后,极大优化效率。
update clear_res set candelete=0 where resid in
(
select resourceid from (
select distinct resourceid from att_attentionresult where important=0
) as tmp
);
(2)exists()适合B表比A表数据大的情况
2. 性能优化案例
网页上有处刷新每次都需要4~5s的时间,分析了下,是由于默认使用了hibernate的自动生成sql方式;
将其修改为自定义sql方式后,运行效率大幅提升。