Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

how to reduce sort on order by? Expand / Collapse
Posted Sunday, March 24, 2013 9:24 PM


Group: General Forum Members
Last Login: Friday, November 18, 2016 9:50 AM
Points: 1,525, Visits: 3,573
I have a query where sort is done at the end on different columns from 3 different databases. I see that in the execution plan most of the cost is around the sort , if all these columns were in one db i could have added as part of index but how this work when sort is done on multiple columns from different dbs? Sample code is below

GROUP  BY Db1.UserName,

Post #1434737
Posted Monday, March 25, 2013 1:14 AM



Group: General Forum Members
Last Login: Saturday, December 3, 2016 5:18 AM
Points: 45,619, Visits: 44,147
I think there's something missing from your sample code.

In short, you can't really reduce the cost, sorts are expensive operations, if you need a sorted resultset, you have to accept the cost of sorting. With adequate memory and optimised TempDB, you may be able to reduce the time required to do the sort though.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1434770
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse