MySQL index of B + Tree

MySQL index of B + Tree

1. Common index data structure

It is a schematic view from www.cs.usfca.edu generated

  • Hash (Hash)
    • schematic diagram
      Hash schematic
    • High efficiency, but because the characteristics of Hash algorithms, data disorderly range can not be searched
  • Binary search tree (Binary Search Tree)
    • schematic diagram
      Schematic binary search tree
    • Data orderly, able to find by range, but is likely to cause some data tilt, resulting in the slower part of the data query
  • Balanced binary search tree (Balanced Binary Search Tree, AVL Tree)
    • schematic diagram
      Schematic balanced binary search tree
    • It is an optimized version of the binary search tree, to solve the problem of data skew, but need to maintain a balanced tree overhead
  • B-tree (Tree B)
    • schematic diagram
      A schematic view of a B-tree
    • Each node can be stored a plurality of data, the number of child nodes may be larger than 2, to optimize the depth of the tree
  • B + trees (B + Tree)
    • schematic diagram
      B + tree schematic
    • Extra leaf nodes store a pointer to the adjacent leaf nodes to optimize the efficiency of the B-tree range queries and more stable

2. MySQL using the B + Tree

  • MySQL using B + Tree, the key points are as follows:
    • Maintain an index of non-leaf nodes, the control depth of the tree
    • Leaf nodes stored data, and a pointer to the leaf node adjacent
    • Data stored in the hard disk, you need to control the size of each piece of data to fit a hard page
  • Then each piece of data to be stored much of it?
    • MySQL is a multiple of the hard disk every data page size
      • System from the hard disk read operation is read by the page (e.g., 1024k, 2048k ......)
      • If MySQL size of each piece of data is smaller than the amount of hard disk page, then read each hard disk that could read some of the unnecessary data, affect performance
    • Through SHOW GLOBAL STATUS LIKE 'Innodb_page_size';to view each MySQL data size

3. MySQL in the two main engines index

  • MyISAM (non-clustered index)
    • Index and data stored separately
    • Primary Index (Primary Key): Found values ​​directly from the index
    • Secondary indexes (Secondary Key): Found values ​​directly from the index
  • InnoDB (clustered index)
    • Index and data stored together (must be an index, there will be built a default)
    • Primary Index (Primary Key): Found values ​​directly from the index
    • Secondary index (Secondary Key): used to find the primary key index, to find a value based on the master key
Published 128 original articles · won praise 45 · Views 150,000 +

Guess you like

Origin blog.csdn.net/alionsss/article/details/103767512
Recommended