是否使用索引进行排序

是否使用索引进行排序

本文介绍了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?

推荐答案

是的,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.

这篇关于MySQL 是否使用索引进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:47