Reading — step 1 of 5
Read
~1 min readWhy Columnar
Vectorized Execution
Row-at-a-time execution:
python
Each iteration: branch prediction, virtual function dispatch, cache miss. Slow.
Vectorized execution processes BATCHES (e.g., 1024 rows at a time):
python
Why faster?
- Tight loops, no virtual dispatch.
- Branch predictor wins on predictable comparisons.
- CPU prefetcher kicks in.
- SIMD: SSE/AVX/NEON instructions process 4-16 values per cycle.
Modern engines (DuckDB, ClickHouse, Photon in Databricks) use vectorized + push-based pipeline:
File Reader -> [batch1] -> Filter -> [batch1'] -> Aggregate
-> [batch2] -> Filter -> [batch2'] -> Aggregate
...
Each operator processes batches. Less overhead than tuple-at-a-time.
Push vs pull:
- Pull (Volcano): operator calls
next()on child for each tuple. - Push: child pushes batch to parent.
Push is more cache-friendly: parent processes batch fully before getting next.
Compilation:
- LLVM JIT to compile query plan to native code (HyPer, MonetDB, ClickHouse).
- Removes interpretation overhead entirely.
Modern column stores combine: vectorized batches + JIT-compiled hot loops.
Latency hides cost via large batches; small queries don't benefit. OLAP-only.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…