Firebird is an open-source SQL relational database management system (RDBMS) that provides a full-featured database engine with ACID transaction support, SQL-92/99 compliance, stored procedures, triggers, and multi-version concurrency control (MVCC). The codebase implements both embedded and client-server deployment models using the same core engine.
Key Characteristics:
This page provides:
Detailed Information:
The Firebird repository at https://github.com/FirebirdSQL/firebird is organized into the following directories:
| Directory | Purpose | Key Files |
|---|---|---|
| src/jrd/ | JRD (Jupiter Relational Database) core engine | jrd.cpp, exe.cpp, vio.cpp, tra.cpp, cch.cpp |
| src/dsql/ | DSQL (Dynamic SQL) compiler and parser | parse.y, dsql.cpp, pass1.cpp, gen.cpp |
| src/yvalve/ | Y-valve API dispatcher and client library | why.cpp, YObjects.h |
| src/remote/ | Remote protocol for client-server communication | server/server.cpp, client/interface.cpp, inet.cpp |
| src/common/ | Shared utilities and configuration | classes/, config/config.cpp |
| src/lock/ | Lock manager for Classic mode | lock.cpp |
| src/isql/ | Interactive SQL tool | isql.epp, show.epp |
| src/burp/ | Backup/restore utility (gbak) | backup.epp, restore.epp |
| builds/ | Build system and version management | posix/Makefile.in.*, writeBuildNum.sh |
Sources: Repository structure, src/jrd/jrd.cpp1-50 src/dsql/dsql.cpp1-50 src/yvalve/why.cpp1-50
Firebird employs a layered architecture where each layer provides services to the layer above it. The system supports both embedded (direct library linking) and client-server deployments using the same codebase.
Sources:
The following table maps conceptual components to their primary C++ classes and key files:
| Component | Primary Classes | Key Files | Purpose |
|---|---|---|---|
| Database Handle | Jrd::Database, Jrd::Attachment | jrd/Database.h, jrd/Attachment.h | Represents database connection state |
| Transaction | Jrd::jrd_tra | jrd/tra.h, jrd/tra.cpp | Transaction context and state management |
| Request | Jrd::Request, DsqlRequest | jrd/req.h, dsql/dsql.h | Compiled statement execution state |
| Statement | DsqlStatement, Jrd::Statement | dsql/dsql.h | Prepared SQL statement |
| Record Buffer | record_param (rpb) | jrd/jrd.h:600-650 | Record location and version tracking |
| Page Buffer | BufferDesc (bdb), BufferControl (bcb) | jrd/cch.h | Page cache management |
| AST Node | ExprNode, StmtNode, ValueExprNode | dsql/Nodes.h | SQL abstract syntax tree |
Sources:
The Y-valve in src/yvalve/why.cpp provides the primary API dispatch layer. Key functions include:
Sources:
The JRD engine is initialized and accessed through src/jrd/jrd.cpp:
| Function | Location | Purpose |
|---|---|---|
JRD_attach_database() | jrd.cpp:~1400 | Initialize database attachment |
JRD_start_transaction() | jrd.cpp:~5400 | Begin new transaction |
JRD_prepare() | jrd.cpp:~3600 | Compile BLR into executable request |
JRD_start_and_send() | jrd.cpp:~4800 | Execute request with input message |
JRD_receive() | jrd.cpp:~4200 | Fetch result row |
Sources:
Dynamic SQL processing begins in src/dsql/dsql.cpp:
Sources:
SQL Statement Execution Pipeline
The following sequence shows how a SQL statement flows through the system from client API call to data retrieval:
Processing Stages:
parse.y): SQL text → Abstract Syntax Tree (AST)pass1.cpp): Name resolution, type checking, validationgen.cpp): AST → BLR (Binary Language Representation)Optimizer.cpp): BLR → Optimized execution plan (RecordSource tree)exe.cpp): Execute plan using EXE_looper() state machinevio.cpp): Fetch records with MVCC version traversalcch.cpp): Buffer pool management for disk pagesFor detailed information on each stage, see Query Processing.
Sources: src/yvalve/why.cpp1-100 src/dsql/dsql.cpp1-200 src/dsql/parse.y1-100 src/dsql/pass1.cpp1-100 src/jrd/optimizer/Optimizer.cpp1-200 src/jrd/exe.cpp1-200 src/jrd/vio.cpp1-200 src/jrd/cch.cpp1-200
Firebird's architecture is built around several tightly-integrated subsystems. Each is documented in detail in its own wiki section.
The Virtual I/O layer (vio.cpp) implements multi-version concurrency control where each record maintains a chain of versions. Transactions see consistent snapshots by traversing version chains based on transaction state.
Key Concepts:
record_param (rpb) structures with back-version pointers (rpb_b_page, rpb_b_line)VIO_chase_record_version() follows chains to find visible versionjrd_tra snapshot bitmap determines which versions are visiblegarbage_collect()Transactions (jrd_tra) maintain ACID properties with state tracked in Transaction Inventory Pages (TIP). Transaction numbers increase monotonically and states are cached for fast visibility checks.
Key Operations:
TRA_start() - Allocate transaction number and initialize snapshotTRA_commit() - Mark transaction committed in TIPTRA_rollback() - Undo changes by marking versions as deadTPC_cache_state() - Fast lookup of transaction stateDDL operations are transactional through the Deferred Work system (dfw.epp). Work items are queued during statement execution and performed in phases at commit time.
Processing Flow:
DdlNode subclassDFW_post_work()DFW_perform_work() executes in 7 phasesSources: src/jrd/vio.cpp1-200 src/jrd/tra.cpp1-200 src/jrd/dfw_proto.h1-50 src/dsql/DdlNodes.epp1-200
The build infrastructure uses autoconf/automake with custom version management:
builds/posix/setupBuildNum.sh, builds/posix/writeBuildNum.shconfigure.ac, Makefile.in.*builds/posix/make.platformsrc/jrd/build_no.h, gen/Make.VersionKey build targets:
libEngine.so - JRD enginelibfbclient.so / libyvalve.so - Client librarylibfbintl.so - Internationalizationgbak, isql, gfix, gsec, gstatSources:
This architecture enables Firebird to provide:
Refresh this wiki
This wiki was recently refreshed. Please wait 1 day to refresh again.