Section 1.2. SQLite Architecture

Overview > SQLite Architecture

1.2. 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.

Figure 1-1. Components of SQLite


1.2.1. Frontend

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

The tokenizer splits an input statement into tokens.


The parser

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.

1.2.2. Backend

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

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

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.

NOTE

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.



Inside SQLite
Inside Symbian SQL: A Mobile Developers Guide to SQLite
ISBN: 0470744022
EAN: 2147483647
Year: 2004
Pages: 29
Authors: Ivan Litovski, Richard Maynard
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net