Understanding MySQL clustered indexes and how clustered indexes grow

Understanding MySQL clustered indexes and how clustered indexes grow

In this note, we briefly describe

  • What is the B+Tree index of MySQL?
  • How does the clustered index grow taller?

If you look at it bit by bit, it's actually quite easy to understand.

If you have read my previous notes, you must know that MySQL performs CRUD in memory, that is, in the Buffer Pool. Then you also know that when there is no data required by MySQL in the memory, MySQL will read the data from the disk into the memory through IO operations. The unit of reading is: data page

The general data page length is as follows

That’s right, real data is stored in the data pages, and the data pages are organized in the memory as a two-way linked table! As shown below

In the setting of B+Tree, it requires that the primary key index is incremented, that is to say, if the primary key index is incremented, then all the data in the data page on the right must be larger than the data in the data page on the left. But it is obvious that the above picture does not match, so it needs to be adjusted to the following by page splitting.

OK, now think back, you must have heard before: MySQL's B+Tree clustered index, only the leaf nodes store real data, and the non-leaf nodes store index data, and the leaf nodes are connected by a bidirectional linked list.

That’s right, all the leaf nodes of the B+Tree are the data pages in the above figure, and they are indeed linked by a doubly linked list!

Let's continue reading. If we only look at the doubly linked list connected by data pages in the above figure, what will happen if we retrieve the data row with id=7?

Obviously we have to start the scan from scratch!

Then you might ask: Didn’t we just say that B+Tree requires the primary key to be increasing? And there is a page split mechanism to ensure that all data in the data page on the right is larger than the index value of the data page on its left. Why not do a binary search?

Answer: Yes, it is indeed possible to perform binary search in a single data page, but the organizational relationship between data pages is a linked list, so traversal from the beginning is inevitable.

So what about MySQL?

As shown below: MySQL abstracts an index directory for many data pages

With this index directory, it will be much easier for us to search among many data pages! Directly have the ability of binary search!

And this directory actually exists in the data page. What is different from the leaf node is that it only stores index information, while the leaf node stores real data?

The birth of the index page also means that the prototype of B+Tree has been born!

As users continue to select, the number of data pages in the buffer pool increases, and the number of data in the index page will also increase. When the existing index size exceeds 16KB (the capacity of a data page), a new index page must be created to store the new index information. At this time, the B+Tree will slowly become fatter and fatter.

Then you also know that B+Tree is a variant of B-tree, and B-tree can actually be a general term for M-order trees such as 2-3 tree, 2-3-4 tree, etc. When the elements that can be stored in each node reaches the upper limit, the tree will grow taller (mentioned in the previous article).

Just like the following picture:

The above is the detailed content of MySQL clustered index and how clustered index grows, which can be understood at a glance. For more information about MySQL clustered index, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • MySQL learning tutorial clustered index
  • Detailed explanation of MySQL clustered index and non-clustered index
  • Example analysis of the page splitting principle of MySQL clustered index

<<:  Complete steps for deploying confluence with docker

>>:  Design reference WordPress website building success case

Recommend

Explanation of MySQL performance inspection through show processlist command

The show processlist command is very useful. Some...

Element-ui's built-in two remote search (fuzzy query) usage explanation

Problem Description There is a type of query call...

MYSQL slow query and log example explanation

1. Introduction By enabling the slow query log, M...

Linux system dual network card binding configuration implementation

System version [root@ ~]# cat /etc/redhat-release...

Detailed steps to build a file server in Windows Server 2012

The file server is one of the most commonly used ...

Idea deploys remote Docker and configures the file

1. Modify the Linux server docker configuration f...

JavaScript to achieve floor effect

This article shares the specific code of JavaScri...

Getting started with JavaScript basics

Table of contents 1. Where to write JavaScript 2....

Vue implements dynamic query rule generation component

1. Dynamic query rules The dynamic query rules ar...

MySQL 5.7.17 winx64 installation and configuration method graphic tutorial

Windows installation mysql-5.7.17-winx64.zip meth...

HTML line spacing setting methods and problems

To set the line spacing of <p></p>, us...

MySQL time types and modes details

Table of contents 1. MySQL time type 2. Check the...

Understand the use of CSS3's all attribute

1. Compatibility As shown below: The compatibilit...