SQL SQL In Depth
0%
Guided SQL & Engine Coding Lab

Columnar RLE/Dictionary Encoder with Zone-Map Predicate Pushdown

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.

Guided SQL & Storage Engine Lab 0/3 Steps Completed

Execute & Verify SQL & Storage Engine Invariants in the Browser SQL Studio

Complete 3 progressive relational steps with guided hints in PostgreSQL 18 WASM, SQLite 3 & Step-by-Step Relational Table Visualizer against automated result-set and query-plan assertions — zero local setup required.

01 Phase 1 · Base Relation & SARGable Predicate
Base Relation Scan & SARGable Filter (saas_telemetry)
Establish the base relation scan in saas_telemetry for Hands-On Build: Columnar RLE/Dictionary Encoder with Zone-Map Predicate Pushdown with a SARGable predicate and explicit Three-Valued Logic NULL handling.
02 Phase 2 · Relational Join, Aggregation & 3VL Guard
Relational Join, Grouping & NULL-Safe Aggregation
Combine normalized tables via explicit JOIN conditions and fold group buckets or window partitions without losing NULL boundary rows.
03 Phase 3 · Production Query & Plan Verification
Production Query & Execution Plan Verification (Hands-On Build: Columnar RLE/Dictionary Encoder with Zone-Map Predicate Pushdown)
Verify final column projections, ordering, and physical B+Tree access paths via EXPLAIN QUERY PLAN and automated relational assertions.

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.js step 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.js step 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.js step 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 O(runs)O(\text{runs}) 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.js step 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

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.