1. The Memory Wall & Cache Line Mechanics
In modern computing architectures, ALU cycle speeds have outpaced DRAM memory bus latency by more than two orders of magnitude—a phenomenon known as the memory wall. When a CPU core requests an address from main memory, it stalls for approximately 50 to 80 nanoseconds (equivalent to 200–300 compute cycles) while the memory controller retrieves a 64-byte cache line into L3/L2/L1 cache.
In classical row-oriented storage engines (OLTP), a table is represented as an array of tuples:
When an analytical aggregation query executes:
The two fields account for only 16 bytes of each example record. A columnar layout can avoid reading unrelated fields during this query.
2. Columnar Memory Layout (Array of Structs vs. Struct of Arrays)
The prototype stores typed column values in contiguous buffers. The simplified layout below illustrates the separation of values and validity bits.
For a column of u64 integers, a single 64-byte cache line contains exactly eight sequential values. Sequential access can help the hardware prefetcher bring in adjacent cache lines.
3. Bit-Packed Null Representation (0.125 Bytes/Row)
A frequent source of memory bloat in naive database implementations is nullability representation. Representing a nullable value using Option<T> in Rust or a boolean flag introduces memory alignment padding:
In mini-columnar-engine, nullability is decoupled into a bit-packed 64-bit word bitmap (BitMask):
This architecture reduces null tracking overhead from 8 bytes per row down to exactly 1 bit (0.125 bytes) per row—a 64x memory savings that enables the entire validity mask for 1,000,000 rows to fit within 122 KB (comfortably inside modern L2 CPU cache).
4. Dictionary Encoding & Surrogate Integer Evaluation
Variable-length strings (such as product categories, country codes, or status flags) destroy memory alignment and prohibit SIMD vectorized operations.
Dictionary encoding is available for string columns in the prototype. A distinct dictionary vector stores unique strings, while the columnar data vector stores compact integer surrogate IDs:
Filtering on string equality (WHERE status = 'COMPLETED') converts into a single dictionary lookup to obtain surrogate ID 0, followed by an ultra-fast integer comparison across the contiguous vector.
5. Morsel-Driven Vectorized Execution (1024-Row Batches)
Rather than executing queries row-at-a-time (tuple iteration) or materializing whole-column vectors (which exhausts cache capacity), mini-columnar-engine uses morsel-driven chunked execution. Operations process batches of 1024 rows:
- 1024 rows of 8-byte integers = 8 KB (resides completely within 32 KB L1 data cache).
- Iterators produce selection vectors (arrays of active indices) rather than copying data buffers.
- Fixed-size blocks can help the compiler vectorize inner loops. Instruction selection depends on the compiler and target.
6. Direct-Indexed Array Aggregation (Eliminating Hash Tables)
In typical OLAP engines, evaluating GROUP BY category allocates a HashMap<Key, Accumulator>. Under high throughput, hash computation, bucket collisions, and cache-line misses during bucket lookups dominate execution time.
Because our dictionary encoding provides dense surrogate IDs S ∈ [0, N−1] where N is the dictionary cardinality, we eliminate the hash table completely. Aggregation allocates a simple flat array indexed directly by surrogate ID:
Direct indexing is useful when group IDs are dense and already encoded. The example above omits validity checks. Grouped results in the prototype can omit null keys and groups where every value is null.
7. Verification & Benchmark Results
Archived Criterion estimates on Apple Silicon used one million values for scan plus sum and one million rows with eight repeating keys for grouping. Dictionary construction was outside the timed grouping comparison.
| Operation | Archived estimate |
|---|---|
| Contiguous i64 scan + sum | 0.253 ms (~3.96B elements/s) |
| Direct-indexed grouping | 1.025 ms |
| Owned-string HashMap grouping | 16.806 ms |
| Borrowed-string HashMap grouping | 30.223 ms |
For full Rust source code, unit test suites (32 passing tests), and Criterion benchmark suites, inspect the public repository on GitHub.