且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL 是否使用索引进行排序?

更新时间:2023-01-23 08:09:16

是的,MySQL 使用您的索引在按已排序列的顺序对信息进行排序.

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

此外,如果您在添加到 SELECT 子句的所有列中都有索引,MySQL 将不会从表本身加载数据,而是从索引(速度更快)加载数据.

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).

组合索引和单独索引的区别在于,MySQL 不能在每个查询中使用多个一个 索引,因此,如果您的查询按许多列进行过滤,并且您希望将其正确编入索引需要创建所有列的组合索引.

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.

我还强烈推荐 O'Reilly 的高性能 MySQL 一书,该书将涵盖深入了解所有这些问题以及您需要知道的许多其他提示,以便真正能够最大限度地使用 MySQL.

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.