Slow performance in linked server query

♀尐吖头ヾ 提交于 2019-12-23 01:54:53

问题


I'm using a Linked Server Query from MSSQL to mySql. MySql table to be queried has 800K + records

I'm using a temp table to pull the results from linked server and do a join on that temp table for SQL query

Is there a performance difference between:

Declare
@MyString varchar(max),
@Address varchar(20),
@tempTable (Address, ColumnB, ColumnC)


set @MyString  = 'Select Address, ColumnB, ColumnC from schemaname.tablename where ''' + convert(varchar(30),@Address) + ''') order by ColumnB desc limit 10'

set @MyString  = 'Select * from Openquery([My_Linked_Server], ''' + REPLACE(@MyString, '''', '''''') + ''')'

insert into @tempTable
exec (@MyString) 

and

Set @MyString = 'Select Address, ColumnB, ColumnC from schemaname.tablename where ''' + convert(varchar(30),@Address) + ''') order by ColumnB desc limit 10'

exec (@MyString) at My_Linked_Server

(all this is done in SQL) --second approach is currently giving me an error:

OLE DB provider "MSDASQL" for linked server "My_Linked_Server" returned message "[MySQL][ODBC 5.2(w) Driver]Optional feature not supported". Msg 7391, Level 16, State 2, Line 14 The operation could not be performed because OLE DB provider "MSDASQL" for linked server "My_Linked_Server" was unable to begin a distributed transaction.

DTC is started

Another problem with using this is that I'm getting random timing on the results 1 second to 1 minute

Thanks in advance!

Update:

First approach gives quite good results. The only issue remaining is the random timing of the results. More than 80% of the times the result is instant. This could be due to MySql table locks (tables of type MyISAM) since there's constant writing to this table and additional job running in SQL Server Querying MySQL for usage information.

Is this a reasonable explanation for the delay?


回答1:


Debugging MSDTC problems can be a bit painful. You said it is running, is it running on both servers? Are there firewall(s) between the servers -- you have to make sure each server can DTCPing the other one. DTCPing is a MS utility you can download. You can have permission problems too.

DTC performance can be pretty awful at times, but this is usually due to bandwidth and roundtrip time issues or memory consumption if the transactions are large. As far as I know, it is always slower than the non MSDTC equivalent -- assuming that they are actually equivalent

Personally, if I can rewrite the query to avoid MSDTC completely, I am usually happier with the result. If you insert the output of an exec proc on the remote server, MSDTC will always be invoked.

No real advice on the random timings, perhaps if you explained in more detail.

Added info on DTC Ping from this article

DTCPING makes anonymous RPC call to remote machine

from xp,sp2,by default,remote machine won't accept anonymous calls,so it is giving you access denied error message (OX5 error code)

if you disable RestrictRemoteClients key,remote machine accepts anonymous calls

http://msdn.microsoft.com/security/productinfo/XPSP2/networkprotection/restrict_remote_clients.aspx

This is just DTCPING tool problem,This error is not related to DTC.



来源:https://stackoverflow.com/questions/18718473/slow-performance-in-linked-server-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!