询问者
SQL SERVER 2016/2019 非聚集列存储索引大表JOIN小表性能问题

问题
-
全部回复
-
你好,
如果可以的话,请分享一下语句和执行计划。
你可以尝试创建聚集索引; 也可以尝试用where in子句句查询,当INNER JOIN 表中列数据是重复的,此时IN性能要INNER JOIN要好
希望对你有用
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
感谢您的及时回复!
表已经有一个聚集索引。引入非聚集列式存储索引,是为了对数据进行分析时获得更好的性能。
可参见下面的图片(因无法上传,暂时贴了一个的链接地址,辛苦移步),其中DMS_DATA_SALE表是大表,T为仅5行记录的小表,他们通过ID进行关联。 不管是使用INNER JOIN,还是WHERE IN,在性能上都不太理想。 使用小表中的5个值,以常量形式对大表进行过滤,基本秒查。 我期望的是在关联类似小表时,优化器能识别出小表是几个有限值,能直接按照常量值的处理方式执行。尝试通过查找有无QUERY HINTS无果, 所以想问问官方能否对这个提供支持,谢谢!
1)INNER JOIN图片地址 https://social.microsoft.com/Forums/getfile/1595060
2) WHERE IN图片地址 https://social.microsoft.com/Forums/getfile/1595092
3) 使用常量图片地址 https://social.microsoft.com/Forums/getfile/1595095
-
你好,
查了相关文档,由于你的一个表很大,另一个表较小,我觉得你可以用inner Hash join。
Hash join可以有效处理未排序的大型非索引输入,它的工作方式是将一个表(通常是小一点的那个表)做hash运算,将列数据存储到hash列表中,从另一个表中抽取记录,做hash运算,到hash 列表中找到相应的值,做匹配。你可以参考以下文章:
多表连接的三种方式详解 hash join、merge join、 nested loop
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- 已编辑 Dawn YoungMicrosoft contingent staff 2020年5月20日 8:31
-
不好意思,你的图片都看不了了,能否再发一下?
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
把图片传到百度网盘上了,链接也无法插入,还得麻烦您复制到浏览器啊。
https://pan.baidu.com/s/1f0TSjciOkl4IQPk3w8qBow 提取码:2x47
https://pan.baidu.com/s/1Jg8VyOBfZLAe-1zhF4s0Ow 提取码:6y66
https://pan.baidu.com/s/1kvDqrVJ_4vyd-uXlrqoGVQ 提取码:hed9
- 已编辑 luckydogs168 2020年5月25日 8:14 该论坛不支持上传图片