简体   繁体   English

为什么MS-Access中的Teradata查询比SQL Server更快

[英]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. 我需要加入一个包含大约5亿条记录的Teradata表和一个包含大约10,000条记录的本地表。 I have it working in MS Access and it takes about 15 minutes to run. 我让它在MS Access中工作,运行大约需要15分钟。 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. 我更喜欢在SQL Server中执行此操作,但甚至无法在本地SQL表中获得具有1条记录的连接。

Why is MS Access able to do this, albeit slowly, whereas SQL Server chokes? 为什么MS Access能够做到这一点,虽然速度很慢,而SQL Server会窒息? What is MS Access doing differently from SQL Server? 什么是MS Access与SQL Server的不同之处?

The SQL Server query with a join that fails: 连接失败的SQL Server查询:

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: 一个没有连接的简单SQL Server查询:

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. 不是答案,但我使用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. 解决方案是确保WHERE子句中涉及的所有colmns都具有数学数据类型。 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. 在我的例子中,远程列是INT,但在查询中它作为varchar传递:...'WHERE remote_table.ID =''4'''...一旦我将所有值更改为相应的数据类型,查询采取了运行秒。

Look at the Execution Plan in SQL Server. 查看SQL Server中的执行计划。 Since it knows very little about the dataset that is going to come back from Teradata, it is making some has assumptions. 由于它对将要从Teradata返回的数据集知之甚少,因此它正在做出一些假设。

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). 使用显式的INNER HASH JOIN可能有所帮助(一旦你切换了订单)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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