mysqlMySQL学习MySQL

Mysql Documentation 阅读笔记: 索引原理

2017-01-04  本文已影响29人  JennyGump

MYSQL优化: How MySQL Uses Indexes

Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. This is much faster than reading every row sequentially.

索引是为了更快的搜索指定的列;没有索引的搜索会搜索整张表;

Most MySQL indexes (PRIMARY KEY, UNIQUE, INDEX, and FULLTEXT) are stored in B-trees.

大部分索引都以B树的方式存储,B树的优点:搜索树、Log n 的时间复杂度。具体B树在Mysql存储中的应用待深入研究。

MySQL uses indexes for these operations:

If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to look up rows. For example, if you have a three-column index on (col1, col2, col3), you have indexed search capabilities on (col1), (col1, col2), and (col1, col2, col3).

To retrieve rows from other tables when performing joins. MySQL can use indexes on columns more efficiently if they are declared as the same type and size.

# age 列如果已添加索引,会依照上述流程执行
SELECT MIN(age), MAX(age) FROM students WHERE gender = 'male';
上一篇下一篇

猜你喜欢

热点阅读