MySQL's InnoDB storage engine

MySQL default storage engine is InnoDB, by using the command SHOW VARIABLES LIKE 'storage_engine';

a, InnoDB storage engine

1.InnoDB choice for transactional database engine, support for transaction-safe tables (the ACID)
 (MyISAM: transactions are not supported; only support table-level locking )

the ACID properties of transactions: namely atomicity, consistency, isolation, durability

                            a atomicity: atomicity that this set of statements either all executed or not executed all, if the transaction is executed to half errors , the database must roll back to the beginning of the implementation of local affairs.

                             Implementation: mainly based redo MySQ system log and undo mechanisms. A transaction is a set of SQL statements, there are select, query, delete functions. Each statement there will be a node. For example, delete statement is executed, there are records preserved in the transaction, the record stores when we have done something. If an error occurs, it will roll back to the original position, redo has been stored inside I did something, and then execute it again reverse it.

                                b consistency: the beginning and the end of the transaction, integrity constraints of the database is not corrupted before. (EG: such as A to B transfer, money can not buckle A, B did not receive)

                                C Isolation: the same time, only one transaction request for the same data, without any interference from each other between different transactions;.

                                If not isolation will consider several questions arise:

                                 i, dirty read: refers to a transaction processing in the data read another transaction uncommitted (when a transaction is a data modified several times, but this many times in this transaction have not yet modified Submit, a case of concurrent access to the transaction data, the transaction will result in inconsistent data obtained two); (dirty read another uncommitted transaction)

                                 II, non-repeatable read: in a database for data, within a range of transaction has multiple queries return different data values, which is due to the query interval, and is modified by another transaction submitted; (read previous transaction data submitted query are the same a data item)

                                 III, phantom read: is a phenomenon that occurs when the non-independent transaction execution (EG: transaction T1 to a data item in a table of all the lines made from "1" to "2" operation , transaction T2 and time T1, the user operates the transaction to see if we just modify the data table row is inserted into a data item, while a value of the data item or to "1", and submitted to the database, We found that there is a line not modify, in fact, this line is added from the transaction T2, like hallucinations, like); (read previous transaction data submitted, a batch of data as a whole)

                                persistence d:. After the transaction is completed , all updates to the database transaction will be saved to the database, you can not roll back

2.InnoDB mySQL is the default storage engine, the default is the isolation level RR, and one step closer in the RR isolation level, through multi-version concurrency control ( MVCC) to solve the problem of non-repeatable read, plus clearance lock (that is, concurrency control) to solve the problem of phantom read. Therefore, RR isolation level of InnoDB actually achieve serialization level of effect, while retaining good concurrent performance.

The four isolation MySQL database provides us with the level of:

a, Serializable (serialization): can prevent dirty reads, non-repeatable read, phantom read occurs; (do not use, a great impact on serialization, query efficiency)

B, Repeatable Read (Repeatable Read): can avoid dirty reads, non-repeatable reads occur; (the default isolation level)

c, the read committed (read committed): can avoid dirty reads occurring;

d, the read uncommitted (read uncommitted): the lowest level, in any case can not be guaranteed;

from A ---- d isolation level from high to low, the higher the level, the lower the efficiency

3.InnoDB supports row-level locks. Row-level locking can support concurrent maximum, row-level locking is implemented by the storage engine layer.

Lock: Lock main role is to manage concurrent access to shared resources, for implementing the transaction isolation

        types: shared lock (read lock), an exclusive lock (write lock)         

        MySQL locks efforts: table-level locking (small overhead, concurrency low), usually implemented in the server layer

                                    row-level locking (big spending, high concurrency), will be implemented in the storage engine level

4, InnoDB is designed to handle huge amounts of data designed for maximum performance. Its CPU efficiency may be any disk-based relational database engine can not match

5, InnoDB storage engine is fully integrated with MySQL server, InnoDB storage engine to cache data and indexes in main memory and maintains its own buffer pool. InnoDB tables and indexes it in a logical table space, table space can contain a number of files (disk files or original);

. 6, InnoDB support foreign keys integrity constraints, data stored in the table, each table stored in storing the primary key are in accordance with the order, if the primary key is not displayed when the specified table definition. InnoDB generates a 6-byte ROWID for each row, and as the primary key

7, InnoDB is used in many high performance is required large database sites

the number of rows 8, InnoDB not storage table (eg: select count (*) from the time table, InnoDB again need to scan the entire table to calculate the number of rows); empty the entire table, InnoDB is to delete the line by line, the efficiency is very slow;
  (MyISAM engine will record the number of table rows)

InnoDB does not create directories, use InnoDB, MySQL will create a file called ibdata1 in the MySQL data directory size 10MB automatic extension of a data file, and two files named 5MB log size and ib_logfile1 ib_logfile0 the

two underlying engine to achieve InnoDB

InnoDB has two storage file, and the suffix respectively .frm .idb; wherein .frm table definition files, .idb is a table of data files.

1, InnoDB engine uses B + Tree index structure as the structure

B-Tree (balanced search tree multiplexing): a balanced search tree is loaded with the disk storage devices designed for

the system data read from the disk memory to the disk block is the basic unit of bits, a data block on one disk are read out only once, rather than read on demand.

InnoDB storage engine to use as a data page reads, and pages is the smallest unit of its disk management, the default page size is 16k.

Storage space of a disk block system is often not so great, InnoDB Thus each application will be the number of disk space address contiguous disk blocks to reach the size of 16KB pages.

InnoDB when the number of disk reads data into the disk will be the basic unit of a page, when you query data, each data if a page can help to locate the position of the recorded data, which will reduce disk I / O, improve query efficiency.

B-Tree data structure allows the system to efficiently find the disk where the data block

Each Node B-Tree may contain significant amounts of the key information and the branch, according to the actual embodiment:

 



Each node of disk space occupied by a disk block, there are two pointers in ascending order of keyword and three points on a child node of the root node, the address pointer is stored in disk blocks child node is located.

In the root, for example, 17 and 35 for the keywords, the data range P1 subtree pointer to less than 17, the data range P2 subtree pointer 17 ---- 35, the data pointer P3 subtree range greater than 35;

simulation keyword lookup procedure 29:

a block according to find root disk 1, is read into memory. [Disk I / O operations for the first time]

b compare keywords in the section 29 (17, 35), to find a disk block pointer P2. 1;.

. Found C disk block 3 is read into memory as pointer P2. [Disk I / O operations second]

d 29 Comparative keywords in the interval (26, 30), to find a disk block pointer P2. 3;.

E 8 P2 find disk block pointer, read into memory. [Disk I / O operations third]

f. 29. find keywords in the keyword list of disk blocks 8 in

MySQL's InnoDB storage engine is designed to root permanent memory, and therefore strive to achieve the depth of the tree no more than 3, that is, I / O does not need more than three times;

the above analysis results, it was found need three times the disk I / O operations, and three memory lookup operation. Since the memory key is an ordered list structure, you can use a binary search to improve efficiency; while determining factor affecting the overall efficiency of the B-Tree to find when three times the disk I / O operations.

Tree + B

B + Tree is an optimization based on the B-Tree to make it more suitable for implementing the external memory index structure, each node in the B-Tree have key, there are Data, and each page of memory is a limited, small number of data if the data is large will cause each node (i.e., a page) can be stored in the key. When the amount of data stored in the B-Tree will also lead to a greater depth, the query is increased when the disk I / O times, thereby affecting the efficiency of the query.

In the B + Tree nodes are all in accordance with the key-data records stored in the order of the leaf nodes of the same level, not only stores the key value of the leaf node information, which can greatly increase the number of key values stored at each node, reducing + height Tree, B;

B + Tree there are two variations on the basis of B-Tree on: (1) data is present leaf nodes (primary key index leaf node storing the master key ID; ordinary index, stored is entire row of data)

                                                         between (2) the data is a pointer to the node (conveniently range lookup)

Since B + Tree of non-leaf nodes store only the key information, assuming that each disk can store four key block and pointer information, after the B + Tree structure becomes as shown below:

 



There are usually two head pointer on the B + Tree, a pointer to the root node, pointing to another keyword minimum leaf node, and a ring structure is a chain among all the leaf nodes (i.e., node data).

Thus two search operation can be performed on the B + Tree, one is for the primary key range search and find the tab, the other is from the root node, random search.

Tree in InnoDB + B

InnoDB ID is stored as the index data

using InnoDB engine has two data storage file, a definition file is a data file.

 


InnoDB by B + Tree Structure ID indexed, and store records in a leaf node

if the indexed fields not established primary key ID, then the field is indexed and then stored in the leaf node is the primary key of the record, and the primary key the index to find the corresponding record

 Reference links: https://blog.csdn.net/m0_37962600/article/details/81005191

Guess you like

Origin www.cnblogs.com/fish-eatingWolfCub/p/11373072.html