[MySQL] MySQL Inside: in-depth understanding of InnoDB and MyISAM storage engine

introduction

MySQL storage engine has a lot of, including InnoDB, MyISAM, FEDERATED, MEMORY, CSV, etc., but is commonly used in the first two, before the default MySQL storage engine version 5.1 is MyISAM, after the default is InnoDB, then the two What are the differences underlying storage engine, have any effect on the performance of it? This article deals with you in-depth understanding of these.

1. InnoDB

InnoDB 引擎提供了对数据库ACID事务的支持,并且实现了SQL标准的四种隔离级别。The engine also provides row-level locking, and foreign key constraint, it is designed to handle high-capacity database system, which itself is actually a complete database system based on MySQL backend, MySQL runtime Innodb will create a buffer pool in memory for buffering data and indexes. But the engine does not support FULLTEXT index type, and it does not hold the number of rows in the table, when SELECT COUNT (*) FROM TABLE when the need to scan the entire table. 当需要使用数据库事务时,该引擎当然是首选。由于锁的粒度更小,写操作不会锁定全表,所以在并发较高时,使用Innodb引擎会提升效率。However, row-level locking is not absolute, if MySQL can not determine the range to be scanned in the implementation of a SQL statement, InnoDB table will also lock the whole table.

2. MyISAM

MyISAM does not provide support for database transactions, does not support row-level locking, and foreign keys, so when INSERT (insert) or UPDATE (update) data-write operations need to lock the entire table, the efficiency will be lower. However, InnoDB and different, MyISAM中存储了表的行数,于是SELECT COUNT(*) FROM TABLE时只需要直接读取已经保存好的值而不需要进行全表扫描。if the table read much more than write and does not require database transaction support, then the MyISAM is a good choice.

Difference 3. InnoDB and MyISAM storage engine

3.1 Summary of differences between two storage engine

1, InnoDB supports transactions, while MyISAM does not support transactions.

2, InnoDB supports row-level locks, and the lock granularity is MyISAM table level.

3, InnoDB does not support full-text indexing FULLTEXT, and MyISAM support.

4, the specific number of lines does not save the table InnoDB, the implementation of select count (*) when from table, InnoDB to scan the whole table to calculate how many rows, but MyISAM save a specific number of rows in the table, simply read out save a good number of rows can be.
5, InnoDB clustered index, while the non-clustered index MyISAM.

3.2 clustered index and non-clustered indexes principle

From the above comparison, InnoDB using 聚簇索引the MyISAM is 非聚簇索引, in fact, both the non-clustered index or clustered index are used in the B + tree structure. B + tree structure as shown:
Here Insert Picture Description
InnoDB使用的是聚簇索引,将主键组织到一棵B+树中,而行数据就储存在叶子节点上。If you use "WHERE id = 14" primary key to find such conditions, the search algorithm in accordance with the B + tree to find the corresponding leaf node, the data obtained after row. If the conditional search of the name column, requires two steps: first retrieving the auxiliary name B + tree index, which reach the leaf node corresponding to the acquired primary key. The second step uses the primary key in the primary B + tree index perform another B + tree retrieval operation, to obtain the final leaf node entire row of data.
MyISAM的是非聚簇索引,B+Tree的叶子节点上的data,并不是数据本身,而是数据存放的地址。Non-clustered index, the primary key index and a secondary index biggest difference is that the primary key index key obtained must be unique. Non-clustered index of two B + tree looks no different from the structure node exactly the same, but the stored content is different, the node the primary key index B + tree to store the primary key, secondary key index B + tree to store the secondary keys. Table data is stored in a separate place, these two B + tree leaf nodes are using a real address points table data for the table data, these two keys there is no difference. Because the index is independent of the tree, retrieved without accessing the primary key index tree through the auxiliary key. FIG lookup process is as follows:
Here Insert Picture Description

4. Summary

InnoDB is suitable for transaction processing, with features such as ACID transaction support, if you do a lot of INSERT and UPDATE operations in the application, should choose InnoDB, if more SELECT operation, you should consider MyISAM.

Published 27 original articles · won praise 12 · views 30000 +

Guess you like

Origin blog.csdn.net/Carson_Chu/article/details/104074966