The Engine

The engine is the software: the code that writes records, finds them again, keeps them safe through a power cut and answers questions about them. AltSql’s engine is a native hybrid of key-value and SQL. It has two ways in, designed together, and both reach the same records.

Two Doors, Built Together

  • Get/put, the direct door. A read or write by key goes straight to the record: one walk down the store, with no SQL parser or planner in between. In the Alpha’s speed tests, reads by key never entered SQL code at all, checked under a debugger.
  • SQL, the asking door. SQL reads a question, plans it and turns it into walks and scans over the same records: a lookup by key, a range, a time range across a whole fleet, GROUP BY, UPDATE and DELETE.
  • One set of transactions. A put and a SQL statement can sit in the same transaction, so related changes are saved together or not at all.
  • The same rules. The same code checks types and keys whichever door a change comes through.

Small Enough for Both Ends

Where What the engine does there Size
On the device The key-value door: readings and settings kept as records in flash, read back to decide on the spot, and sent on to the gateway as they are About 15 KB of code as compiled for a Cortex-M4. The demo devices use 672 to 1,048 bytes of engine RAM, plus up to 1.4 KB of stack
On the gateway Both doors, onto one store that holds a whole fleet 166,667 bytes of code at -O2 with both doors, about a sixth of SQLite’s 982,281 (computed from the measured sizes). It can open in 38 KB of memory, with small pages

It never calls malloc: the program hands it one block of memory when it starts. It’s written in C99, and a program links in one file per part.

Built for Power Cuts

On a device, the power was cut 400,000 times in one simulated run, and nothing saved was lost. On the gateway, a cut at every write of a run, 3,354 cuts in all, left the file at the last commit or at the one under way, every time.

How Fast

In the Alpha, measured in simulation on a PC, a read by key on the gateway ran 5 times as fast as SQLite answering the same read through SQL, and 100,000 random SQL statements gave the same answers as SQLite. SQLite is still faster on some questions that read a whole table, and the Alpha reports say which.

Where It Stands

Everything here runs on a PC, with chips, links and files simulated. Real hardware comes next, in the Beta. The database page says how the records are kept, the native hybrid explains why the two doors matter, and the modules build on this engine for particular jobs.