简体   繁体   中英

Using dot notation vs OpenQuery from SQL Server to Oracle

Trying to bring data from Oracle into SQL Server. SQL has a linked server defined. I need to filter data out on the Oracle side, so there is a WHERE clause that limits the data, based on the value of one column (time period).

Tried performance with two different methods: OpenQuery:

select * INTO T2 from OpenQuery(LinkedSrv,'select * from SCHEMA.TAB')

dot notation (LinkedServer..Schema.Table):

select * INTO T2 from LinkedSrv..SCHEMA.TAB

Both perform kind of slow, pushing about 5-6k rows/second. For 20M row table, this is not ideal. And then discovered something rather interesting:

select * INTO T2 from LinkedSrv..SCHEMA.TAB WHERE col >= Value

This pushes the throughput up to almost 100k rows/second

Specifying criteria with OpenQuery does not affect the throughout. Explain plan shows

RemoteQuery -> ComputeScalar -> Filter (WHERE) -> TableInsert in the dot notation scenario with WHERE.

Other than that, explain plans are the same. So... How does adding a WHERE clause locally (because this is where it does it) improve throughput by a factor of 10???

... And what can I do to achieve (the desired outcome) the same fast throughput when using OpenQuery?

Thank you!

The difference between the dot notation and the OpenQuery methods is that the first uses client cursor engine and most things are evaluated locally while the second send the Query to the remote server and read the output.

Not always filtering data in the dot notation query is faster from OpenQuery approach. It is based on each the local and remote server resources.

Check out the following stackoverflow question they will give you more information:

Additional Information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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