By Dmitriy · · 10 min read

How we built a local SQL engine for DynamoDB

DynamoDB can export a 100 GB table, but it cannot aggregate one. It has no JOIN and no GROUP BY. A Query or with Select=COUNT returns the number of matches observed on one page. You add those counts yourself.

, AWS's own SQL-like interface, does not add them. So teams write the same throwaway script again and again: paginate a Scan, fold rows into a map, print the answer, delete the script.

DynoTable's Workbench replaces that script. It is a tab where you write one SELECT with multi-table JOIN … ON, WHERE, GROUP BY, HAVING, DISTINCT, CASE and aggregates.

The SQL Workbench now also runs joins on non-key attributes, CTEs, subqueries, and window functions. The preview shows how a query will read, and the results indicate when a read is still in progress.

This post covers how it works, the first compiler that returned wrong answers without an error, and why we later replaced the engine's memory model.

We compile SQL onto an engine that already exists

The core decision was to not write a relational executor. DynamoDB pages stream into an embedded SQLite database, and SQLite does the relational work. Our code is the compiler between your SQL and that engine.

which tables,which join keysrewritten SQLYour SQLCompilerDynamoDBpage streamLocal SQLiteResult grid

Each DynamoDB item lands in SQLite as its raw typed envelope, such as {"platform": {"S": "ios"}}, in a single column. A small user-defined function unwraps attributes at query time.

So your SELECT platform compiles to a call to that function. The function catches its own JSON parse errors and returns NULL for that row.

Without the catch, the SQLite binding turns one malformed row's error into an abort of the whole statement.

At the time, a Workbench tab only supported joins it could resolve by key. A JOIN had to land on the of a table that has no , or on a partition key.

The engine resolved each join by key lookup. A join on a non-key attribute failed to compile.

DynoTable's SQL Workbench running a multi-table JOIN over DynamoDB tables, with the joined result grid below.
DynoTable's SQL Workbench running a multi-table JOIN over DynamoDB tables, with the joined result grid below.

Our first compiler returned wrong answers without an error

The first version used a popular off-the-shelf SQL parser. Within about a week, four correctness bugs piled up, and the parser blocked the fix.

Two of them lived in the emitter. That is the part of the compiler that turns each parsed node back into SQL for the local engine.

  • SELECT DISTINCT was dropped without a warning. The parser accepted it and the emitter ignored it, so every duplicate row came back. One user's bug report read: "shows a table of all the values, not counters."
  • Any unhandled syntax became the literal SQL NULL. For CASE, CAST and scalar subqueries, the emitter fell back to return 'NULL'. Queries ran, returned wrong answers and raised no error.
  • Identifier case did not behave like SQL. SELECT PLATFORM FROM t returned nulls when the attribute was platform. Standard SQL treats unquoted names as case-insensitive.
  • Autocomplete missed matching names. Typing a name in a different case found nothing, and suggestions for quoted names did not always appear.

We picked the parser that keeps the quotes

The replacement, sql-parser-cst, was the only parser we evaluated whose tree keeps both the raw text and the normalized name of every identifier. With both, the compiler can tell platform from "PLATFORM".

That one distinction gives a single grammar proper ANSI semantics. Unquoted identifiers resolve case-insensitively. Quoted identifiers are the case-sensitive escape hatch, as in Postgres.

Without it, case-insensitive lookup and correct autocomplete could not both be right. A strict match drops rows. A fully case-insensitive match removes your way to pick platform over Platform when an item has both.

The parser also attaches a source range to every node, so a diagnostic underlines the exact construct that failed.

We replaced the return 'NULL' fallback with a fixed rule. Anything the emitter does not support raises an error on that node's range. A window function gets this one:

Unsupported expression: window function. Supported: column refs, literals, arithmetic, comparison, AND/OR/NOT, IN, BETWEEN, IS NULL, LIKE, CASE, CAST, function calls, aggregates. Not yet: window functions, scalar subqueries, set operations, CTEs.

The message lists what the Workbench does support, so you can rewrite the query without guessing.

sql-parser-cst is pre-1.0. We pin the exact version and upgrade it only by hand, with the test suite as the gate.

We rejected five alternatives. Patching the old parser needed a second tokenizer to recover quote information, so every input would be parsed twice.

Reusing the editor's own syntax tree failed because that tree is token-level, with no clause structure for a compiler to walk.

Writing our own parser meant most of a SQLite parser and maintenance with no end. Waiting for sql-parser-cst 1.0 left four correctness bugs in front of users.

Restricting the Workbench to the SQL the old parser handled would have banned CASE, CAST and DISTINCT, which SQL users expect to work.

One warning deliberately does not block the query. A filter can name an attribute whose case the schema cannot confirm, because DynamoDB declares only key attributes and its server-side filters are case-sensitive.

That filter gets a warning, and warnings never stop a query from running. Our validator work taught the same lesson. A gate that rejects the most common valid query does more harm than no gate.

Buffering in memory failed on big tables or answered from part of them

The first aggregation engine buffered scanned rows into an in-memory SQLite database. The 's SQL tool capped it at 64 MB or 100,000 rows, and its transform tool at 250 MB. Hitting a cap failed the query.

The Workbench tab had no cap. It aggregated the pages loaded so far, and loading every page of a large table could run the app out of memory.

For the redesign, we asked what the throwaway script would do. A competent script streams and folds each page into a running total, so its memory stays bounded.

A GROUP BY over part of a table gives a wrong answer, and a ranking built from it puts the wrong rows first. Our own AI demo once presented a partial "top spenders" ranking as fact.

A planner streams or stores each query

For the redesign, the Workbench tab moved its pages to a disk-backed SQLite file. We also added a planner to the SQL tool for the AI agent and MCP clients. It picked between two paths:

  • Fold as it streams. Plain COUNT, SUM, AVG, MIN and MAX over one table, with every projected column in the GROUP BY. DynoTable folded each page into a running total.
  • Store, then query. Sorts, key-bounded joins and the other queries the planner could model went to a disk-backed SQLite file.

When the planner could not model a query, the tool streamed each referenced table into a SQLite file and ran the SQL there. That let the agent and MCP clients run non-key joins before the tab could. The fallback scanned every table in the query.

The fold path was deliberately narrow. A WHERE, HAVING, ORDER BY or LIMIT, a join, or a column missing from the GROUP BY sent the query to the store path.

The fold applied none of those clauses. A fold that skipped one and still reported an exact result would be the confident wrong answer this planner was designed to prevent.

Exactness is part of the result. In a Workbench tab, an aggregate carries a partial badge while pages stream, and the badge drops only when the scan has finished.

On the streaming path at the time, integer sums stayed exact past 2⁵³ because the engine stored them as 64-bit integers. The engine marked a fractional sum above 2⁵³ partial.

On the store path, a value past 2⁵³ also made the result partial.

Workbench can ask before a large Run to end. Agents have their own download budget. If a read pauses, narrow the query or have the agent retry from the start using the confirmation it received. See large reads over MCP.

At us-east-1 list prices, an on-demand scan of 1 GiB of item data costs about $0.016 with eventual consistency, or $0.033 with strong consistency, before rounding per request. A full DynamoDB export costs $0.10 per GB of table data and requires point-in-time recovery. For recurring reports, compare repeated scans with the cost of exporting once and querying the export with Athena. See AWS pricing.

SQL in the Workbench cannot write to your table

The SQL that reaches the local engine must be one read-only SELECT. Anything else is refused before it runs and treated as a compiler bug, because the compiler should never produce it.

The engine also runs with extension loading and other risky built-ins turned off. Workbench SQL has no path that writes to DynamoDB. The grid and item editor can stage edits for review. Commit actions and bulk Direct Run can write immediately.

What transfers if you're building one

  • Compile onto an engine that already exists. Your bugs will live in the seams: identifier case, type envelopes, corrupt rows.
  • Demand quote information from your parser. If it cannot tell name from "NAME", you cannot implement SQL's case rules.
  • Make unhandled syntax a loud error. A silent NULL default is how confident wrong answers ship.
  • Measure your design against the throwaway script your user would write. If the script streams and you buffer, change the design.
  • Label partial aggregates as partial. Users read an unlabeled number as the answer.

The Workbench docs cover the day-to-day feature set. SQL for DynamoDB maps what works across the whole ecosystem.

To try it, download DynoTable, open a Workbench tab with ⌘⌥B and run a JOIN against a database that does not have one.

Work with DynamoDB without the Console

A fast DynamoDB desktop client that runs the real SQL DynamoDB can’t — JOINs, GROUP BY, aggregates — with visual editing and an AI agent on your own Bedrock keys or your Claude or ChatGPT plan.

Free 30-day trial, no credit card — then the Free plan with no time limit.