Wednesday, February 4, 2009

Understanding the InnoDB Source Code Structure

Innodb source code is organized into directories where each directory holds the C source code files for a given module. Within the directory are 1 or more files that are part of the module. The file names have a structure which I will describe below.

The first part of the file name indicates the module name. The module name is followed by a '0' character which is a separator. The second part of the file name represents the sub-module. Most modules have one file where the sub-module is the same name as the module, this file represents the primary file in the module.

For, example the main file for Btree is located in the btr directory and named: btr0btr.c
The first btr indicates the module name, the 0 is a separator and the the second btr is the sub module name which is the same for the primary file.

The file that handles the Btree cursor is also located in the btr directory and named: btr0cur.c
The first btr is the module name, the 0 is a separator, and the cur is the sub module name which stands for cursor in this case.

There is also a include directory which contains all the header files. The header files are also named in a similar way.

For example, the file 'btr0cur.h' is the header file for the Btree cursor module. Note the include files contain both '.h' files and '.ic' files which are included C files.

Now that we understand the naming conventions, I am going to give you a list of all the modules in the Innodb source code base and a description of what they are for. The list below is sorted by lines of code in the module, with the biggest modules coming first.



Row Abstraction, 19,768 lines
sub-modules: Updates, Undo, Undo Modify, Undo Insert, Select, Purge, Mysql Interface
The logic for the mysql row formatting and the innodb row formatting is quite lengthy. This module also seems to have a lot of the high-level business logic for Innodb.


Transactions, 13,138 lines
sub-modules: Rollback, Rollback Segment, Undo, Log Records, Purge
As Innodb is a transactional storage engine there is a lot of logic to implement this


Btree data structure, 12,228 lines
sub-modules: Btree Cursor, Btree Persistent Cursor, Btree Adaptive Search
Btree is the index of Innodb and is core functionality

SQL parser, 11,691 lines
sub-modules: Symbol Table, Optimizer, Lexical Analyzer, Grammar
I am pretty sure you can ignore this directory if you are using innodb with mysql, as it is dead code in that case (please do correct me if I am wrong)

Data Dictionary (meta-data), 10,446 lines
sub-modules: Boot, Creation, Load, Memory
Table names, column names, key names, etc. all in this code


Mysql Storage Engine Interface, 8498 lines
This is the primary interface between Mysql and the innodb storage engine and the entry point for all mysql API calls.

Database Log, 8379 lines
sub-modules: Recovery
Database logging is core functionality

Buffer Pool, 7784 lines
sub-modules: Buffer Flush Algorithm, Buffer Replacement Algorithm, Buffer Read Abstraction

Operating System Interface, 7659 lines
sub-modules: Files, Processes, Threads, Synchronization
This is the fun stuff, all the low level OS specific code


Transaction Lock System, 6224 lines
sub-modules: Lock Queue Iterator

Index Page, 5675 lines
sub-modules: Page Cursor

Main Server Driver, 5469 lines
sub-modules: Startup, Query Execution
Look here for configuration option handling coding and other startup issues

Synchronization, 5361 lines
sub-modules: ReadWrite Lock, Wait Array

Table Space Memory Cache, 5282 lines

Records Abstraction, 4965 lines
sub-modules: Record Manager, Record Comparison Service

File Space Management, 4405 lines

Insert Buffer, 4125 lines

Utilities, 4113 lines
sub-modules: Vector, Random Numbers, Memory, List, Debug, Byte Manipulation, Work Queue

Memory Management, 3598 lines
sub-modules: Memory Debug, Memory Pool

Data Element Abstraction, 2867 lines
sub-modules: Data Types

Query Graph, 2255 lines

Mini-transaction Buffer, 1967 lines
sub-modules: Mini-transaction Log

SQL evaluator, 1603 lines
sub-modules: Stored Procedures

Hash table, 1422 lines

Machine Dependent Utilities, 1198 lines

File Based Utilities, 951 lines
sub-modules: File Based List


Cursor Read, 788 lines

Dynamically Allocated Array, 560 lines

Threads, 302 lines
sub-modules: Thread Local Storage

Sessions, 163 lines


  1. Buying a piece of jewelry for him is thpmas sabo not as tricky as it might seem.thoughtfully-picked piece of jewelry. thomas sabo charms Here are five suggestions for when you are considering buying thomas sabo bracelets jewelry for him:A timepiece: Every man needs a reliable timepiece. thomas sabo charm carriers You have three different options to work with: thomas sabo watches A dress watch: Men with office thomas sabo charm pearl jobs need a watch that complements their suits.

  2. This comment has been removed by the author.

  3. Really helpful blog! Thanks author :)

  4. For more information one can visit :-