Does MySQL use index for sorting?

12,986

Yes, MySQL uses your index to sort the information when the order is by the sorted column.

Also, if you have indexes in all columns that you have added to the SELECT clause, MySQL will not load the data from the table itself, but from the index (which is faster).

The difference between combined and separate indexes is that MySQL can not use more than one index per query, so, if your query filters by many columns and you would like to have it correctly indexed you will need to create a combined index of all columns.

But before adding lots of indexes to your tables, remember that each index makes insert/update/delete operations go slower.

I would also highly recommend the High Performance MySQL book by O'Reilly that will cover in depth all of these issues and a lot of other hints you need to know to really be able to use MySQL to the limit.

Share:
12,986
Anush
Author by

Anush

Updated on June 13, 2022

Comments

  • Anush
    Anush almost 2 years

    Does a sort use a MySQL index if there is an index on the sorting column? Also what other things is the index used for?

    What difference does it make in a combined and separate indexes of the columns?

  • Kiran
    Kiran almost 7 years
    mysql optimizer merges different indexes if it speeds up the query and therefore MySQL can use multiple index for a single query, at least in latest versions.