MySQL two storage engine

Commonly used storage engines are MyISAM and InnoDB storage engines.

The difference between MySQL storage engine MyISAM and InnoDB?

MyISAM Innodb
Storage structure Each table is stored in three files: frm-table definition, MYD (MYData)-data file, MYI (MYIndex)-index file All tables are stored in the same data file (may be multiple files, or independent table space files), the size of the InnoDB table is only limited by the size of the operating system file, generally 2GB
storage MyISAM can be compressed and the storage space is small InnoDB tables require more memory and storage, it will establish its dedicated buffer pool in main memory for high-speed buffering of data and indexes
Portability, backup and recovery Since MyISAM data is stored in the form of files, it will be very convenient in cross-platform data transfer. Operate on a table separately during backup and restore The free solution can be to copy data files, back up binlog, or use mysqldump, which is relatively painful when the amount of data reaches dozens of gigabytes.
file format Data and index are stored separately, data .MYD, index.MYI Data and indexes are stored centrally,.ibd
Record storage order Save in order of record insertion Insert in order by the size of the primary key
Foreign key not support stand by
Affairs not support stand by
Lock support (locks are a mechanism to avoid resource contention, MySQL locks are almost transparent to users) Table-level locking Row-level locking, table-level locking, small locking strength, high concurrency
SELECT MyISAM is better
INSERT、UPDATE、DELETE InnoDB is better
select count(*) Myisam is faster, because myisam maintains a counter internally, which can be called directly.
How the index is implemented B+ tree index, myisam is a heap table B+ tree index, Innodb is an index-organized table
Hash index not support stand by
Full-text index stand by not support

other:

  • InnoDB index is a clustered index, MyISAM index is a non-clustered index.
  • The leaf nodes of InnoDB's primary key index store row data, so the primary key index is very efficient.
  • The leaf node of the MyISAM index stores the row data address, which needs to be addressed again to get the data.
  • The leaf nodes of the InnoDB non-primary key index store the primary key and other indexed column data, so it is very efficient to cover the index when querying.

4 major features of InnoDB engine?

  • Insert buffer
  • Double write
  • Adaptive hash index (ahi)
  • 预读(read ahead)

Why is MyISAM faster than InnoDB when querying?

  1. When querying, since innodb supports transactions, there will be a comparison of mvvc. This process will lose performance.
  2. When querying, if you leave the index, because InnoDB is a clustered index, there will be a process of returning to the table, that is: first go to the non-clustered index tree to query the data, find the key corresponding to the data, and then return to the table through the key Cluster the index tree, and finally find the required data. Myisam is directly a clustered index. When querying, the final result is not the key of the clustered index tree, but the disk address, so it will directly query the disk. Detailed
  3. A loss of locks, InnoDB locks support row locks. When checking locks, not only table locks are checked, but also row locks.

How to choose the right storage engine?

If there is no special requirement, just use the default Innodb.

MyISAM: Applications that focus on reading and writing, such as blog systems and news portals.

Innodb: The update (delete) operation frequency is also high, or the integrity of the data must be guaranteed; the amount of concurrency is high, and transactions and foreign keys are supported. Such as OA automated office system.

Guess you like

Origin blog.csdn.net/weixin_44533129/article/details/112787995