MySql InnoDB vs MyISAM Index Comparison

InnoDB engine clustered index

InnoDB Clustered Index

The InnoDB clustered index actually stores the B-Tree index and data rows in the agreed structure. In fact, the B-Tree here is a kind of B+Tree. Read the relevant information about B and B+Tree by yourself.

The so-called clustered index means that the primary key and data rows are stored together, which improves the density of the data. However, because the clustered index has already stored the data rows, only one clustered index can be used for a table.

The indexed column is the primary key. If the primary key is not selected, InnoDB will select a unique non-null index instead.

advantage:

1. Relevant data can be stored together. For example, user emails use ID as a clustered index, and after a few IOs, you can get emails related to the ID.

2. High efficiency and stability

3. Use the covering index scan query to directly use the primary key value in the leaf node

shortcoming:

1. If all data is stored in memory, the access order becomes less important, and the advantages of clustered indexes are not obvious.

2. Inserting and updating irregular data may lead to frequent index reconstruction, that is, page splitting, which will lead to performance degradation when inserting or updating

3. When the data is not too dense or discontinuous, it will cause the traversal speed to decrease.

4. It has a certain impact on the performance of the secondary index, because what is stored in the secondary index is not the actual address of the data row, but the primary key value of the row, so you need to hold the primary key value to search again, InnoDB adaptive Hash indexes can reduce the impact of this problem

 

Index comparison between MyISAM and InnoDB when storing data

InnoDB:

 

pk: primary key, rb pointer: rollback pointer, tx id: transaction id, npk: remaining non-primary key columns

In fact, it can be seen that the InnoDB clustered index is basically equivalent to the table that actually stores the data

By the way, the secondary index of InnoDB, that is, the non-clustered index, the main difference is that the primary key of the data row is stored in the part of the leaf node, not the actual physical address of the data row

 

MyISAM:

MyISAM builds indexes separately for all columns, each column has an independent index, data rows are stored independently, and each leaf node of a non-clustered index points to a certain unit of a data row, for example:

Suppose the data row is structured like this:

Index on column A:

This index and the index of column B form the index of the entire table. The primary key index is no different from the secondary index.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325672035&siteId=291194637