Sorting on the server or on the client?

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 to the client. I on the other hand thinks that the server is probably busy enough as it is, and it must be better for performance to let the client handle the sorting after it has fetched the rows.

Anyone which strategy is best for the overall performance of a multi-user system?


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.

Need Your Help

Keeping track of time with 1 second accuracy in Google App Engine

google-app-engine time

I'm currently in the process of rewriting my java code to run it on Google App Engine. Since I cannot use Timer for programming timeouts (no thread creation allowed), I need to rely on system clock...

Creating file/image folder directory for Spring MVC and Maven WebApplication

java spring maven spring-mvc java-ee

I'm building a web app with Maven and Spring MVC.I've decided to save my images in a directory folder, not in database.I will save links of images to database. After searching I've found that saving

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.