此查询需要16秒才能运行
SELECT
WO.orderid
FROM
WebOrder as WO
INNER JOIN Addresses AS A ON WO.AddressID = A.AddressID
LEFT JOIN SalesOrders as SO on SO.SO_Number = WO.SalesOrderID
如果我注释掉任何一个连接,它会在很短的时间内运行。例如:
SELECT
WO.orderid
FROM
WebOrder as WO
INNER JOIN Addresses AS A ON WO.AddressID = A.AddressID
-- LEFT JOIN SalesOrders as SO on SO.SO_Number = WO.SalesOrderID
或
SELECT
WO.orderid
FROM
WebOrder as WO
-- INNER JOIN Addresses AS A ON WO.AddressID = A.AddressID
LEFT JOIN SalesOrders as SO on SO.SO_Number = WO.SalesOrderID
备注
慢版本的执行计划(SalesOrders Join已注释掉)
快速版的执行计划
为什么这些连接在一起使用时会导致从0.01秒到16秒?
答案 0 :(得分:2)
您的执行计划没有显示任何昂贵的操作,我会尝试关注以解决性能不佳问题:
DBCC FREEPROCCACHE
我个人不希望后者做任何事情 - 看起来你有一个合理的查询计划。