随笔 - 120  文章 - 0  评论 - 902  阅读 - 51万

The InnoDB Engine

The InnoDB Engine

InnoDB was designed for transaction processing—specifically, processing of many

short-lived transactions that usually complete rather than being rolled back. It

remains the most popular storage engine for transactional storage. Its performance

and automatic crash recovery make it popular for nontransactional storage needs,

too.

InnoDB stores its data in a series of one or more data files that are collectively known

as a tablespace. A tablespace is essentially a black box that InnoDB manages all by

itself. In MySQL 4.1 and newer versions, InnoDB can store each table’s data and

indexes in separate files. InnoDB can also use raw disk partitions for building its

tablespace. See “The InnoDB tablespace” on page 290 for more information.

InnoDB uses MVCC to achieve high concurrency, and it implements all four SQL

standard isolation levels. It defaults to the REPEATABLE READ isolation level, and it has a

next-key locking strategy that prevents phantom reads in this isolation level: rather

than locking only the rows you’ve touched in a query, InnoDB locks gaps in the

index structure as well, preventing phantoms from being inserted.

InnoDB tables are built on a clustered index, which we will cover in detail in

Chapter 3. InnoDB’s index structures are very different from those of most other

MySQL storage engines. As a result, it provides very fast primary key lookups. However,

secondary indexes (indexes that aren’t the primary key) contain the primary key

columns, so if your primary key is large, other indexes will also be large. You should

strive for a small primary key if you’ll have many indexes on a table. InnoDB doesn’t

compress its indexes.

At the time of this writing, InnoDB can’t build indexes by sorting, which MyISAM

can do. Thus, InnoDB loads data and creates indexes more slowly than MyISAM.

Any operation that changes an InnoDB table’s structure will rebuild the entire table,

including all the indexes.

InnoDB was designed when most servers had slow disks, a single CPU, and limited

memory. Today, as multicore servers with huge amounts of memory and fast disks

are becoming less expensive, InnoDB is experiencing some scalability issues.

20 | Chapter 1: MySQL Architecture

InnoDB’s developers are addressing these issues, but at the time of this writing, several

of them remain problematic. See “InnoDB Concurrency Tuning” on page 296

for more information about achieving high concurrency with InnoDB.

Besides its high-concurrency capabilities, InnoDB’s next most popular feature is foreign

key constraints, which the MySQL server itself doesn’t yet provide. InnoDB also

provides extremely fast lookups for queries that use a primary key.

InnoDB has a variety of internal optimizations. These include predictive read-ahead

for prefetching data from disk, an adaptive hash index that automatically builds hash

indexes in memory for very fast lookups, and an insert buffer to speed inserts. We

cover these extensively later in this book.

InnoDB’s behavior is very intricate, and we highly recommend reading the “InnoDB

Transaction Model and Locking” section of the MySQL manual if you’re using

InnoDB. There are many surprises and exceptions you should be aware of before

building an application with InnoDB.


                                   《high performance mysql 2》

posted on   Keep Walking  阅读(764)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
< 2009年12月 >
29 30 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 1 2
3 4 5 6 7 8 9

点击右上角即可分享
微信分享提示