本文介绍了内联接vs内联接(SELECT.FROM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同一查询的这两个版本之间在性能方面是否存在差异?

Is there any difference in terms of performance between these two versions of the same query?

--Version 1
SELECT p.Name, s.OrderQty
FROM Product p
INNER JOIN SalesOrderDetail s on p.ProductID = s.ProductID

--Version 2
SELECT p.Name, s.OrderQty
FROM Product p
INNER JOIN (SELECT ProductID, OrderQty FROM SalesOrderDetail) s on p.ProductID = s.ProductID

我听说(DBA)说版本2更快,因为它在内部SELECT语句中仅获取查询所需的列.但这似乎没有意义,因为查询性能(据我所知)基于受影响的行数和返回的最终列列表.

I've heard it said (by a DBA) that Version 2 is faster because it fetches, within the inner SELECT statement, only the columns that are required for the query. But that doesn't seem to make sense, since query performance (as I know) is based on number of rows affected and final list of columns returned.

两者的查询计划是相同的,所以我猜两者之间没有任何区别.

The query plans for both are identical, so I'm guessing there isn't any difference between the two.

我正确吗?

推荐答案

您是正确的.您做的完全正确,检查了查询计划,而不是尝试猜测优化器. :-)

You are correct. You did exactly the right thing, checking the query plan rather than trying to second-guess the optimiser. :-)

这篇关于内联接vs内联接(SELECT.FROM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 00:00