|
I have been given the following slow performing query which is taking a cut from 1.2 million rows to return about 51,000. It is taking about 56 seconds which is slow for a webpage.
Can I write the JOIN in a different way to speed things up or should I be looking at indexes and so on for the tables? Also I am surprised that sort of join still exists and still runs on SQL Server!
(comments are locked)
|
|
As long as it's an inner join it will work in 2008. The ANSI 89 outer join syntax is deprecated. Based on the tags you're running in this in '05, so it'll work. As to whether or not changing the syntax will speed it up, it's hard to know without seeing the execution plans for the query. But, in general, I shy away from joining views to views where I can. SQL Server can do a very good job of resolving the view for a given query, but, depending on the view and the query, it might not bother to resolve the view at all and will merely run it as written, whether or not you're referencing all the tables & columns in the view or not. Clearly, that can lead to huge performance problems. +1 Marked as the answer because of course I should carry on diving through the views to get at the base query. Thanks for the information on joins it would appear that it works akin to a cross join in nature.
Feb 24 '10 at 10:31 AM
Ian Roke
(comments are locked)
|
|
Just out of interest here is the query plan. I have managed to get it down to 17 seconds now. Clearly, you want to find a way around that clustered scan.
Feb 24 '10 at 11:38 AM
Grant Fritchey ♦♦
That's what I thought. Thanks for the confirmation Grant.
Feb 24 '10 at 12:01 PM
Ian Roke
(comments are locked)
|
|
Ian... I see no join criteria between the two tables. What you have there is a full blown cross-join. There has to be something that both tables can relate to so you can join them without them being a cross-join. Agreed. The reason is because I am trying to select records where the OM_Available date is between two dates in the vwWeeklyRanges2Only table. I suppose it would be much quicker if I used a subquery instead? I think I might try that for comparison.
Feb 25 '10 at 04:52 AM
Ian Roke
Subquery or not, unless you have something to join on between the two views, you have a time consuming cross join. I also agree with Grant... joing two views together isn't usually a form of computational Nirana.
Mar 07 '10 at 12:38 AM
Jeff Moden
(comments are locked)
|

