SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 join speed help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

alecwh22
Starting Member

United Kingdom
15 Posts

Posted - 02/14/2013 :  04:53:22  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3742 Posts

Posted - 02/14/2013 :  05:56:42  Show Profile  Reply with Quote
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

United Kingdom
206 Posts

Posted - 02/14/2013 :  07:15:26  Show Profile  Reply with Quote
Provide execution plan details please.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000