且构网

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

mysql是否使用索引进行排序...

更新时间:2023-01-23 08:17:19

是的,当按排序列排序时,MySQL使用索引对信息进行排序.

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

合并索引和单独索引之间的区别是,每个查询MySQL不能使用超过一个的索引,因此,如果您的查询按许多列进行过滤,并且您希望正确地为其建立索引,则需要创建所有列的组合索引.

但是在向表中添加大量索引之前,请记住,每个索引都会使插入/更新/删除操作变慢.

我也强烈推荐O'Reilly撰写的 高性能MySQL 一书,该书将在深入探讨所有这些问题,以及需要知道要真正能够最大限度地使用MySQL的许多其他提示.

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?

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.