Architectural Overview
A Parquet/DuckDB-style columnar execution engine implementing Dictionary + Run-Length Encoding (RLE), Row-Group Zone-Map (min/max) pruning, and late-materialization direct compressed predicate evaluation.
In production relational and analytical database systems—spanning PostgreSQL, SQLite, MySQL/InnoDB, and DuckDB—understanding how query clauses, schema constraints, index structures, and storage engines execute under the hood separates surface-level query authors from staff-level database engineers. This capstone build lab guides you through implementing Columnar RLE/Dictionary Encoder with Zone-Map Predicate Pushdown from first principles with deterministic self-test invariants.
Guided Implementation Walkthrough (4 Progressive Steps)
Step 1: Dictionary + Run-Length Encoding (RLE) Compressor
- Core Database Concept: Mapping Strings to Integer Codes and Collapsing Contiguous Runs into (code, length) Pairs
- Target Module:
index.js(ColumnarQueryEngine.encodeDictionaryRle) - Engineering Specification: Implement
encodeDictionaryRle(values)returning{ dict, runs: [{ code, count }] }. - Implementation Hint:
Assign integer codes in dictionary array and collapse consecutive identical values into { code, count }. - Verification Invariant: deterministic assertion verified in
test.jsstep 1
Step 2: Row-Group Zone-Map (Min/Max) Builder
- Core Database Concept: Storing Per-Block Min/Max Statistics in Columnar Footers
- Target Module:
index.js(ColumnarQueryEngine.buildRowGroups) - Engineering Specification: Implement
buildRowGroups(rows, groupSize, statCol)to partition rows into fixed-size row groups annotated with{ min, max, count, rows }. - Implementation Hint:
Chunk rows into blocks of groupSize and record min/max per numeric column in each row group. - Verification Invariant: deterministic assertion verified in
test.jsstep 2
Step 3: Zone-Map Row-Group Pruning Scan
- Core Database Concept: Skipping Entire Row Groups Whose [min, max] Interval Is Disjoint From the Query Range
- Target Module:
index.js(ColumnarQueryEngine.scanWithZoneMaps) - Engineering Specification: Implement
scanWithZoneMaps(rowGroups, statCol, minVal, maxVal)to prune non-overlapping row groups before inspecting rows. - Implementation Hint:
Skip any row group where rg.max < minVal || rg.min > maxVal; track groupsScanned and groupsSkipped. - Verification Invariant: deterministic assertion verified in
test.jsstep 3
Step 4: Direct Compressed RLE Count Without Decompression
- Core Database Concept: Vectorized Aggregation Directly on Compressed Run Headers
- Target Module:
index.js(ColumnarQueryEngine.countCompressedEquals) - Engineering Specification: Implement
countCompressedEquals(encodedCol, targetVal)to count matching tuples directly from the RLE runs in time without decompressing individual rows. - Implementation Hint:
Look up targetVal in dict; if missing return 0, else sum run.count where run.code === targetCode. - Verification Invariant: deterministic assertion verified in
test.jsstep 4
Relational & Storage Engine Guarantees
- Curriculum Domain: Columnar OLAP & Modern Engines
- Difficulty & Time Budget: Advanced (~40 minutes)
- Key Architectural Highlights:
• Dictionary + Run-Length Encoding (RLE) compressing sorted low-cardinality columns by 10x–50x
• Row-Group Zone-Map (min, max) metadata pruning skipping irrelevant row groups without decompression
• Direct predicate evaluation over RLE runs and late materialization of projected attributes - Core Primitives & Tags:
Columnar Storage,Run-Length Encoding,Dictionary Encoding,Zone Maps,Late Materialization
Related Curriculum Units
- columnar storage layout parquet
- columnar compression rle dictionary delta
- late materialization simd vectorization
- zone maps min max pruning bloom
- embedded olap duckdb architecture
Production Database Context & Verification
This from-scratch relational engine component is engineered with zero external dependencies and deterministic verification harnesses. Every internal database invariant—from three-valued logic (TRUE / FALSE / UNKNOWN), referential integrity, and fan-out-free join pre-aggregation to B+Tree page splits, MVCC snapshot visibility (xmin / xmax), slotted-page compaction, and ARIES write-ahead log crash recovery—is asserted directly in test.js. Use the interactive browser workbench above to complete the 4 guided steps in Guided Lab mode or inspect and benchmark the complete reference architecture in Full Solution mode.