High performance MySQL chapter 1th MySQL Architecture and history (1)

Source: Internet
Author: User
Tags mysql in

MySQL Logical architecture diagram:

First-tier client

Second tier (service layer): the parts that can be publicly extracted for all types of storage engines. This is where the rest of the storage engine is pumped away. Such as: query parsing, analysis optimization, built-in functions, stored procedures, triggers, views.

Third tier (storage engine layer): The storage Engine is responsible for the storage and extraction of MySQL data. The server communicates with the storage engine through the API. These APIs mask the specific implementation differences of different storage engines. The Storage Engine API contains operations such as "Start a transaction", "get a row of data based on a primary key." The storage engine itself does not parse SQL.

Note: Mongdb also has a storage engine.

The database controls concurrent transactions through read and write locks, also called shared and exclusive locks.

With regard to lock granularity, MySQL is given to the storage engine to manage itself, and each storage engine can implement its own lock granularity and lock policy.

Different locking strategies bring different effects, with the least cost of table locks, but the worst concurrency. Row-level locks have the best concurrency performance, but are the most expensive.

Although the lock policy is managed on the storage engine, the service layer uses the table directly, ignoring the locking mechanism of the storage engine layer, when performing ALTER TABLE operations.

Isolation level:

MySQL supports the four isolation levels:

    • READ UNCOMMITTED: Uncommitted reads
    • Read commited commit (default isolation level for Oracle)
    • REPEATABLE Read REPEATABLE reading (default isolation level for MySQL)
    • Serializable serialization

Note: Repeatable reading solves the problem of non-repeatable reads (the same data is not the same when it was read two times). Serialization solves the problem of Phantom reading (two executions of the same where statement result in inconsistent result bars).

Question: About serialization, the book says that MySQL locks the data that each line reads. If you do this, you can certainly guarantee repeatable reads, but how can you guarantee phantom reading, because locking the data you read does not block the insert operation?

Deadlock: The cause of the deadlock, one is the operation of the business scenario, and the other is caused by the way the storage engine is implemented.

The InnoDB is able to identify the deadlock and rollback the transaction that holds the least exclusive lock.

Transaction log:

The transaction log can improve the efficiency of the transaction, MySQL in the Update table only need to modify the in-memory data, and then record the modification behavior in the transaction log of the hard disk, the process of this transaction is finished. You do not have to wait for the data file on your hard drive to be returned. The transaction log is a sequential storage space on the hard disk, not a random disk storage, and each add is appended, and the contents of the transaction log are persisted to the hard disk data file. This is called pre-write logging and requires two hard drives to be written.

If a power outage occurs, the data can be recovered through the transaction log after a restart.

Note: MongoDB's newest Wiredtiger storage engine also has the concept of a transaction log, but not a transaction log, called a pre-write log (Wal:write-ahead Logging), because Mongdb has no transactions.

High performance MySQL chapter 1th MySQL Architecture and history (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.