Sorting on the server or on the client?

前端 未结 10 674
一生所求
一生所求 2020-12-04 22:31

I had a discussion with a colleague at work, it was about SQL queries and sorting. He has the opinion that you should let the server do any sorting before returning the rows

10条回答
  •  天涯浪人
    2020-12-04 22:57

    I am in favor of Roberts answer, but I wanted to add a bit to it.

    I also favor the sorting of data in SQL Server, I have worked on many systems that have tried to do it on the client side and in almost every case we have had to re-write the process to have it done inside SQL Server. Why is this you might ask? Well we have two primary reasons.

    1. The amount of data being sorted
    2. The need to implement proper paging due to #1

    We deal with interfaces that show users very large sets of data, and leveraging the power of SQL Server to handle sorting and paging is by far better performing than doing it client side.

    To put some numbers to this, a SQL Server Side sort to a client side sort in our environment, no paging for either. Client side 28 seconds using XML for sorting, and Server side sort total load time 3 seconds.

提交回复
热议问题