I have added indexes to table which are used for searching result. I am showing results by ASC or DESC order. So that column should have index or not? I have 2 more indexes on that table. How performance will affect by making or not making index to that column?
MySQL Performance – Should Order By Column Have an Index?
indexMySQLorder-byperformance
Related Question
- Mysql – same field in bothe “where” and “order by” – how to index for this query
- MySQL – Using Index for Both ASC and DESC on String Column
- MySQL Indexes – How to Manage Too Many Indexes
- SQL Server – Aligned Index Column Order
- Effect of Index on Update Statements in SQL Server
- Postgresql – How to speed up an ASC sort on a column that only holds an integer between 0 and 9 across multiple millions of rows
- MySQL Query Performance – Using Index with ORDER BY
Best Answer
Yes, MySQL can use an index on the columns in the ORDER BY (under certain conditions). However, MySQL cannot use an index for mixed ASC,DESC order by (
SELECT * FROM foo ORDER BY bar ASC, pants DESC
). Sharing your query and CREATE TABLE statement would help us answer your question more specifically.For hints on how to optimize ORDER BY clauses: http://dev.mysql.com/doc/refman/5.1/en/order-by-optimization.html
Edit 2012-01-21 8:53AM
There were questions about the source of my statement about using an index with mixed ASC/DESC in the ORDER BY. From the ORDER BY Optimization documentation:
Also, the DESC keyword is meaningless in CREATE INDEX