About

KvSQL is a hybrid of key-value and SQL in Rust. It comes as two products built on one set of records. KvSQL Engine is a library you embed in your program: one file on disk, no server. KvSQL DB is a database server, kvsqld, and a shell, kvsql, built on the same engine.

Why It Exists

Many programs need two things from their data. They need fast lookups by key, thousands of times a second, and they need real questions answered: totals, filters, joins. The usual answer is two stores, a key-value store such as RocksDB or Redis for the lookups and SQLite for the questions. The data then lives twice. Code has to keep the two copies in step, and a change can’t be atomic across both.

KvSQL keeps one copy. A row read by key comes straight from the storage tree, without parsing or planning anything. SQL about the same rows goes through the parser and planner and reads the same bytes. One transaction covers both, and secondary indexes stay right whichever door wrote the row. How it works explains the design in plain words.

What Ships in 0.1.0

  • The engine. A copy-on-write B+tree per keyspace in a single file, two alternating meta pages, snapshot readers that never wait for the writer, and one writer at a time. It has no dependencies beyond the Rust standard library.
  • SQL on the same records. CREATE TABLE and INDEX, INSERT, UPDATE, DELETE, and SELECT with joins, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT and the common functions, with SQLite’s rules for NULLs, numbers and comparisons between text and numbers. The reference lists what is in and what isn’t.
  • The server and the shell. kvsqld serves one file over HTTP with JSON. Each request is one transaction, and a write is answered only after it is on disk. kvsql talks to the server or opens a file directly.
  • Binaries for Linux, macOS and Windows on the download page.

How the Project Works

  • Test the promise, then make it. The main promise is that a commit that returned is never lost and a crash leaves either the whole commit or none of it. The tests aim at exactly that: how it was tested.
  • Every number has its conditions. Figures on this site come from the project’s recorded test runs, which are kept in the repository with the machine they ran on. The benchmark against SQLite shows where SQLite is faster too.
  • An independent review before a release. Before 0.1.0, a separate reviewer that hadn’t seen the code went through it looking for bugs. Every confirmed finding was fixed and tested before release.
  • Releases are built by CI. A release goes out only when every build passes its tests and a smoke test on its own platform.

License

KvSQL Engine and KvSQL DB are open source under the Apache License 2.0. The code, the issue tracker and the releases are on GitHub. KvSQL is a SoftDevStudio.com project.