how to reduce sort on order by?

  • 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]

  • 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

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply