Sorting on the server or on the client?

前端 未结 10 644
一生所求
一生所求 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 23:07

    In general, you should let the database do the sorting; if it doesn't have the resources to handle this effectively, you need to upgrade your database server.

    First off, the database may already have indexes on the fields you want so it may be trivial for it to retrieve data in sorted order. Secondly, the client can't sort the results until it has all of them; if the server sorts the results, you can process them one row at a time, already sorted. Lastly, the database is probably more powerful than the client machine and can probably perform the sorting more efficiently.

提交回复
热议问题