谁能把这个sql优化下

classnameextendsjava classnameextendsjava 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

select
A.aaID,
A.aaName,
A.aaIP,
D.ddName,
E.eeName,
count(distinct(f.ooID))
from
A
join B on A.bbID=B.bbID
join C on B.ccID=C.ccID
left join D on A.ddID=D.ddID
left join E on A.eeID=E.eeID
left join F on
(F.xxID=A.aaID and F.yyID=1)
or
(exists(select 1 from G where G.aaID=A.aaID and G.ggID=F.xxID) and F.yyID=2)
or
(exists(select 1 from H,G where H.ggID=G.ggID and G.aaID=A.aaID and H.hhID=F.xxID ) and F.yyID=3)
where
C.ccID= ?
group by
A.aaID,
A.aaName,
A.aaIP,
D.ddName,
E.eeName

这个sql执行需要30秒左右
(exists(select 1 from G where G.aaID=A.aaID and G.ggID=F.xxID) and F.yyID=2)这个花的时间较长 大约25秒 G表里有5W条数据
...全文
评论 15
收藏 已收藏
分享
返回顶部