KDBS

KDBS is a user-space database engine written in C++20. It targets short transactions that read and write by key, joins that follow keys, and durability chosen by the caller. It keeps the feature surface narrow and concentrates on two things. One is that the rules the data must obey are declared in the schema and the engine enforces them on every write. The other is acceleration structures that cannot change results: for every structure the engine consults for speed, deleting it never makes a query return different rows. The sandbox on this site uses KDBS v3.4.17.

KDBS states that it is neither a general-purpose SQL DBMS nor a dialect-compatibility layer for another DBMS. It therefore rejects, with a position (byte offset) and a reason, many syntaxes that are familiar from other DBMSs. The tables in this document collect those differences.

Key Specifications

ItemValue
ImplementationC++20, Linux. One cooperative reactor per core (thread-per-core); the buffer pool and WAL are shared
Storage unit8KB page
Table storageDefault BTREE: a B+ tree clustered by tuple key. HEAP is also available (tuple key)
Row formatFixed-length tuples. UPDATE overwrites in place, and long values go to an immutable side store (var-heap)
Row identifier48-bit tuple key. A key, once written, is not handed to another row until PURGE
StringsThe N in varchar(N) is the cell width (in bytes), not a maximum length. A single value is at most 8,144 bytes
NumbersIntegers, decimal(p,s) (p ≤ 38). float is rejected
NULLColumns are NOT NULL by default. You must write NULL to allow it
Isolation levelsTwo: READ COMMITTED (default) and REPEATABLE READ. SERIALIZABLE is rejected (transactions)
DurabilityThree levels: strict, group (default), relaxed (durability levels)
ProtocolIts own binary protocol KWP/1 (port 15432, loopback by default). Not PostgreSQL wire compatible
AuthenticationOff (default) or SCRAM-SHA-256. Roles readonly, readwrite, admin
Reserved wordsOnly 11 (JOIN, ON, AS, IN, EXISTS, NOT, BETWEEN, LEFT, RIGHT, FULL, OUTER)

Execution Structure

The structure of the reactor threads and the buffer pool is in Memory and Thread Structure, and the protocol and portals are in Connections, Portals, and the Statement Cache.

Statements run by two paths (step chain and query layer).

  • Step chain: A statement that reads as the basic grammar is compiled at parse time into a chain of steps (key lookup, probe, range, scan, sub-chain). There is no general plan search, and the one thing the engine chooses is the join order of the inner join block (join order and plans).
  • Query layer: The rest of SQL, such as outer joins, set operations, derived tables, expressions in the select list, and HAVING, takes rows from the engine's single-table lookup for each table and computes on top of them. ANALYZE does not explain this path.

Everything the engine learns (Waystone traces, Cabin entries, plan statistics) can be erased, and every query returns the same rows after erasing it. Traces only decide where to look first, and statistics only decide the join order.

SQL That Differs from Other DBMSs

ItemOther DBMSsKDBS
Table aliasFROM orders oFROM orders AS o only. A bare alias is rejected so that a misspelled keyword is not read as an alias
Type conversionImplicit conversionNone. '20' against an int column, or 5 against a varchar column, is rejected at compile time
Date and time literalsDATE '2025-01-01''2025-01-01' (date), '2025-01-01 00:00:00' (timestamp). No type prefix
' inside a string'it''s'No escape. A value that contains a single quote cannot be written as a literal
Comments--, /* */-- only
CTE, window functionsSupportedWITH and OVER return NOT_IMPLEMENTED
Outer joins, UNION, HAVING, derived tables, scalar subqueriesSupportedThe query layer answers them. ANALYZE does not explain them
SortingSpills to diskNo spill. The statement fails if it exceeds sort_max_rows (default 1,048,576)
NULLS FIRST/LASTSupportedNone. NULL is the largest value (fixed to the PostgreSQL rule)
Hints/*+ … */, OPTION (…)None. An administrator pins the join order and access method with CREATE PLAN
Auto incrementSERIAL, IDENTITYNone. If INSERT omits the tuple key, the engine issues one
IF NOT EXISTS, SAVEPOINTSupportedNone

Rejections fall into three kinds. InvalidArgument means the statement is wrong. NOT_IMPLEMENTED means the design accepts it but it is not built yet (it may work in a later version). UNSUPPORTED means the structure cannot accept it (updating a tuple key, float, and so on).

In the Sandbox

ItemValue
DataIn the tune namespace: 100,000 rows in customers, 2,000,000 rows in orders, 3 rows in grade_cd. Same distribution as the other DBs (common lab environment)
Accountsbx_run with the readonly role. Only SELECT, ANALYZE, and BEGIN/ROLLBACK
ExecutionFor each request, BEGIN READ ONLY ISOLATION LEVEL REPEATABLE READ … ROLLBACK. For each statement, it fetches the rows once and the step statistics once through ANALYZE
Execution plan tableOne step line of ANALYZE is one row. Starts = opens, A-Rows = matched, Buffers = pages

Configuration and Inspection

-- Tables, indexes, columns (in the admin tool; the sandbox blocks the sys views)
SHOW TABLES;
SHOW INDEXES;
DESCRIBE orders;

-- What one statement actually did
ANALYZE SELECT * FROM orders WHERE ord_id = 42;

-- Cumulative cost per statement shape (calls, time, pages read)
SELECT fetch_id, kind, calls, total_us, rows_examined, pages, shape_text FROM sys.statement_stats;

NOTE KDBS is an engine under development, and its wire protocol and SQL surface have changed over time. This document is based on v3.4.17-178. Where it differs from the manual (ckdbs/manual/sql/sql.md), it follows the behavior measured in the sandbox (for example, the manual says joins reject SELECT *, but this version accepts it).

Related pages