All projects

smuSQL

In-memory database with specialised data structures optimised for specific query patterns, featuring custom implementations of TreeMap, LFU cache, and chunked storage

Team, 20243

Why

A project for a data structures and algorithms module. Databases rely on general-purpose storage structures; this asks what happens when you swap in one tuned for a single kind of query.

How it works

It is a console program that understands a small subset of SQL. The table's name picks its storage: three implementations sit behind one interface, so the very same statements can be run against all three and compared.

Follow a table operation

A SQL statement enters through the console.

same SQLConsoleA small subset of SQLEngineParses, then picks storage by table nameEvaluatorSequential, skewed and range workloadsChunk tableBlocks of 128 rowsForest tableA sorted map per columnLFU tableA cache over a list

Decisions

Storage chosen by the table's name

Extending the SQL syntax would have been cleaner. Encoding the choice in a name prefix let the evaluator run identical statements against all three tables with no special cases.

Blocks with a bitmap

Deleting a row is clearing one bit, and nothing moves until a third of a block is dead. That keeps deletes cheap and scans dense, at the price of occasional tidying.

A skew that looks like real traffic

Uniform random keys flatter every structure equally. I wrote a generator that draws keys so a few are far more popular than the rest, which is the pattern the cache was built for.

What the measurements did not settle

Our two benchmark runs disagreed about the forest table: one ranked it fastest, the other slowest at every size. There was no warm-up phase, so I would not quote either as a result. Next time I would fix that before anything else.

My part

A team of five. I wrote the chunk table, the shared table interface, the data types and the skewed-key generator, and started the engine and the evaluator. About half of the 71 commits are mine.

Built with

SQL engine
  • Java
Benchmarks
  • Python
  • pandas
  • Matplotlib