HoloDb, an embedded SQL database for .NET
A SQL database for .NET that builds structures from the queries it serves and drops those that stop paying.
Every SQL statement is answered exactly, with ACID and no index to design.
dotnet add package EvaluatedApplications.HoloDbCommercial licence for commercial use. Evaluation and non-commercial use are permitted.Licence terms
What you can build
Each one is in the package today.A store that tunes itself to its workload
A paged table keeps exact per-column totals and zone maps beside its data, and a bulk-loaded analytic table also keeps per-value counts. Every other structure is built only when repeated queries have paid for it, and dropped when the workload moves on or when a write would make it cost more than it saves. There is no index to design.
Exact aggregates, some read from a stored total
One copy of the data answers a lookup by key in ordinary SQL, similarity search with NEAREST, and exact aggregates, some of which read a stored total or count instead of scanning. INT sums are 128-bit running totals.
Similarity search in one statement
NEAREST ranks rows by how closely they match a partial description, in the same SQL. It ranks exactly on small tables and approximately above a size threshold.
Exact decimals
DECIMAL(p, s) columns with up to 18 digits are stored as scaled integers. +, -, * and / are exact, rounding half away from zero, and an overflow or a division by zero is refused with its SQLSTATE code.
A database that survives a power cut
START TRANSACTION, COMMIT and ROLLBACK run over a write-ahead log with group commit: a statement that has returned is on disk. A rollback or a power cut leaves the table as it was.
Look back with AS OF
Read a paged table as it was after any commit the history still holds, and fingerprint it with Seal so replicas can compare.
Tables bigger than memory
Paged tables read through a buffer pool of 8 KB pages, with a logical block map and a CRC-32C checksum on every log block and data page.
Apply a batch of changes atomically
ApplyChanges applies a batch of upserts and deletes atomically on in-memory tables. KeyDigest compares two key sets, and Seal fingerprints a table so replicas compare.
Real SQL NULL on paged tables
Declare a column NULL and it holds true nulls with three-valued logic. A statement that names a nullable column takes an exact path that reads only the columns it names.
Run it yourself
Create a service, run some SQL and read the rows back.dotnet add package EvaluatedApplications.HoloDbdotnet add package EvaluatedApplications.HoloDb.Clientdotnet add package EvaluatedApplications.HoloDb.Protocolusing HoloDb;
var db = new HoloDbService(new HoloDbOptions());
db.Execute("CREATE TABLE users (id INT PRIMARY KEY, age INT, name TEXT)");
db.Execute("INSERT INTO users VALUES (1, 30, 'Ada')");
var result = await db.ExecuteAsync("SELECT name FROM users WHERE age >= 18");
foreach (var row in result.Rows) Console.WriteLine(row["name"]);
// AdaAdaA WalPath in the options makes the database durable. For a database whose tables can be larger than memory, set both WalPath and Paged = true. Paged = true without a WalPath throws.
Similarity search in one statement. NEAREST ranks the rows by how close they are to the description.
using HoloDb;
var db = new HoloDbService(new HoloDbOptions());
db.Execute("CREATE TABLE products (id INT PRIMARY KEY, category TEXT, price INT)");
db.Execute("INSERT INTO products VALUES (1,'electronics',100),(2,'electronics',120),(3,'furniture',300)");
var near = db.Execute("SELECT id, category, price, score FROM products NEAREST (category = 'electronics', price = 118) LIMIT 2");
foreach (var row in near.Rows) Console.WriteLine($"id={row["id"]} category={row["category"]} price={row["price"]} score={row["score"]:F3}");
// id=2 category=electronics price=120 score=0.993
// id=1 category=electronics price=100 score=0.988id=2 category=electronics price=120 score=0.993
id=1 category=electronics price=100 score=0.988What it is, and how it learns
HoloDb is an embedded SQL database for .NET. You create tables and write SQL. Tables are typed columns, in memory or on disk. The answer to every SQL statement is exact; NEAREST ranks exactly on small tables and approximately above a size threshold. A paged table keeps exact per-column totals and zone maps beside its data, and a bulk-loaded analytic table also keeps per-value counts. Every other structure is built only when repeated queries have paid for it, and dropped when the workload moves on or when a write would make it cost more than it saves.
SQL is the standard dialect by default. Vendor spellings are opt-in with Dialect = SqlDialect.Extended, and a statement that uses one under the default is refused by name.
One copy of the data answers three kinds of question: a lookup by key in ordinary SQL, similarity search with NEAREST, and exact aggregates, some of which read a stored total or count instead of scanning (the shapes are listed below). Everything the engine builds is derived from the columns, so losing a derived structure costs time and never data.
Three terms recur on these pages. A block is a run of rows stored together. A page is 8 KB of file. A pin is one page read through the buffer pool, and counts of pins stand in for time.
SET indexes and SET summaries choose whether automatic indexes and summaries are built (auto), only declared ones are kept (declared), or none answers a query (off).
Learned records that stay right when rows change
For a filter you ask for often, the engine writes a card for each block of rows: how many rows match, and the exact sums of the columns you total. The next time you ask, it reads the cards and opens only a block whose card a write has touched. When an UPDATE or DELETE changes rows, or consolidation moves them, the cards are corrected by the exact difference. They are not thrown away. Each card carries its own checksum and is checked when it is read, so a wrong card is dropped and relearned and never changes an answer.
Totals, zone maps and value counts are built at load
These three structures are not learned. A bulk load builds them. Per-column totals hold the row count, the exact sum, the minimum and the maximum, and every write keeps them current. Zone maps record the lowest and highest value of each integer-like column in each block. Value counts record the exact number of rows per value of a column; they are saved when the table is closed cleanly, and a column whose values are nearly all distinct has none. A whole-table COUNT, SUM, AVG, MIN or MAX of a numeric column with no WHERE is read from the totals. COUNT(DISTINCT col), and GROUP BY col with COUNT(*) and at most the filter col <> 0 or col <> '', are read from the value counts while they match the table. A write makes the value counts unusable until the next clean close, and a missing file is not rebuilt. Any other shape reads rows.
A ski-rental ledger decides what to build and what to drop
Renting skis is cheap for one weekend and buying wins after enough weekends. The engine keeps that ledger for every structure the planner builds from the workload. Each scan that a structure would have saved is rent. The structure is built when the rent paid has reached the cost of building it, and dropped when the cost of keeping it up through writes exceeds what it saves. The cost of keeping a structure up is the time its delta path takes on the machine it runs on, measured per write and averaged, never an assumed rebuild per write.
Gather, regroup and placement lay rows out by what reads waste
If the rows a filter wants are scattered over the whole table, every repeat reads many blocks to find a few rows. The engine measures that waste for each learned filter. Gather moves matching rows next to each other when the time saved by repeats is larger than the cost of the move. Regroup rewrites the whole layout once, when gather alone cannot reach it. Placement puts a newly written row in a block the repeated filters already read. A repeat that the stored counts and sums already answer reads nothing, so it pays no rent and nothing is moved.
A paged store with a logical block map
Paged tables are larger than memory. They read through a buffer pool of 8 KB pages. Every page has a logical number, and a map takes that number to a place in the file. The map changes only inside a committed log batch. A moved or rewritten page therefore never leaves the file half-changed, and a shrunk table keeps its freed pages and refills them. Every log block and every data page carries a CRC-32C checksum. A page that fails its checksum is an error that names the page, never a changed answer.
ACID with crash-tested recovery
START TRANSACTION, COMMIT and ROLLBACK (BEGIN under Extended) run over a write-ahead log of signed page deltas in a ring file whose size follows the largest recent batch, with group commit: a statement that has returned is on disk. A failed statement inside a transaction undoes only itself. A transaction larger than the buffer pool spills to a scratch file, and a rollback or a power cut leaves the table as it was. Each commit is kept as a signed record within a retention budget, so SELECT ... FROM t AS OF n reads a paged table as it was after commit n for any n the history still holds, and Seal(table, asOf: n) gives an order-free fingerprint that replicas can compare.
Real SQL NULL on paged tables
Declare a column NULL and it holds true nulls with three-valued logic, on paged tables as well as in memory. A statement that names a nullable column takes an exact path that reads only the columns it names. COUNT(col), SUM, AVG, MIN and MAX skip nulls, GROUP BY makes one null group, and a join never matches one. Null counts are maintained.
Exact decimals
DECIMAL(p, s) with up to 18 digits is stored as a scaled integer. +, -, * and / are exact, rounding half away from zero, and an overflow or a division by zero is refused with its SQLSTATE code. Results come back with their scale.
Everything in the package
SQL, Standard (the default)
The SQL a first user reaches for: joins of every kind with table aliases, WITH, UNION, INTERSECT and EXCEPT, scalar, IN and EXISTS subqueries (correlated ones too), window functions with frames, CASE, CAST, the standard scalar and aggregate functions, NULL with three-valued logic, SELECT without FROM, DROP TABLE, TRUNCATE, information_schema, CREATE TABLE ... AS SELECT, INSERT ... SELECT, UPDATE with expressions, exact DECIMAL(p, s) columns, and ImportCsv for files. Also CREATE TABLE, ALTER TABLE ... ADD COLUMN, CREATE SUMMARY TABLE, SET summaries and SET indexes, SHOW SUMMARIES, DELETE, COUNT(DISTINCT), WHERE with AND, OR, NOT, LIKE, IN, BETWEEN, IS NULL and IN (SELECT ...), GROUP BY, HAVING, ORDER BY, FETCH FIRST n ROWS ONLY, NEAREST, and START TRANSACTION, COMMIT and ROLLBACK.
SQL, Extended (Dialect = SqlDialect.Extended)
LIMIT, ILIKE, CREATE INDEX (sorted, summary, keyed) and DROP INDEX, SHOW INDEXES, EXPLAIN, IF [NOT] EXISTS, INSERT ... ON CONFLICT ... DO UPDATE, BEGIN, DESCRIBE, and the vendor functions. A statement that uses one under Standard is refused by name, with SQLSTATE 0A000.
Exact
INT sums are 128-bit running totals and throw only past 64 bits. DECIMAL(p, s) holds up to 18 digits exactly. Empty selections give NULL for SUM, AVG, MIN and MAX, and 0 for COUNT.
Built at load
Per-column totals, zone maps (which skip blocks and bound top-k) and, for bulk-loaded analytic tables, value counts. Writes keep the totals current; a write makes the value counts unusable until the next clean close.
Learns by use
Summaries, sorted and keyed indexes, a tree of exact sums, learned block records with exact partial sums, learned routes, text predicate records, gather and placement. The planner's structures share one budget, which is a hard cap.
Inspection
EXPLAIN reports the route of a statement without running it. For in-memory tables and older paged tables it names the route and the structure that answered, or the reason none did. For an analytic table it does not report which stored structure answered.
Look back
AS OF n and Seal(table, asOf: n) on paged tables.
Analytic SQL
Narrow column types, dictionary-coded text, CASE, CAST, EXTRACT, positional GROUP BY and ORDER BY, and COUNT(DISTINCT) on large cardinalities. With Dialect = SqlDialect.Extended, also DATE_TRUNC and REGEXP_REPLACE.
Change feeds
ApplyChanges applies a batch of upserts and deletes atomically on in-memory tables. KeyDigest compares two key sets in modulus numbers. Seal fingerprints a table so shards add and replicas compare.
Aggregate plane (optional)
An exact derived summary of small-domain columns, served through Phasor's Pleroma stores, with PleromaVerify to check it against the columns.
Metering
MeteredDatabase reports the rows and bytes each query read.
Statement limits
A statement can carry a cancel token, a deadline and a result byte budget. A stopped statement has no effect, and a statement the budget refuses is refused before the rows that would pass it are allocated.
Integration
services.AddHoloDb() for dependency injection, and an EvalApp context for pipelines.
Know before you start
What HoloDb does not do, and where to be careful- Scale: the correctness suites run to 3,000,000 rows in both pipeline modes. Larger tables work; the lifecycle and crash guarantees are tested at 3,000,000 rows.
- Writers: one. Simple selects read without the lock and retry if a write overlaps them; writes, DDL and transactions take one lock at a time.
- Statement budget: the budget estimates each cell (8 bytes for INT and REAL, 48 for the others) and charges the working rows of a join before its WHERE is applied, so a large join can be refused although its filter would keep few rows.
- Joins: INNER JOIN runs on the engine's join routes (one per statement on a paged table). LEFT, RIGHT, FULL and CROSS joins run on the row engine, under its memory budget. A join over a paged table with NULL columns runs with SQL NULL rules: a NULL key never matches, and aggregates skip NULL cells.
- SQL not offered: NATURAL JOIN, WITH RECURSIVE, GROUP BY ROLLUP, CUBE, GROUPING SETS or ALL, QUALIFY, the WINDOW clause, DISTINCT ON, LATERAL, DROP COLUMN, column rename, and CREATE INDEX ... USING NEAREST. UPDATE ... SET takes an expression on its right side.
- Dialect: Standard by default. Vendor spellings (LIMIT, BEGIN, ILIKE, CREATE INDEX, EXPLAIN and others) need Dialect = SqlDialect.Extended, and are refused by name under Standard.
- NEAREST: does not combine with GROUP BY, with a join on a nullable table, or over a table with a decimal column. It ranks exactly on small tables and approximately above a size threshold.
- Keys and types: one primary key per table, INT or TEXT. Types are INT, TEXT, REAL and DECIMAL(p, s) with up to 18 digits, with narrow integer, date, timestamp and fixed-width text types on analytic tables.
- Decimal columns: literals, columns, expressions, WHERE on SELECT, aggregates, GROUP BY and HAVING work on in-memory and paged tables. Joins, NEAREST, Seal, AS OF, host bulk loads, ApplyChanges and KeyDigest refuse a table that holds a decimal column.
- In-memory only: ApplyChanges and the SQL upsert (Extended) run on in-memory tables. A paged table refuses them.
- Row order: without ORDER BY, the order of rows is unspecified and can change after a DELETE or a write that moves a row.
- Structures: they help repeated work. A filter whose matching rows are spread evenly over every block gains nothing from learned records. The first lookup of a value no earlier read has seen is a scan, except a text value absent from the column or a number outside its range, which read no block. Moving scattered rows costs time per row moved, so a scattered filter pays it back only after repeated use.
- Older data: table records of format 13 and older, older write-ahead logs, and a text-format database opened as paged throw a named error that says to export the rows and load them into a new database. Format 14 stores open and are written as format 15 on their next catalog write. A build from an earlier release refuses stores written by this release. There is no in-place upgrade.
- History: AS OF works on paged tables and reads sequences the history still holds. A sequence below the floor, inside a retained segment, or on an in-memory table is refused by name, as is a join under it.
Evidence
How it is testedA wrong answer is the one failure a database cannot afford, so the tests try to make HoloDb wrong and report the first time it is. A battery of specs runs in both pipeline modes, checks have mutant arms, a deliberately broken engine that the check must catch, chaos runs compare every answer with SQLite, and a customer lifecycle test works one database across many separate processes, reopening it after every session.
Related
Licence
Proprietary. Every package ships as a compiled library. Evaluation and non-commercial development or testing are permitted; commercial, production or revenue-generating use needs a commercial licence from the owner. Read the licence terms.