MySQL索引工作原理和管理

发布时间:2023年12月25日

索引概述

MYSQL官方对索引的解释How MySQL Uses Indexes

MySQL官方对索引的解释为:索引用于快速查找具有特定列值的行。

8.3.1 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.
  MySQL官方对索引的定义:索引(Index)是帮助MySQL高效获取数据的数据结构。
  索引:是经过了排序的可以快速查找的特殊数据结构,定义在作为查找条件的字段上,索引通过存储引擎实现。

索引优缺点

优点:
  1.索引可以降低检索时需要扫描的数据量,减少了IO次数。(字典通过偏旁部首或拼音可以直接翻到对应字的页数)
  2.索引可以避免服务器排序和使用零时表。
  3.索引可以帮助随机IO转为顺序IO.

缺点:
  1.索引占用额外的磁盘空间,每个所以都还占据一定的物理空间。
  2.索引有创建和维护成本,随着数据量的增加,索引需要投入的成本也就越高。
  3.索引影响数据的插入和修改速度。
  
  (试想,新华大字典的检字表里突然需要增加一个7画的字,那7画的这个字就得插入到6画和8画的字的中间,7画字的详情页数占用了原来8画字的页数,所以8画以后得字,9画,10画,11画...等等的字的页数都得往后挪一挪,这就是一个巨大索引维护成本)

索引结构

参考链接:https://www.cs.usfca.edu/~galles/visualization/StackArray.html

二叉树参考链接:https://www.cs.usfca.edu/~galles/visualization/StackArray.html

文章来源:https://blog.csdn.net/flytalei/article/details/135210415
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。