How to View the Engine of the MySQL Database/Detailed Explanation of the MySQL Database Engine

 

Under normal circumstances, mysql will provide multiple storage engines by default. You can check through the following:

see what storage engine your mysql has provided now:
mysql> show engines;

see the current default storage engine of your mysql:
mysql> show variables like '%storage_engine%';

you need to see what engine a table uses (in the display result, the engine behind the parameter indicates the storage engine currently used by the table):
mysql> show create table table name;

 

Detailed explanation of MySQL database engine

As a Java programmer, everyone should use MySQL database a lot, and they should also have some understanding of the engine of the MySQL database. This article will let me talk about the two engines of the MySQL database, Innodb and MyIASM, and their index structure in detail . Also to consolidate their mastery of this knowledge.

Innodb engine

The Innodb engine provides support for database ACID transactions, and implements four isolation levels of the SQL standard. For the content of database transactions and their isolation levels, please refer to this article on database transactions and their isolation levels. The engine also provides row-level locks and foreign key constraints. Its design goal is to handle large-capacity database systems. It is actually a complete database system based on the MySQL background. When MySQL is running, Innodb will establish a buffer pool in memory for Buffer data and indexes. But the engine does not support FULLTEXT type index, and it does not save the number of rows in the table, when SELECT COUNT (*) FROM TABLE needs to scan the whole table. This engine is of course preferred when database transactions need to be used. Due to the smaller granularity of the lock, the write operation will not lock the entire table, so when the concurrency is high, using the Innodb engine will improve the efficiency. However, the use of row-level locks is not absolute. If MySQL cannot determine the range to be scanned when executing an SQL statement, the InnoDB table will also lock the entire table.

MyIASM engine

MyIASM is the default engine of MySQL, but it does not provide support for database transactions, nor does it support row-level locks and foreign keys. Therefore, when INSERT (insert) or UPDATE (update) data, the write operation needs to lock the entire table, which is more efficient. will be lower. However, unlike Innodb, MyIASM stores the number of rows in the table, so SELECT COUNT(*) FROM TABLE only needs to directly read the saved value without performing a full table scan. MyIASM is also a good choice if the table has far more reads than writes and does not require database transaction support.

Choice of two engines

Large-sized datasets tend to choose the InnoDB engine because it supports transaction processing and failure recovery. The size of the database determines the length of time for failure recovery. InnoDB can use transaction logs for data recovery, which will be faster. The primary key query is also quite fast under the InnoDB engine, but it should be noted that if the primary key is too long, it will also cause performance problems, which I will talk about below. Bulk INSERT statements (writing multiple rows per INSERT statement, batch inserts) will be faster under MyISAM, but UPDATE statements will be faster under InnoDB, especially when the amount of concurrency is high.

Index - index

Index (Index) is a data structure that helps MySQL obtain data efficiently. Both MyIASM and Innodb use the tree data structure as an index. I also wrote an article about the tree. The tree is a great data structure, just my own understanding, and interested friends can read it . Next, I will talk about the index structure used by these two engines. When it comes to this, I should first talk about B-Tree and B+Tree.

B-Tree和B+Tree

B+Tree is a variant of B-Tree, so I will talk about B-Tree first. I believe everyone knows red-black trees. This is a red-black tree that I realized when I studied the book "Algorithms" some time ago. Everyone can refer to. In fact, a red-black tree is similar to a 2,3-search tree, which has both 2-fork nodes and 3-fork nodes. B-Tree is also similar, each of its nodes can have d branches (forks), d is called the degree of B-Tree, as shown in the figure below, each of its nodes can have 4 elements , 5 branches, so its degree is 5. The elements in the B-Tree are ordered. For example, the elements in the nodes pointed to by the pointer to the left of element 7 in the figure are all less than 7, and the elements in the nodes pointed to by the pointers between elements 7 and 16 are all between 7 and 16. Between 16 and 16, it is this relationship that can be efficiently searched: first, perform a binary search from the root node, and return the corresponding value if found, otherwise enter the corresponding interval node to recursively search until the corresponding element is found or found A null pointer, if a null pointer is found, the search fails. This lookup is very efficient, and its time complexity is O(logN) (based on d, when d is large, the height of the tree is very low), because each retrieval only needs to retrieve at most h nodes in the tree height .

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326629409&siteId=291194637