Reputation: 5041
I am trying to understand how Sql Server handles views and joins inside the views.
I have a view something like.
CREATE VIEW
[dbo].[vw_Product]
AS
SELECT
Product.Id AS ProductId,
Customer.Name AS CustomerName
FROM
Product
INNER JOIN
Customer ON Customer.Id = Product.CustomerId
What is the difference between the following two queries in terms of performance?
SELECT ProductId, CustomerName FROM vw_Product
SELECT ProductId FROM vw_Product
The reason for asking this question is that the first query selects CustomerName. In the view there is an Inner Join on the Customer table. An Inner Join execution has its extra cost on the performance.
Upvotes: 0
Views: 3635
Reputation: 1723
Basically the second query will be a bit slower, because the data returned by the SQL Server contains additional column. In both cases INNER JOIN
will take place.
Upvotes: 1
Reputation: 13700
It does not matter whether you select column from single table or multiple tables, the JOIN is performed always. So I would say the difference is negligible
Upvotes: 1