Home Database Mysql Tutorial What are the differences between mysql storage engines?

What are the differences between mysql storage engines?

May 06, 2019 am 11:33 AM
innodb myisam

The difference between storage engines in MySQL: Taking Innodb and myisam as an example, the former supports transactions but the latter does not; the former emphasizes versatility and supports more extended functions, while the latter mainly focuses on performance; the former does not support full-text indexing , and the latter supports full-text indexing, etc.

What are the differences between mysql storage engines?

mysql supports several storage engines. Here we mainly discuss several commonly used storage engines. Innodb, myisam

INNODB

INNODB index implementation

The same thing as MyISAM is that InnoDB also uses B Tree. A data structure to implement B-Tree index. The big difference is that the InnoDB storage engine uses the "clustered index" data storage method to implement the B-Tree index. The so-called "aggregation" means that the data rows and adjacent key values ​​​​are compactly stored together. Note that InnoDB can only The records of a leaf page (16K) are aggregated (that is, the clustered index satisfies a certain range of records), so records containing adjacent key values ​​​​may be far apart.

In InnoDB, the table is called an index organized table. InnoDB constructs a B Tree according to the primary key (if there is no primary key, a unique and non-empty index will be selected instead. If there is no primary key, a unique and non-empty index will be selected instead. For such an index, InnoDB will implicitly define a primary key as a clustered index), and at the same time, the leaf pages store the row record data of the entire table. The leaf nodes of the clustered index can also be called data pages. Non-leaf pages can be viewed Do a sparse index of leaf pages.

The following figure illustrates the implementation of InnoDB clustered index, and also reflects the structure of an innoDB table. It can be seen that in InnoDB, the primary key index and data are integrated and not separated.

What are the differences between mysql storage engines?

#This implementation method gives InnoDB ultra-high performance in retrieval by primary key. You can choose a clustered index purposefully, for example, in a mail table, you can choose user ID to aggregate data. In this way, you only need to read a small number of consecutive data pages from the disk to obtain all the mails of a user with a certain ID, avoiding the need for Random I/O spent reading scattered pages.

InnoDB is an I/O operation. Innodb reads and writes using MVCC to support high concurrency.

Full table scan

When InnoDB does a full table scan, it is not efficient because InnoDB does not actually read sequentially. In most cases, it reads randomly. Pick. When doing a full table scan, InnoDB scans pages and rows in primary key order. This applies to all InnoDB tables, including fragmented tables. If the primary key page table (the page table that stores primary keys and rows) is not fragmented, a full table scan is quite fast because the read order is close to the physical storage order. But when the primary key page is fragmented, the scan will become very slow

Row-level lock

Provides row locking (locking on row level), provided with Oracle Type-consistent non-locking read in SELECTs. In addition, the row lock of the InnoDB table is not absolute. If MySQL cannot determine the range to be scanned when executing a SQL statement, the InnoDB table will also lock the entire table. Tables, such as

update table set num=1 where name like “%aaa%”
Copy after login

MYISAM

MyISAM index implementation

Each MyISAM is stored as three files on disk . The name of the first file begins with the name of the table, and the extension indicates the file type. The MyISAM index file [.MYI (MYIndex)] and the data file [.MYD (MYData)] are separated. The index file only saves the pointer (physical location) of the page where the record is located. The page is read through these addresses, and then the page is read. The indexed row. Let’s take a look at the structure diagram first

What are the differences between mysql storage engines?

#The above picture illustrates well that the leaves in the tree save the physical location of the corresponding row. Through this value, the storage engine can smoothly query the table and obtain a complete row of records. At the same time, each leaf page also saves a pointer to the next leaf page. This facilitates range traversal of leaf nodes. As for the secondary index, it is implemented in the MyISAM storage engine in the same way as the above figure. This also shows that MyISAM's indexing method is "non-clustered", which is in contrast to Innodb's "clustered index"

MyISAM will read the index into memory by default and operate directly in memory;

Table-level lock

Summary: Innodb emphasizes versatility and compares the supported expansion functions Many, myisam mainly focuses on performance

Difference

1. InnoDB supports transactions, MyISAM does not support it. For InnoDB, every SQL language is encapsulated into a transaction by default and automatically submitted. , this will affect the speed, so it is best to put multiple SQL statements between begin and commit to form a transaction;

2. InnoDB is a clustered index, and the data file is tied to the index and must be There must be a primary key, and indexing through the primary key is very efficient. However, the auxiliary index requires two queries, first to query the primary key, and then to query the data through the primary key. Therefore, the primary key should not be too large, because if the primary key is too large, other indexes will also be large. MyISAM is a non-clustered index, the data files are separated, and the index saves the pointer of the data file. Primary key indexes and secondary indexes are independent.

3. InnoDB does not save the specific number of rows in the table. When executing select count(*) from table, a full table scan is required. MyISAM uses a variable to save the number of rows in the entire table. When executing the above statement, you only need to read the variable, which is very fast;

4. Innodb does not support full-text index, while MyISAM supports full-text index. In terms of query efficiency, MyISAM is higher;

The above is the detailed content of What are the differences between mysql storage engines?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

what is mysql innodb what is mysql innodb Apr 14, 2023 am 10:19 AM

InnoDB is one of the database engines of MySQL. It is now the default storage engine of MySQL and one of the standards for binary releases by MySQL AB. InnoDB adopts a dual-track authorization system, one is GPL authorization and the other is proprietary software authorization. InnoDB is the preferred engine for transactional databases and supports transaction security tables (ACID); InnoDB supports row-level locks, which can support concurrency to the greatest extent. Row-level locks are implemented by the storage engine layer.

How MySQL sees InnoDB row format from binary content How MySQL sees InnoDB row format from binary content Jun 03, 2023 am 09:55 AM

InnoDB is a storage engine that stores data in tables on disk, so our data will still exist even after shutdown and restart. The actual process of processing data occurs in memory, so the data in the disk needs to be loaded into the memory. If it is processing a write or modification request, the contents in the memory also need to be refreshed to the disk. And we know that the speed of reading and writing to disk is very slow, which is several orders of magnitude different from reading and writing in memory. So when we want to get certain records from the table, does the InnoDB storage engine need to read the records from the disk one by one? The method adopted by InnoDB is to divide the data into several pages, and use pages as the basic unit of interaction between disk and memory. The size of a page in InnoDB is generally 16

How to handle mysql innodb exception How to handle mysql innodb exception Apr 17, 2023 pm 09:01 PM

1. Roll back and reinstall mysql. In order to avoid the trouble of importing this data from other places, first make a backup of the database file of the current library (/var/lib/mysql/location). Next, I uninstalled the Perconaserver 5.7 package, reinstalled the original 5.1.71 package, started the mysql service, and it prompted Unknown/unsupportedtabletype:innodb and could not start normally. 11050912:04:27InnoDB:Initializingbufferpool,size=384.0M11050912:04:27InnoDB:Complete

How to solve phantom reading in innoDB in Mysql How to solve phantom reading in innoDB in Mysql May 27, 2023 pm 03:34 PM

1. Mysql transaction isolation level These four isolation levels, when there are multiple transaction concurrency conflicts, some problems of dirty reading, non-repeatable reading, and phantom reading may occur, and innoDB solves them in the repeatable read isolation level mode. A problem of phantom reading, 2. What is phantom reading? Phantom reading means that in the same transaction, the results obtained when querying the same range twice before and after are inconsistent as shown in the figure. In the first transaction, we execute a range query. At this time, there is only one piece of data that meets the conditions. In the second transaction, it inserts a row of data and submits it. When the first transaction queries again, the result obtained is one more than the result of the first query. Data, note that the first and second queries of the first transaction are both in the same

MySQL storage engine selection comparison: InnoDB, MyISAM and Memory performance index evaluation MySQL storage engine selection comparison: InnoDB, MyISAM and Memory performance index evaluation Jul 26, 2023 am 11:25 AM

MySQL storage engine selection comparison: InnoDB, MyISAM and Memory performance index evaluation Introduction: In the MySQL database, the choice of storage engine plays a vital role in system performance and data integrity. MySQL provides a variety of storage engines, the most commonly used engines include InnoDB, MyISAM and Memory. This article will evaluate the performance indicators of these three storage engines and compare them through code examples. 1. InnoDB engine InnoDB is My

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

How to use MyISAM and InnoDB storage engines to optimize MySQL performance How to use MyISAM and InnoDB storage engines to optimize MySQL performance May 11, 2023 pm 06:51 PM

MySQL is a widely used database management system, and different storage engines have different impacts on database performance. MyISAM and InnoDB are the two most commonly used storage engines in MySQL. They have different characteristics and improper use may affect the performance of the database. This article will introduce how to use these two storage engines to optimize MySQL performance. 1. MyISAM storage engine MyISAM is the most commonly used storage engine for MySQL. Its advantages are fast speed and small storage space. MyISA

Tips and Strategies to Improve MySQL Storage Engine Read Performance: Comparative Analysis of MyISAM and InnoDB Tips and Strategies to Improve MySQL Storage Engine Read Performance: Comparative Analysis of MyISAM and InnoDB Jul 26, 2023 am 10:01 AM

Tips and strategies to improve the read performance of MySQL storage engine: Comparative analysis of MyISAM and InnoDB Introduction: MySQL is one of the most commonly used open source relational database management systems, mainly used to store and manage large amounts of structured data. In applications, the read performance of the database is often very important, because read operations are the main type of operations in most applications. This article will focus on how to improve the read performance of the MySQL storage engine, focusing on a comparative analysis of MyISAM and InnoDB, two commonly used storage engines.

See all articles