suppose we have a page in a site th开发者_开发百科at displays some records from a database.
we need to display the records sorted by some column.
which approach gives better performance: to retreive the data sorted from the database or to apply sorting on the grid ?
thanks
That depends on the amount of data you want to display. For few records which can be shown on one page and you are sure will remain fairly constant can be sorted on the UI side.
For large data, sorting at the database is better. If UI has pagination support, sorting at database side will avoid passing huge data to UI and UI discarding all rows except related to first page.
Sorting is one of the things that databases do best. Assuming you have an index on the column, you should let the database do it. And, if you don't have an index on it, it's not set up correctly.
I think any processing is better to be done on the database,as finally your application is an interface for your database,so just tune up your database and create the appropriate clustered and non-clustered indexes to make the sorting process faster
Sorting in database is much faster if needed indexes exists.
well if it's sorting then it should be done on the database. and if there is index for the required column then no second thoughts. for a few records it may be fine to do it on the UI
It depends that if you are sorting data frequently on different columns then better is to do it on application level because it will be faster rather then to fetch sorted data each time.
But if it is not the case and you have Index for that then do it on server side as it will be faster then to sort at application side.
精彩评论