March 10, 2011 at 6:08 am
Hi
I have 2 queries selecting from the same view. Both queries return the same amount of rows (317145).
The only difference between the 2 queries is that the first one uses DISTINCT.
So : (Query 1)
SELECT DISTINCT col1,col2,col3
FROM vw_myview
ORDER BY col1,col2,col3
(Query 2)
SELECT col1,col2,col3
FROM vw_myview
ORDER BY col1,col2,col3
When I run thr queries together with an execution plan, query 1's cost relative to the batch is 24% while query 2's cost relative to the batch is 76%. The execution plans are completely different. Query 1 runs in 5 seconds, Query 2 runs in 15 seconds.
My question is why is the DISTINCT query 1 so much faster than query 2 when they are returning the same results?
Thanks
Mike
March 10, 2011 at 6:13 am
You'll need to post both execution plans to be able to give you a hint on your Q.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply