自连接表上长时间运行的查询
我尝试通过将实际行的值与同一表中的所有其他行进行比较来提高更新表的每一行上的列的查询的性能。查询如下:
update F set
PartOfPairRC = 1
from RangeChange F
where Reject=0
and exists(
select 1 from RangeChange S
where F.StoreID = S.StoreID
and F.ItemNo = S.ItemNo
and F.Reject = S.Reject
and F.ChangeDateEnd = S.ChangeDate - 1)
随着表中行数的增加,查询的性能会迅速下降。我的表中有 5000 万行。
有更好的方法吗? SSIS 能够更好地处理这样的操作吗?
非常感谢任何帮助,谢谢罗伯特
I try to improve the performance of a query which updates a coloumn on each row of a table, by comparing the actual row's values with all other rows in the same table. Here is the query:
update F set
PartOfPairRC = 1
from RangeChange F
where Reject=0
and exists(
select 1 from RangeChange S
where F.StoreID = S.StoreID
and F.ItemNo = S.ItemNo
and F.Reject = S.Reject
and F.ChangeDateEnd = S.ChangeDate - 1)
The query's performance degrades rapidly as the number of rows in the table increases. I have 50 millon rows in the table.
Is there a better way to do this? Would SSIS be able to handle such an operation better?
Any help much appreciated, thanks Robert
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在该表上创建索引:
--当您不使用 SQL Enterprise 时,摆脱索引中的 where 条件并将拒绝列作为索引中的包含列
--确保表上已有聚集索引(如果没有,您可以将上面的索引创建为聚集索引)
--我会将查询编写为联接:
You can try to create a index on that table:
--when you are not using the SQL enterprise get rid of the where condition in the index and put the reject column as included column in the index
--make sure you have a clustered index already on the table (when not you can create the index above as clustered)
-- I would write the query as a join: