SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


do Distinct, Group By, Order By & Union (without All)


do Distinct, Group By, Order By & Union (without All)

Author
Message
drew.georgopulos
drew.georgopulos
Mr or Mrs. 500
Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)

Group: General Forum Members
Points: 525 Visits: 705
all take the same hit on Sort?
Is there any way to mitigate that or conditions that make one cheaper than another forcing uniqueness?
thanks very much
drew
Bevan Keighley
Bevan Keighley
Old Hand
Old Hand (358 reputation)Old Hand (358 reputation)Old Hand (358 reputation)Old Hand (358 reputation)Old Hand (358 reputation)Old Hand (358 reputation)Old Hand (358 reputation)Old Hand (358 reputation)

Group: General Forum Members
Points: 358 Visits: 834
Hi,


This resource, Logical Query Processing , from Itzik Ben-Gan's book will help you understand what is going on behind the scenes.



But if you want to know for sure then run your particular scenario with the execution plan on and compare results.


Regards,
Bevan Keighley
suneet.mlvy
suneet.mlvy
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 70
drew.georgopulos (5/8/2013)
all take the same hit on Sort?
Is there any way to mitigate that or conditions that make one cheaper than another forcing uniqueness?
thanks very much
drew



I don't think there is any alternative(other than mentioned) way to get unique data.
drew.georgopulos
drew.georgopulos
Mr or Mrs. 500
Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)

Group: General Forum Members
Points: 525 Visits: 705
thanks very much...the execution plan is what informed me about where the query was so costly, but i was surprised to find that all the alternatives boiled down to 96% spent on Sort, (divided sometimes in different branches depending on where i put which operator(s)) but Sort was always the elephant in the room!
that was a great diagram, i learned that ages ago but never saw it so cleanly diagrammed, so thanks a lot for pointing it out.
drew
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16250 Visits: 19551
suneet.mlvy (5/9/2013)
drew.georgopulos (5/8/2013)
all take the same hit on Sort?
Is there any way to mitigate that or conditions that make one cheaper than another forcing uniqueness?
thanks very much
drew



I don't think there is any alternative(other than mentioned) way to get unique data.


It depends upon the shape of the data. If there are relatively few distinct values in the set, then Paul White's super-fast distinct, which uses seeks instead of sorts, can execute many times faster than native DISTINCT.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
drew.georgopulos
drew.georgopulos
Mr or Mrs. 500
Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)Mr or Mrs. 500 (525 reputation)

Group: General Forum Members
Points: 525 Visits: 705
Holy Good Night!
I never would have thought of that, and it is breathtaking!
Thanks so much for telling me about it, I really appreciate it.
drew
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search