Search code examples
mysqlsqlperformanceindexingsql-order-by

Order by column should have index or not?


I am adding indexes to table with millions of records which is used for searching results. I am showing results in ASC or DESC order. My question is should that column have an index or not? I have 2 more indexes on that table. How will performance be affected by adding or not adding an index to that column?


Solution

  • Order by columns are used for ordering the result set, not filtering. An index on the columns mentioned in the order by clause is unlikely to change anything, especially if it's not used to filter the data.