Chapter 16. The InnoDB Storage Engine

Table of Contents

16.1. InnoDB Overview
16.2. InnoDB Contact Information
16.3. InnoDB in MySQL 3.23
16.4. InnoDB Configuration
16.5. InnoDB Startup Options
16.6. Creating the InnoDB Tablespace
16.6.16.6.1. Dealing with InnoDB Initialization Problems
16.7. Creating InnoDB Tables
16.7.16.7.1. How to Use Transactions in InnoDB with Different APIs
16.7.16.7.2. Converting MyISAM Tables to InnoDB
16.7.16.7.3. How an AUTO_INCREMENT Column Works in InnoDB
16.7.16.7.4. FOREIGN KEY Constraints
16.7.16.7.5. InnoDB and MySQL Replication
16.7.16.7.6. Using Per-Table Tablespaces
16.8. Adding and Removing InnoDB Data and Log Files
16.9. Backing Up and Recovering an InnoDB Database
16.9.16.9.1. Forcing Recovery
16.9.16.9.2. Checkpoints
16.10. Moving an InnoDB Database to Another Machine
16.11. InnoDB Transaction Model and Locking
16.11.16.11.1. InnoDB and AUTOCOMMIT
16.11.16.11.2. InnoDB and TRANSACTION ISOLATION LEVEL
16.11.16.11.3. Consistent Non-Locking Read
16.11.16.11.4. Locking Reads SELECT ... FOR UPDATE and SELECT ... LOCK IN SHARE MODE
16.11.16.11.5. Next-Key Locking: Avoiding the Phantom Problem
16.11.16.11.6. An Example of How the Consistent Read Works in InnoDB
16.11.16.11.7. Locks Set by Different SQL Statements in InnoDB
16.11.16.11.8. When Does MySQL Implicitly Commit or Roll Back a Transaction?
16.11.16.11.9. Deadlock Detection and Rollback
16.11.16.11.10. How to Cope with Deadlocks
16.12. InnoDB Performance Tuning Tips
16.12.16.12.1. SHOW INNODB STATUS and the InnoDB Monitors
16.13. Implementation of Multi-Versioning
16.14. Table and Index Structures
16.14.16.14.1. Physical Structure of an Index
16.14.16.14.2. Insert Buffering
16.14.16.14.3. Adaptive Hash Indexes
16.14.16.14.4. Physical Record Structure
16.15. File Space Management and Disk I/O
16.15.16.15.1. Disk I/O
16.15.16.15.2. Using Raw Devices for the Tablespace
16.15.16.15.3. File Space Management
16.15.16.15.4. Defragmenting a Table
16.16. Error Handling
16.16.16.16.1. InnoDB Error Codes
16.16.16.16.2. Operating System Error Codes
16.17. Restrictions on InnoDB Tables
16.18. InnoDB Troubleshooting
16.18.16.18.1. Troubleshooting InnoDB Data Dictionary Operations

NOTE: CRITICAL BUG in 4.1.2 if you specify innodb_file_per_table in my.cnf on Unix. In crash recovery InnoDB will skip the crash recovery for all .ibd files and those tables become CORRUPT! The symptom is a message Unable to lock ...ibd with lock 1, error: 9: fcntl: Bad file descriptor in the .err log in crash recovery.

InnoDB Overview

InnoDB provides MySQL with a transaction-safe (ACID compliant) storage engine with commit, rollback, and crash recovery capabilities. InnoDB does locking on the row level and also provides an Oracle-style consistent non-locking read in SELECT statements. These features increase multi-user concurrency and performance. There is no need for lock escalation in InnoDB because row-level locks in InnoDB fit in very little space. InnoDB also supports FOREIGN KEY constraints. In SQL queries you can freely mix InnoDB type tables with other table types of MySQL, even within the same query.

InnoDB has been designed for maximum performance when processing large data volumes. Its CPU efficiency is probably not matched by any other disk-based relational database engine.

Fully integrated with MySQL Server, the InnoDB storage engine maintains its own buffer pool for caching data and indexes in main memory. InnoDB stores its tables and indexes in a tablespace, which may consist of several files (or raw disk partitions). This is different from, for example, MyISAM tables where each table is stored using separate files. InnoDB tables can be of any size even on operating systems where file size is limited to 2GB.

InnoDB is included in binary distributions by default as of MySQL 4.0. For information about InnoDB support in MySQL 3.23, see the section called “InnoDB in MySQL 3.23”.

InnoDB is used in production at numerous large database sites requiring high performance. The famous Internet news site Slashdot.org runs on InnoDB. Mytrix, Inc. stores over 1TB of data in InnoDB, and another site handles an average load of 800 inserts/updates per second in InnoDB.

InnoDB is published under the same GNU GPL License Version 2 (of June 1991) as MySQL. If you distribute MySQL/InnoDB, and your application does not satisfy the provisions of the GPL license, you must purchase a commercial MySQL Pro license from https://order.mysql.com/?sub=pg&pg_no=1.