MySQL database - storage engine (2) - storage engine features (InnoDB, MyISAM, Memory), storage engine selection

Table of contents

Storage engine features

InnoDB

introduce

Features

document

logical storage structure

MyISAM

introduce

Features

document

Memory

introduce

Features

document

Differences and features

Storage engine selection


Storage engine features

Above we introduced what a storage engine is and how to specify a storage engine when creating a table. Next, we will introduce the characteristics of the three more important storage engines: InnoDB , MyISAM, and Memory

InnoDB

introduce

InnoDB is a general-purpose storage engine that combines high reliability and high performance. After MySQL 5.5, InnoDB is the default MySQL storage engine.

Features

  • DML (add, delete, and modify data records in tables in the database) operations follow the ACID ( Atomicity, Consistency, Isolation, and Durability) model and support transactions;
  • Row-level locks to improve concurrent access performance;
  • Support foreign key FOREIGN KEY constraints to ensure data integrity and correctness;

document

xxx.ibd

xxx represents the table name. Each table in the innoDB engine will correspond to such a table space file, which stores the table structure (frm-early, sdi-new version), data and indexes of the table.

The table structure file frm, after MySQL 8.0, the table structure is stored in the data point sdi, and sdi is integrated into the InnoDB table space file.

Parameter: innodb_file_per_table (if this parameter is turned on, each table will have a corresponding table space file)

Query system parameter settings:

show variables like 'innodb_file_per_table';

logical storage structure

  • Table space: The highest level of the logical structure of the InnoDB storage engine. The ibd file is actually a table space file. The table space can contain multiple Segment segments.
  • Segment: The table space is composed of various segments. Common segments include data segment, index segment, rollback segment, etc. The management of segments in InnoDB is done by the engine itself and does not require human control. A segment contains multiple areas.
  • Area: The area is the unit structure of the table space, and the size of each area is 1M. By default, the InnoDB storage engine page size is 16K, that is, there are 64 consecutive pages in one area.
  • Page: Page is the smallest unit that makes up an area. Page is also the smallest unit of disk management by InnoDB storage engine. The default size of each page is 16KB. In order to ensure page continuity, the InnoDB storage engine applies for 4-5 areas from the disk each time.
  • Row: The InnoDB storage engine is row-oriented, which means that data is stored in rows. In addition to the fields specified when defining the table, each row also contains two hidden fields (will be introduced in detail later). 

The size of the area and page are fixed. Among them, Trx id represents the ID of the last operation transaction, Roll pointer is some pointers, and col is the corresponding field in the table.

MyISAM

introduce

MyISAM was the early default storage engine for MySQL.

Features

  • Does not support transactions, does not support foreign keys
  • Supports table locks, but does not support row locks
  • Fast access

document

  • xxx.sdi: stores table structure information
  • xxx.MYD: store data
  • xxx.MYI: storage index

Memory

introduce

The table data of the Memory engine is stored in the memory. Due to hardware problems or power outages, these tables can only be used as temporary tables or caches.

Features

  • memory storage
  • hash index (default)

document

xxx.sdi: stores table structure information

Differences and features

Features InnoDB MyISAM Memory
storage limit 64TB have have
transaction security support - -
lock mechanism row lock table lock table lock
B+tree index support support support
Hash index - - support
Full text index Supported (after version 5.6) support -
space usage high Low N/A
memory usage high Low medium
Batch insert speed Low high high
Support foreign keys support - -

Interview questions

What is the difference between InnoDB engine and MyISAM engine?

  1. The InnoDB engine supports transactions, but MyISAM does not.
  2. The InnoDB engine supports row locks and table locks, while MyISAM only supports table locks and does not support row locks.
  3. The InnoDB engine supports foreign keys, but MyISAM does not support it.

The main differences are the above three points. You can also give a more in-depth answer in terms of index structure, storage restrictions, etc. For details, please refer to the following official documents: https://dev.mysql.com/doc/refman/8.0/en/innodb-introduction .html

https://dev.mysql.com/doc/refman/8.0/en/myisam-storage-engine.html

 

Storage engine selection

When selecting a storage engine, you should choose an appropriate storage engine based on the characteristics of the application system. For complex application systems, multiple storage engines can be selected and combined according to actual conditions.

  • InnoDB : It is the default storage engine of Mysql and supports transactions and foreign keys. If the application has relatively high requirements for transaction integrity and requires data consistency under concurrent conditions, and data operations include many update and delete operations in addition to insertion and query, then the InnoDB storage engine is a more suitable choice. .
  • MyISAM: If the application is mainly based on read operations and insert operations, with only a few update and delete operations, and the requirements for transaction integrity and concurrency are not very high, then choosing this storage engine is very suitable. (Can be replaced by NoSQL database MongoDB )
  • MEMORY: Saves all data in memory with fast access speed. It is usually used for temporary tables and caches. The disadvantage of MEMORY is that there is a limit on the size of the table. Tables that are too large cannot be cached in memory, and data security cannot be guaranteed. (Can be replaced by NoSQL database Redis )

END


Learn from: Dark Horse Programmer - MySQL Database Course

Guess you like

Origin blog.csdn.net/li13437542099/article/details/132703021