Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

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

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, December 16, 2014 9:01 AM
Points: 1,299, Visits: 3,003
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,
Db1.Email,
Db2.LocationID,
Db3.[Name]

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


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 8:36 AM
Points: 40,615, Visits: 37,080
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 2008, MVP
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