Firebird Relational Database Management System

repository·master·Indexed 23 days ago

https://github.com/firebirdsql/firebird

A high-performance, multi-platform RDBMS implementing ANSI SQL standards with support for stored procedures and triggers. This repository includes the core database engine, the Firebird Binary Installer Test Harness (FBIT) for automated installation testing, Object Pascal examples, and external libraries such as libcds (Concurrent Data Structures), libtomcrypt, and LibTomMath.

Tokens
158.9K
Snippets
306
Records
725
Agent score
78%

What's inside Firebird

  1. Overview of the CDS C++ library

    master

    The Concurrent Data Structures (CDS) library is a collection of concurrent containers designed for shared access without requiring manual external synchronization. It utilizes Safe Memory Reclamation (SMR) algorithms, such as Hazard Pointers and user-space RCU (epoch-based SMR), to manage memory safely in concurrent environments.

    Key features include:

    • Mostly header-only template library (SMR core is in a separate .so/.dll).
    • Support for both intrusive (cds::intrusive) and non-intrusive (STL-like, cds::container) versions of containers.
    • A wide variety of lock-free and fine-grained lock-based implementations (stacks, queues, maps, sets, skip-lists, etc.).
  2. Overview of Firebird Relational Database

    master
    Firebird is a multi-platform relational database management system (RDBMS) that supports many ANSI SQL standard features. It is designed for high performance and excellent concurrency, offering powerful language support for stored procedures and triggers. It runs on Linux, Windows, MacOS, and various Unix platforms.
  3. Overview of the Firebird Profiler (FB 5.0)

    master

    The Firebird Profiler allows you to measure the performance cost of SQL and PSQL (Procedural SQL) code. It collects statistics such as execution counts, minimum, maximum, and accumulated execution times (with nanosecond precision) for each line of code, as well as cursor statistics (open/fetch) for implicit and explicit SQL cursors.

    Key Concepts

    • Sessions: Profiling is managed via sessions. A session can be local (the same attachment/connection) or remote (targeting another attachment).
    • Remote Profiling: To profile a remote attachment, the target must be in an idle state. If the remote attachment belongs to a different user, you must have the PROFILE_ANY_ATTACHMENT system privilege.
    • Data Collection: Statistics are collected in memory and aggregated per request (statement execution). To view the data, it must be flushed to the snapshot tables.
    • Flushing: Data is moved from memory to snapshot tables using an autonomous transaction. This means if you call FLUSH within a transaction, the results may not be immediately visible in that same transaction.
  4. Overview of the RDB$BLOB_UTIL package

    master
    The RDB$BLOB_UTIL package (introduced in Firebird 5.0) provides routines for direct binary manipulation of BLOBs. It is designed for scenarios where standard functions like BLOB_APPEND or SUBSTRING are insufficient or perform poorly. These routines operate directly on binary data, regardless of whether the BLOB is a text or binary type.
  5. Understand Firebird RDBMS licensing

    master

    The Firebird RDBMS project uses two primary licenses for its source files:

    1. InterBase Public License (IPL), version 1.0: Applies to specific source code originally released under the IPL.
    2. Initial Developer's Public License (IDPL), version 1.0: Applies to new files developed by Firebird project members and external contributors.

    Detailed exhibits for these licenses can be found in the /doc/license directory of the repository.

  6. Understand recursive and subroutine behavior for Local Temporary Tables

    master

    When using declared local temporary tables in complex PSQL structures:

    • Recursion: Recursive calls reuse the same compiled table structure, but each recursive execution frame has its own separate rows. Data does not leak between recursive levels.
    • Local Subroutines: Local procedures or functions declared within a scope can access and modify the rows of the containing execution frame's declared local temporary table.
    -- Example of local subroutine accessing outer table
    set term !;
    
    execute block returns (n integer, s integer)
    as
        declare local temporary table t (
            id integer
        );
    
        declare procedure p_add(v integer)
        as
        begin
            insert into t values (:v);
        end
    
        declare function f_count returns integer
        as
            declare variable ret integer;
        begin
            select count(*) from t into ret;
            return ret;
        end
    begin
        insert into t values (1);
        execute procedure p_add(2);
    
        n = f_count();
        select sum(id) from t into s;
        suspend;
    end!
    
    set term ;!
  7. Locate Firebird instances via the Windows Registry

    master

    To support multiple simultaneous installations of Firebird, the engine uses a registry key to manage different instances. Firebird-compliant applications should use this key to locate the specific version of Firebird they wish to use, rather than relying on system-wide paths.

    Applications can enumerate the entries under the Instances key to determine which library instance to load. By default, Firebird ensures a DefaultInstance entry exists, which points to the root directory of the default installation.

  8. Implement an Authentication Plugin

    master

    An authentication plugin consists of a Client side and a Server side. During the handshake, the client and server exchange data iteratively. The process continues as long as the authenticate() method returns AUTH_MORE_DATA.

    Return Codes:

    • AUTH_SUCCESS: Authentication successful.
    • AUTH_FAILED: Authentication failed (aborts process).
    • AUTH_MORE_DATA: More data is needed for the handshake.
    • AUTH_CONTINUE: Try the next plugin in the configured list.
  9. Use named windows with the WINDOW clause (FB 4.0)

    master

    To avoid repetitive window definitions, you can use the WINDOW clause to name a window and reference it in subsequent OVER clauses.

    Rules for Named Windows

    • Referencing: A named window can be used in OVER to reference its definition. It can also serve as a base window for another named or inline window.
    • Limitations:
      • A window that includes a frame clause (ROWS, RANGE, or GROUPS) cannot be used as a base window, though it can be used with OVER <window_name>.
      • A window that uses another window as a base cannot have its own PARTITION BY clause, nor can it override the base window's ORDER BY.
    • Scope: The scope of a named window is limited to its specific query context (e.g., it is not visible to outer or sibling subqueries).
    -- Example: Defining and nesting named windows
    select
        id,
        department,
        salary,
        count(*) over w1,
        first_value(salary) over w2,
        last_value(salary) over w2
      from employee
      window w1 as (partition by department),
             w2 as (w1 order by salary)
      order by department, salary;
  10. Handle Firebird events using IEvents and IEventCallback

    master

    In Firebird 3, event handling uses the IEventCallback interface to avoid unsafe void* casts. Instead of a simple identifier, IAttachment::queEvents() returns a reference-counted IEvents interface.

    Important Lifecycle Note: The IEvents interface must be explicitly released after receiving an event to avoid segmentation faults. If an event arrives immediately before calling cancel(), the interface might already be destroyed. A safe pattern is to release the interface and set it to NULL before queuing for a new event.

    events->release();
    events = NULL;
    events = attachment->queEvents(&status, this, eveLen, eveBuffer);