Comparison of InnoDB and MyISAM storage engines

Comparison of InnoDB and MyISAM storage engines

Similar points: They are all B+ indexes. If you are not sure about the B+ index, you can read the previous article.

Indexes in InnoDB

Innodb structure is a clustered index, the index and data files are placed in one file

, including 2 types of indexes: primary key index (clustered index) and auxiliary index (non-clustered index) .

Primary key index : Each table has only one primary key index, b+ tree structure, the leaf nodes save the value of the primary key and the data record at the same time, and other nodes only store the value of the primary key.

Auxiliary index : Each table can have multiple b+ tree structures. The leaf nodes store the values ​​of the index fields and the values ​​of the primary keys. The other nodes only store the values ​​of the index tips.

Indexes in the MyISAM engine

B+ tree structure, MyISM uses non-clustered index

The index file and the data file are both separate files.

As shown below: In order to more vividly illustrate the difference between these two indexes, we assume that a table stores 4 rows of data. Among them, Id is used as the primary index and Name is used as the auxiliary index. The figure clearly shows the difference between clustered index and non-clustered index.

image-20230710154900118

Let’s take a look at the data retrieval process in the picture above.

InnoDB data retrieval process

If you need to query the data with id=14, you only need to search in the primary key index on the left.

If you need to search for data with name='Ellison', you need 2 steps:

  1. First retrieve the data with name='Ellison' in the auxiliary index and obtain the id of 14
  2. Then retrieve the record with id 14 in the primary key index

The query process of auxiliary index is called table return in mysql

MyISAM data retrieval process

  1. Find the corresponding keyword in the index and obtain the address of the record corresponding to the keyword
  2. Find the corresponding data record through the recorded address

The most common one we use is the innodb storage engine, so here we mainly talk about the innodb index. In innodb, it is best to use the primary key query, so that only one index is needed. If you use the auxiliary index retrieval, it involves a table return operation, which is better than the primary key query. The query takes some time.

Why does the auxiliary index in innodb not store the address of the record like myisam?

When the data in the table changes, it will affect the change of other record addresses. If the address of the data recorded in the auxiliary index is affected at this time, the value of the primary key is generally rarely updated. When the address of the record in the page occurs When changing, there is no impact on the auxiliary index.

Guess you like

Origin blog.csdn.net/itScholar001/article/details/131640990