Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 join speed help

Author  Topic 

alecwh22
Starting Member

15 Posts

Posted - 2013-02-14 : 04:53:22
i have this situation

select
*,
case when row_number() over (partition by t1.i orderby t2._date desc) = 1 then 1 else 0 end as isCurrent2,
case when row_number() over (partition by t1.i orderby t3._date desc) = 1 then 1 else 0 end as isCurrent3
from
t1
left outer joun t2 on t1.i = t2.i
left outer joun t3 on t1.i = t3.i
where
t1.thing = @thing
and
(
t2.blah = @blah
or t3.blah = @blah
)

the speed of this query is critical please can someone tell me if outer applying would be quicker and if you have any other tip or tricks.

All help very much appreciated

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-14 : 05:56:42
Outer apply may not outperform left joins, but couple of things I can suggest are:

1. Since you have columns t2 and t3 in the WHERE clause, it is effectively an inner join of the 3 tables. If that is not the intention, you should rewrite it to move the where clause on t2 and t3 to the joins, or you might as well specify inner joins.

2. Instead of SELECT *, explicitly list the columns you want to retrieve (and only the columns you need).
Go to Top of Page

Abu-Dina
Posting Yak Master

206 Posts

Posted - 2013-02-14 : 07:15:26
Provide execution plan details please.
Go to Top of Page
   

- Advertisement -