简体   繁体   中英

Why is a Teradata query faster in MS-Access than SQL Server

I need to join a Teradata table with about 0.5 billion records and a local table with about 10,000 records. I have it working in MS Access and it takes about 15 minutes to run. I would prefer to do it in SQL Server but can't even get a join with 1 record in the local SQL table to work.

Why is MS Access able to do this, albeit slowly, whereas SQL Server chokes? What is MS Access doing differently from SQL Server?

The SQL Server query with a join that fails:

SELECT a.trk, a.wgt
FROM openquery(TERADATA, 'SELECT trk, wgt 
                          FROM SHIPMENT_DB.pkg') a
INNER JOIN  (Local_Tbl) b ON a.trk = b.Tracking_Number

A simple SQL Server query without a join that works:

SELECT * 
FROM openquery(TERADATA,'SELECT trk, wgt 
                         FROM SHIPMENT_DB.pkg 
                         WHERE trk = ''773423067500''') 

Not the answer, but I had a similar issue using OPENDATASOURCE. Performance was terrible, the query took hours to run. The solution was to ensure all colmns involved in the WHERE clause had mathcing datatypes. In my case the remote column was INT but in the query it was being passed as a varchar: ...'WHERE remote_table.ID = ''4'''... Once I changed all values to the appropriate datatypes the query took seconds to run.

Look at the Execution Plan in SQL Server. Since it knows very little about the dataset that is going to come back from Teradata, it is making some has assumptions.

Swapping the order of the tables in the join will help. Using an explicit INNER HASH JOIN may help (once you've switched the order).

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