开发者

Does MySQL use index for sorting?

开发者 https://www.devze.com 2023-03-23 18:25 出处:网络
Does a sort use a MySQL index if there is an index on the sorting 开发者_Go百科column? Also what other things is the index used for?

Does a sort use a MySQL index if there is an index on the sorting 开发者_Go百科column? Also what other things is the index used for?

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消