Optimizing SELECT statements, performance – MySQL How to speed up sorting query, MySQL tips to increase sorting query, MySQL – How to speed up sorting queries on a large record list, MySQL sort by ID field instead of date field.
For improve query execution speed use sort by ID instead of date create. For example when we need sort record based on time period we using date_create or date related field in MySQL query.
Generally in table design good practice we always create ID field in table with auto increment option. So when new record insert in table, ID increase in same way as like date_create field, means new value always greater than previous one. Now if we sort table entries by ID or date_create, query gives same result.
Points that make sort by ID faster:
#1: ID is numeric field #2: ID is primary key and have Index
MySql query example:
//sort record by date field SELECT * FROM table_name WHERE 1=1 ORDER BY date_create DESC //sort record by ID field SELECT * FROM table_name WHERE 1=1 ORDER BY ID DESC
If table have large number of rows, this technique gives better result compare to sort by date value field.