时间:2021-07-01 10:21:17 帮助过:34人阅读
这是他们开发写的一个SQL语句:SELECTSQL_NO_CACHECOUNT(a.ad_id)FROMt_wiki_adaWHERE1=1andexists(select*fromt_wiki_ad_relbwherea.ad_id=b.ad_idandb.rel_sta
这是他们开发写的一个SQL语句:
SELECT SQL_NO_CACHE COUNT(a.ad_id) FROM t_wiki_ad a WHERE 1 = 1 and exists (select * from t_wiki_ad_rel b where a.ad_id = b.ad_id and b.rel_state = 1 and b.biz_code = '100010') and exists (select * from t_wiki_ad_rel b where a.ad_id = b.ad_id and b.rel_state = 1 and b.biz_id = '代孕母亲') and exists (select * from t_wiki_ad_rel b where a.ad_id = b.ad_id and b.rel_state = 1);执行计划:
执行时间:
耗时30.20秒
优化思路,去除没必要的关联查询,去除1=1,把exist改为join,优化后:
耗时0秒
执行计划:
本文出自 “贺春旸的技术专栏” 博客,请务必保留此出处
,