使用 MySQL 作为 SQL Server 的链接服务器时查询速度缓慢(ODBC 连接)
当从 SQL Server 在 MySQL 链接服务器上运行存储例程时,我发现查询性能非常差。从 SQL Server 运行查询
select * from OPENQUERY(COGNOS, 'call reporting.sr_vendor_location_report(''2011-06-13 00:00:00'',''2012-01-18 00:00:00'',1,''0,1'',28,''(All)'',''(All)'',1,''(All)'')')
需要 15 秒,但如果我检查 mysql 查询日志或直接在服务器上运行它,我发现只需要 7 秒。
我在其他地方读到 MySQL ODBC 连接速度很慢,但我没有看到任何建议的解决方案。我尝试设置 mysql-proxy(仅使用重定向运行它 - 无 LUA 脚本),但没有看到任何改进。我正在使用 MySQL ODBC Connector 5.1 并在服务器上运行 MySQL 版本 5.5。
如果您有任何有关尝试的想法,我将非常感激。
更新
事实证明,openquery 在 mysql 服务器上运行每个查询两次,第一次可能是为了获取元数据。有什么办法可以避免这种情况吗?
I'm seeing very poor query performance when running a stored routine on a MySQL linked server from a SQL Server. The query runs from the SQL Server
select * from OPENQUERY(COGNOS, 'call reporting.sr_vendor_location_report(''2011-06-13 00:00:00'',''2012-01-18 00:00:00'',1,''0,1'',28,''(All)'',''(All)'',1,''(All)'')')
takes 15 seconds but if I check the mysql query log or run it on the server directly, I see that it only takes 7 seconds.
I've read elsewhere that MySQL ODBC connections are slow but I haven't seen any solutions suggested. I tried setting up mysql-proxy (just running it with a redirection - no LUA scripts) but didn't see any improvement. I'm using the MySQL ODBC Connector 5.1 and running MySQL version 5.5 on the server.
I'd be enormously grateful for any ideas on what to try.
UPDATE
It turns out that openquery runs each query twice on the mysql server, the first time presumably to get metadata. Is there any way to avoid this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将提供程序配置为在进程外运行(右键单击提供程序并取消选中“允许在进程中”框)。
这并不完全是与性能相关的设置,但我在某些情况下使用 oracle 看到了良好的性能提升,也许它也适用于 mysql。
try to configure the provider to run out-of-process (right click on the provider and uncheck the allow in process box).
This is not exactly a setting related with performance, but I saw good performance gains in some cases with oracle, maybe it works with mysql too.
事实证明,使用RPC而不是OPENQUERY解决了SQL Server生成两个查询的问题。
例如
变成
It turns out that using RPC instead of OPENQUERY solves the problem of SQL Server generating two queries.
e.g.
becomes