简体   繁体   中英

SQL Server Linked Server with Oracle - Issue: Select * x Select Columns

I have a performance problem with the OPENQUERY on SQL SERVER 2008 R2: When I run:

select 
*
from openquery([LINKEDSERVER],'
            SELECT
            COLUMN1,COLUMN2,COLUMN3...(45 columns at all)
            FROM ORACLE_TABLE
            WHERE X>Y')

the response time past 5 minutes (yes, 5 minutes). But, if I run the same select with one only column on Oracle side:

select 
*
from openquery([SERVER],'
            SELECT
            COLUMN1
            FROM ORACLE_TABLE
            WHERE X>Y')

the response time is 17 seconds (10.000 records).

Any ideas?

What are the wait events on both sides? What are the query plans?

Is the process waiting on network traffic? If so, presumably, 45 columns of data has substantially more data to transmit over the network. If we assume that it is 45 times more data and that 7 of the 17 elapsed seconds in the faster case is spent on network traffic, then going from one column of data to 45 columns of data would increase the amount of network wait events by 7s * 44 columns = 308 seconds. So without more information, going from 17 seconds to 5 minutes by increasing the amount of data you're sending over the network by a factor of 45 seems at least potentially reasonable.

Of course, if you tell us that column1 is a large image and the other 44 columns are CHAR(1) columns that each consume a single byte, then an increase in network traffic wouldn't be a reasonable explanation for the change in performance.

Is column1 indexed? If so, perhaps there is a very different plan when you want to fetch all 45 columns. Perhaps the first query plan shows that Oracle simply has to scan a small covering index while the second plan shows that it has to do a much more expensive table scan.

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