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
Author
Message
Posted Sunday, March 24, 2013 9:24 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, September 14, 2016 12:36 PM
Points: 1,516, Visits: 3,556
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: Today @ 4:02 AM
Points: 45,302, Visits: 43,527
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