Is a JOIN faster than a WHERE?

前端 未结 10 1058
渐次进展
渐次进展 2020-11-29 05:44

Suppose I have two tables that are linked (one has a foreign key to the other):

CREATE TABLE Document (
  Id INT PRIMARY KEY,
  Name VARCHAR 255
)

CREATE TAB         


        
10条回答
  •  醉酒成梦
    2020-11-29 06:23

    Performance of "JOIN" versus "WHERE"... everything hinges on how well the database engine is able to optimize the query for you. It will take into account any indexes you might have on the columns being returned and consider that performance of WHERE and JOIN clauses also come down to the physical database file itself and its fragmentation level and even the storage technology you use to store the database files on.

    SQL server executes queries in the following order (this should give you an idea of the functions of the WHERE and JOIN clauses)

    Microsoft SQL Server query process order

    the following is taken from the excellent series of books about Microsoft SQL Server, Inside Microsoft SQL Server 2005: T-SQL Querying which can be found here

    (Step 8) SELECT (Step 9) DISTINCT (Step 11)
    (Step 1) FROM left_table
    (Step 3) join_type JOIN right_table
    (Step 2) ON join_condition
    (Step 4) WHERE where_condition
    (Step 5) GROUP BY group_by_list
    (Step 6) WITH [CUBE|ROLLUP]
    (Step 7) HAVING having_clause
    (Step 10) ORDER BY order_by_list

提交回复
热议问题