๐Ÿ—„๏ธ

ColumnarDB

Analytical Query Engine in C++17

A from-scratch columnar database with SIMD-accelerated vectorized execution

C++17 AVX2 SIMD MVCC B+ Tree Index Volcano Executor SQL Parser
5.4 GB/s
SIMD Scan Throughput
3.0ร—
Alloc Speedup
1024-row
Vector Batches

github.com/sidx007/ColumnarDB

Overview

What is ColumnarDB?

ColumnarDB is a complete analytical query engine built from scratch in C++17. It covers every layer โ€” from a hand-written SQL parser down to custom memory allocators โ€” with a focus on squeezing performance out of modern hardware.

SQL Compiler

Recursive-descent parser โ†’ AST โ†’ cost-based query planner with selectivity estimation, index selection, and join reordering.

Vectorized Executor

Volcano-model iterator with 1024-row batches. Operators: SeqScan (AVX2), IndexScan (B+ Tree), Filter, Aggregate, HashJoin.

Columnar Storage

RowGroups of 64K rows. Columns stored with Dictionary/RLE compression and 1-bit-per-row Null Bitmaps.

Concurrency

MVCC with Snapshot Isolation. Epoch-based GC. B+ Tree with hand-over-hand locking for concurrent reads.

Architecture

Stack Layers

SQL Interface โ€” Lexer (FSA) โ†’ Recursive-Descent Parser โ†’ AST
โ†“
Cost-Based Query Planner โ€” Selectivity Estimation ยท Index Selection ยท Join Reordering
โ†“
Vectorized Volcano Executor
SeqScan (AVX2) IndexScan (B+Tree) Filter Aggregate HashJoin
โ†“
Table ยท RowGroup ยท Column ยท Null Bitmap
B+ Tree Index
Lock-Free Reads
MVCC + Epoch GC
Snapshot Isolation
โ†“
Custom 64B-Aligned Slab Allocator โ€” eliminates malloc contention
Benchmarks

Performance Numbers

Scan Throughput โ€” 10M rows

Equality Scan โ€” Scalar3.3 GB/s
Equality Scan โ€” AVX25.4 GB/s
Range Scan โ€” Scalar2.7 GB/s
Range Scan โ€” AVX24.6 GB/s

Allocator โ€” 100k cycles

SizeSlabmallocSpeedup
32 B5.97 ms9.94 ms1.7ร—
512 B10.35 ms30.57 ms3.0ร—

Query Latency โ€” 100k rows

QueryLatency
Full Scan25.78 ms
COUNT Aggregate8.85 ms
GROUP BY SUM20.27 ms
Usage

SQL Interface

ColumnarDB exposes a SQL interface that covers CREATE, INSERT, SELECT with WHERE filters, GROUP BY aggregations, and JOINs โ€” all executed through the vectorized pipeline.

Build with CMake, runs on x86_64 with AVX2
Extensive test suite โ€” 100k+ assertions
Separate micro-benchmark binaries for scan and query latency
No external dependencies โ€” standard C++17 + CMake only
-- Create and populate CREATE TABLE sales ( id INT, region VARCHAR(50), amount DOUBLE ); INSERT INTO sales VALUES (1,'North',450.50); INSERT INTO sales VALUES (2,'South',1200.00); -- Vectorized aggregation SELECT region, SUM(amount), COUNT(*) FROM sales WHERE amount > 400 GROUP BY region;