INNER JOIN vs INNER JOIN (SELECT . FROM)

后端 未结 4 1764
栀梦
栀梦 2021-02-01 00:27

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 Sal         


        
4条回答
  •  花落未央
    2021-02-01 01:25

    Seems to be identical just in case that SQL server will not try to read data which is not required for the query, the optimizer is clever enough

    It can have sense when join on complex query (i.e which have joings, groupings etc itself) then, yes, it is better to specify required fields.

    But there is one more point. If the query is simple there is no difference but EVERY extra action even which is supposed to improve performance makes optimizer works harder and optimizer can fail to get the best plan in time and will run not optimal query. So extras select can be a such action which can even decrease performance

提交回复
热议问题