Overview > SQLite Architecture
SQLite consists of seven major component subsystems (also known as modules) partitioned into two divisions: frontend parsing system and backend engine. Two block diagrams, showing the component subsystems and how they interrelate, are given in Figure 1-1.
The frontend preprocesses SQL statements and SQLite commands that are sent as input to it by applications. It parses these statements (and commands), optimizes them, and generates equivalent SQLite internal bytecode programs that the backend can execute. The frontend division is composed of three modules:
The tokenizer splits an input statement into tokens.
The parser analyzes the structure of the statement by analyzing the tokens produced by the tokenizer, and generates a parse tree. The parser also includes an optimizer that restructures the parse tree, and finds an equivalent parse tree that will produce an efficient bytecode program.
The code generator
The code-generator traverses the parse tree, and generates an equivalent bytecode program.
The frontend implements the sqlite3_prepare API function.
The backend is the engine that interprets bytecode programs. The engine does the actual database processing work. The backend division is composed of four modules:
The Virtual Machine (VM)
The VM module is the interpreter for the internal bytecode language. It executes bytecode programs to carry out the work of the SQL statements. It is the ultimate manipulator of data from databases. It sees a database as collection of tables and indexes, where a table or index is a set of tuples, or records.
The B/B+-tree module organizes each tuple set into an ordered tree data structure; tables and indexes in separate B+- and B-trees, respectively. (I will discuss about these data structures in the "Table and Index Management" section.) The module helps the VM to search, insert, and delete tuples in trees. It also helps the VM to create new trees, and to delete old trees.
The pager module implements a page-oriented database file abstraction on the top of native files. It manages an in-memory cache (of database pages) that the B/B+-tree module uses, and, in addition, manages file locking and journaling to implement transactional ACID properties.
The operating system interface
The operating system interface module provides a uniform interface to different native operating systems.
The backend implements sqlite3_bind_*, sqlite3_step, sqlite3_column_*, sqlite3_reset and sqlite3_finalize API functions.
Because of limited space availability, in this Short Cut I only discuss the SQLite engine, and not the parsing system. The examples in this Short Cut use Linux to present the inner workings of SQLite, but as SQLite is portable to many other operating systems, they should work similarly on whatever platform you use.