Article Directory
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
- High efficiency, but because the characteristics of Hash algorithms, data disorderly range can not be searched
- schematic diagram
- Binary search tree (Binary Search Tree)
- schematic diagram
- Data orderly, able to find by range, but is likely to cause some data tilt, resulting in the slower part of the data query
- schematic diagram
- Balanced binary search tree (Balanced Binary Search Tree, AVL Tree)
- schematic diagram
- 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
- schematic diagram
- B-tree (Tree B)
- schematic diagram
- 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
- schematic diagram
- B + trees (B + Tree)
- schematic diagram
- Extra leaf nodes store a pointer to the adjacent leaf nodes to optimize the efficiency of the B-tree range queries and more stable
- schematic diagram
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
- MySQL is a multiple of the hard disk every data page 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