sql server - Do the order of JOINs make a difference? -


say have query 1 below:

select t1.id, t1.name table1 t1 --800,000 records inner join table2 t2 --500,000 records on t1.fkid = t2.id inner join table3 t3 -- 1,000 records on t1.otherid = t3.id 

would see performance improvement if changed order of joins on table2 , table3. see below:

select t1.id, t1.name table1 t1 --800,000 records inner join table3 t3 -- 1,000 records on t1.otherid = t3.id inner join table2 t2 --500,000 records on t1.fkid = t2.id 

i've heard query optimizer try determine best order doesn't work. version of sql server using make difference?

the order of joins makes no difference.

what make difference ensuring statistics date.

one way check statistics run query in ssms , include actual execution plan. if estimated number of rows different actual number of rows used part of execution plan, statistics out of date.

statistics rebuilt when related indexes rebuilt. if production maintenance window allows, update statistics every night.

this update statistics tables in database:

exec sp_msforeachtable "update statistics ?" 

Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -