SQLSERVER Union效率难题求解

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

sql是这样的:
第一个查询
with (树 a)
select count(*) from b where b.code = a.code and (b的过滤条件)
耗时0.x秒

第二个查询
with (树 a)
select count(*) from c where c.code = a.code and (c的过滤条件)
耗时也是0.x秒


但这样写就出问题了
with (树 a)
select count(*) from b where b.code = a.code and (b的过滤条件)
union
select count(*) from c where c.code = a.code and (c的过滤条件)

耗时 60+秒......

表数据 a 和 b大的一个是在50万行而已
检查执行路径,似乎c表的全表检索耗时71%,但看不出什么问题来
...全文

相关推荐

评论 19
收藏 已收藏
分享
返回顶部
BurningM
疑难问题 22,298 成员 121,727 内容