Technology Sharing

MySQL Performance Tuning 01-[Data Structure and Index]

2024-07-11

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

What is an index

insert image description here

Types of Indexes

在Mysql中索引是在存储引擎层实现的,而不是在服务层实现的

  • According to data structure: B tree index, Hash index, Full-text index
  • According to the storage structure: clustered index, non-clustered index
  • According to field characteristics: primary key index, unique index, common index, full-text index
  • By number of fields: singleton index, joint index

Common index data structures and differences

  • Binary tree, red-black tree, B-tree, B-number
  • Difference: The height of the tree affects the performance of obtaining data (each tree node is a disk IO)

Binary Tree

Features:Each node has at most two child nodes, the left one is small and the right one is large.The more random the data, the more obvious the branches are.

Set the id of the following table as the index
就是将id列按照二叉树的数据结构存储起来
insert image description here
If the data is entered sequentially at once
The height of the tree will be very high (it is a linked list structure). At this time, the efficiency of element search is equal to linked list query O(n), and the data retrieval efficiency will be extremely low.
insert image description here

Red-Black Tree