简体   繁体   English

SQL Server删除OPENQUERY性能

[英]SQL Server DELETE OPENQUERY performance

We have a series of programs that are designed to move data from one SQL Server database into another using OPENQUERY and database linked servers. 我们有一系列程序,旨在使用OPENQUERY和数据库链接服务器将数据从一个SQL Server数据库移动到另一个数据库。

We are noticing that queries such as the following are taking orders magnitude long than anticipated. 我们注意到以下查询所花费的时间量比预期的长。

DELETE OPENQUERY(server, 'SELECT * FROM table WHERE pkf1 = ''v1'' AND pkf2 = ''v2''')

For example, if the above was rewritten as: 例如,如果以上内容被重写为:

exec('DELETE * FROM table WHERE pkf1 = ''v1'' and pkf2 = ''v2''') at server

or 要么

DELETE FROM server.schema.table WHERE pkf1 = 'v1' and pkf2 = 'v2'

the performance is only a few seconds compared to minutes using OPENQUERY . 与使用OPENQUERY时间相比,性能只有几秒钟。

Can someone explain why the OPENQUERY approach is so inefficient by comparison? 相比之下,有人可以解释为什么OPENQUERY方法如此低效吗? Does it not use the primary key indexes? 它不使用主键索引吗?

与简单查询(例如DELETE)相比,开放查询具有更好的处理程序,并且查询可以在远程服务器中解析

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM