APAaryan Patel

case study · systems · C++17 · dependency-free

columnar-engine

A vector-at-a-time analytical engine. The useful benchmark is not where vectorization wins. It's where the crossover happens, and why.

rows per second on TPC-H Q1, 1,024-row batches, median of five
53.1M
differential assertions, vector against an independent scalar reference
6,288
best speedup on the chained filter + group-by pipeline
1.94×
at 1,000 rows the vector path is slower: the mask costs more than it saves
0.87×
runs in your browser · the operator's semantics on a 32-row batch

Mask, then compact. Watch NULL never match.

A JavaScript rendition of the engine's two-phase filter: compare a contiguous column into a byte mask, respecting the validity bitmap, then compact true lanes into row IDs. The second predicate walks only the surviving IDs. An independently written row-at-a-time loop checks every result, like the repo's differential oracle.

WHERE region =
batch size
selection vector after region
after revenue, walking only those IDs
group_sum(revenue) by region
scalar reference, written separately
measured crossover · chained filters + grouped sum · Apple M2 Pro · median wall-clock■ scalar   ■ vector

Hover or tap a configuration.

how it works

Selection vectors, not copied rows.

Filters return 32-bit physical row IDs. The next operator walks only those rows, input order is preserved, and every incoming ID is bounds-checked: a corrupt selection is an error, not an out-of-bounds read.

Validity bitmaps

Nullness lives beside the values, one bit per row packed into 64-bit words, so value arrays stay dense and typed. A comparison with NULL is unknown, and unknown is never selected. Inner joins never match null keys, not even null against null.

Why the vector path can lose

Each batch writes a byte mask, then rereads it to compact. That gives the compiler a straight numeric loop to vectorize, and it's also a cost a scalar loop never pays. At small inputs or very selective scans, the mask costs more than it saves. Both sides are reported.

TPC-H Q1, fused

The vector executor builds one validity/predicate mask per batch, then updates all six aggregate states in a single pass, without materializing an intermediate table.

measured · Apple M2 Pro, Apple Clang 17
TPC-H Q1 at one million rows, median of five
executortimerows/s
tuple-at-a-time23.51 ms42.5M
vector, 1,024 rows/batch18.85 ms53.1M

That's 1.25×, smaller than the filter pipeline's best. Q1 spends more time on arithmetic and hash-table work per surviving row, so scan dispatch is a smaller share of the total.

Differential verification
checkresult
correctness assertions6,288
random filter/aggregate trials120
random join trials100
batch sizes per filter trial1, 7, 64, 1,024
scalar/vector disagreements0
where it stops holding

Vectorization is a trade, and the table shows both sides.

  • Small inputs loseAt 1,000 rows the vector path runs at 0.87× and at 10,000 rows with 7% survival at 0.93×. The mask and compaction pass cost more than they save.
  • Selective scans cross over lateAt a million rows with 7.4% survival the gain is only 1.10×. Few surviving rows leave little work to amortize the mask over.
  • Q1 gains less than filters1.25× on TPC-H Q1 against 1.94× on the filter pipeline, because arithmetic and hashing dominate once rows survive.
  • One core, one machineSingle-threaded medians on an M2 Pro. No parallel scan, no SIMD intrinsics written by hand: what the compiler auto-vectorizes is what you get.
reproduce
git clone https://github.com/asp53826/columnar-engine
cd columnar-engine
make test       # 6,288 assertions
make benchmark  # CSV, then the Q1 result