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:

// Row-oriented representation: Struct of Arrays (SoA) violation struct OrderRecord { order_id: u64, // 8 bytes customer_id: u64, // 8 bytes timestamp: i64, // 8 bytes shipping_addr: [u8; 64], // 64 bytes item_count: u32, // 4 bytes price_cents: u64, // 8 bytes // Total: ~100 bytes per row };

When an analytical aggregation query executes:

SELECT SUM(price_cents) FROM orders WHERE timestamp > 1700000000;

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.

// Columnar storage: Contiguous Array layout pub struct ColumnChunk { pub null_mask: BitVec, // 1 bit per element (0.125 bytes) pub data: ContiguousBuffer, // Contiguous packed primitive values pub row_count: usize, }

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:

// Naive representation: 16 bytes per element due to 8-byte alignment! struct NullableInt { value: i64, // 8 bytes is_null: bool, // 1 byte + 7 bytes alignment padding = 8 bytes }

In mini-columnar-engine, nullability is decoupled into a bit-packed 64-bit word bitmap (BitMask):

pub struct BitMask { words: Vec<u64>, // Each u64 tracks 64 contiguous rows } impl BitMask { #[inline(always)] pub fn is_valid(&self, row_idx: usize) -> bool { let word = self.words[row_idx >> 6]; (word & (1u64 << (row_idx & 63))) != 0 } }

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:

Dictionary: [0] = "COMPLETED" [1] = "PENDING" [2] = "REFUNDED" Column Vector (Surrogate IDs): [0, 0, 1, 0, 2, 0, 1, 0, 0, 2] --> Stored as contiguous u8 or u16 integers!

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:

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:

// Zero-hash-table direct accumulation pub fn aggregate_sum_direct(surrogates: &[u32], values: &[i64], acc: &mut [i64]) { for (&s, &val) in surrogates.iter().zip(values.iter()) { acc[s as usize] += val; // Single array index instruction, no hash overhead! } }

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.

OperationArchived estimate
Contiguous i64 scan + sum0.253 ms (~3.96B elements/s)
Direct-indexed grouping1.025 ms
Owned-string HashMap grouping16.806 ms
Borrowed-string HashMap grouping30.223 ms

For full Rust source code, unit test suites (32 passing tests), and Criterion benchmark suites, inspect the public repository on GitHub.