mysql optimization (a) - Mysql storage engine

Reference article:

https://mp.weixin.qq.com/s?__biz=MzI4Mzc5NDk4MA==&mid=2247486569&idx=2&sn=97110c3d1b682c8dbb5f4e265ba715a3&chksm=eb840722dcf38e343fe8d48ad491a39d0d8015425c743fcf2febf98d577f47b4a7f23559d5a3&scene=0&xtrack=1#rd
================ ==========================
https://www.cnblogs.com/aikutao/p/11207365.html
https://baijiahao.baidu ? .com / s id = 1629308672995568286 & wfr = spider & for = pc
lock: https: //www.cnblogs.com/zyy1688/p/9924048.html

Database Engine

  1. Description: The database engine is the underlying database software organization, database management systems (DBMS) using the database engine to create, query, update, and delete data, different storage engines provide different storage mechanism, indexing techniques, lock level and other functions, the use of different storage engine, you can also obtain a specific function.

The difference between simple storage engine

Here Insert Picture Description

Here Insert Picture Description

  1. The InnoDB, MylSAM data structure used by both the engine is B + tree index, but the difference is:
  1. InnorDb content data structure stored in a B + tree is the address of the actual data, index, and it is separate from the actual data, but uses the index pointing to the actual data, such an index pattern is in a non-clustered index.
    2.MyISAM data structure stored in B + trees are actual data, this index is called clustered index.

Index Category:

  1. The only index: unique index does not allow the same index value
  2. Primary key index: unique index is a special type, in order to define a primary key table will automatically create a primary key index. Primary key index required for each primary key values ​​are unique, and can not be null.
  3. Clustered index (clustered) logical-physical order of the key values ​​in each row of the same table (index) order, each table can have only one.
  4. Non-clustered index (Non-clustered): logical order non-clustered index table is specified, data is stored in a location index is stored in another location, the index contains a pointer to data storage locations, there may be more than, less than 249.

A, InnoDB

  1. Description: This is the MySQL 5.5 or a later version of the default storage engine.It provides transaction-safe (ACID compliant) table, foreign key support referential integrity constraints. It supports the submission, rollback and emergency recovery to protect data. It also supports row-level locking. When used in a multi-user environment, it's "consistent non-locking read" improve performance. It is stored in the cluster index data, thereby reducing the primary key of the query-based I / O.

Because InnoDB database using as an index the primary key Key, InnoDB table so that the main index file itself, and because the data files that need InnoDB aggregates according to the master key,Therefore, as the table data using InnoDB engine requires a primary keyIf not explicitly specified, MySQL will attempt to automatically select a can be listed as the primary key, if not found, it will generate an implicit uniquely identifies a data field as the primary key, the field length of 6 bytes, the type of long integer.

Here Insert Picture Description
二、MyISAM

  1. Features: The non-transactional storage engine management table, providedHigh-speed storage and retrieval, support for full-text search, table locks, The index only save the address data records.
    Here Insert Picture Description
    Three, MEMORY

It provides in-memory tables, formerly called the heap. it is atAll data in RAM for faster access than data stored on disk. And other references used to quickly find the same data.

Four, MERGE

A plurality of similar MyISAM tables grouped into a table that can handle non-transactional tables, including tables by default.

Five, EXAMPLE

You can use this engine to create the table, but can not store or retrieve data. The aim is to teach developers how to write new storage engine.

Six, ARCHIVE

For storing large amounts of data, it does not support indexing.

Seven, CSV

In a text file format for storing a comma separated value data.

Eight, BLACKHOLE

By the data to be stored, but always returned empty.

九、FEDERATED

The data stored in the remote database.

lock

  1. MySQL table-level locking lock mode (MyISAM)
    MySQL table-level locking has two modes: a shared lock table (Table Read Lock) and exclusive write locks table (Table Write Lock).
  • MyISAM for read operations do not block other users request the same table, but will block the request to write the same table;
  • Writes for MyISAM, and will block other users on the same table read and write operations;
  • Between the read and write operations MyISAM tables, as well as between the write operation is serial.
    When a thread acquires a write lock on the table, only the thread holding the lock can update operations on the table. Other threads read and write operations will wait until the lock is released.
  1. innor shared locks and exclusive locks
    for shared locks we may well understand, is that multiple transactions can only read data can not change the data,After an exclusive lock for everyone's understanding might be some differences, I had just made a mistake, that an exclusive lock to lock a row of data, other transactions will not be able to read and modify the data line, in fact, not the case. Exclusive lock refers to a transaction in a row after data plus exclusive lock, other transactions can not add another lock on it. mysql InnoDB engine default modify data statements, update, delete, insert automatically to the data related to the plus exclusive lock, select statement default will not add any type of lock, if the rate of exclusive lock can use the select ... for update statement, plus share lock You can use select ... lock in share mode statements. Therefore, the increase is too exclusive lock rows of data to other types of transaction data can not be changed, nor by for update and lock in share mode locking way to query data, but can directly select ... from ... query data,Because there is no common query mechanism locks

  2. InnoDB row lock implementations
    InnoDB row lock is achieved by index entries in the index, which is different from MySQL and Oracle, which is locked by a corresponding data line in the data achieved. InnoDB row lock to achieve this characteristic means of: only retrieve data through index conditions, InnoDB will use row-level locking, otherwise, would use InnoDB table lock!
    In practical application, pay special attention to this feature InnoDB row lock, otherwise, may result in a large number of lock conflicts, thus affecting the concurrent performance.

  3. About Deadlock
    MyISAM table locking is deadlock free, this is because MyISAM is always time access to all the locks required to meet either all, or wait, so there is no deadlock. But in InnoDB, in addition to a single SQL transaction consisting of the lock is gradually obtained, which determines the InnoDB deadlock is possible.
    After a deadlock occurs, InnoDB general can automatically detect and make a transaction to release the lock and return, another transaction to acquire a lock, continue to complete the transaction. However, in the context of an external lock, lock, or involving, == InnoDB not completely automatically detect deadlocks, timeout parameters that need to wait innodb_lock_wait_timeout solved by setting lock. == It should be noted that this parameter is not only used to resolve deadlocks in concurrent access is relatively high, if a large number of transactions due to inability to obtain the required lock and immediately suspended, will take up a lot of computer resources, resulting in serious performance problems and even caused the collapse of the database. We wait for the timeout threshold by setting the appropriate locks to avoid this from happening.

Published 36 original articles · won praise 11 · views 10000 +

Guess you like

Origin blog.csdn.net/s_xchenzejian/article/details/104556750