7 routes42 sections324 units

Unit 4.2 · about 3 h

258 / 324

Aggregations, windows, nulls and point-in-time snapshots

Assume Programming's relational-sql-queries and transactions-isolation units. A consistent engine snapshot is not the same as a historically available feature set; this unit makes the two contracts explicit.

  • implement

You can now

  • Test aggregation and window frames against ties, nulls, empty inputs and cutoff boundaries.
  • Construct feature rows using both event time and availability time without future leakage.
  • Preserve an immutable, ordered query result and its provenance for a point-in-time dataset.

Covers

  • Aggregations, windows, null behavior and boundary tests
  • Point-in-time snapshots and feature availability

Study, in this order

3 steps

  1. Lecture 2: Modern SQL
    CMU 15-445/645 - database and storage core

    Section 4, Aggregates, pp. 1-3

  2. PostgreSQL 18: Window Functions
    PostgreSQL - EXPLAIN and transaction isolation lab

    Section 9.22, Table 9.67 and the paragraphs on peers, default frames and whole-partition aggregation

  3. Point-in-time joins
    Point-in-time joins

    Point-in-time joins, including the TTL rule, then Retrieving features as of the event time

    Depth · Read the semantics only. Do not install Feast; express event and availability predicates explicitly in PostgreSQL.

Focus on

  • GROUP BY collapses rows; a window preserves them. COUNT(*) counts rows, COUNT(value) excludes nulls, and SUM over no non-null values returns NULL.
  • An ordered window's default frame includes peers through the current peer group. Use an explicit ROWS frame and a unique tie-breaker for a row-by-row prefix.
  • For an as-served feature, require event_at <= cutoff and available_at <= cutoff before choosing the newest eligible row. Availability must mean when serving could actually use it.
  • An MVCC snapshot gives a consistent current extraction. Persist its ordered result, query, cutoff and content digest; a snapshot identifier alone cannot reproduce it indefinitely.

Reproduce closed-book

Use the section PostgreSQL setup. Create feature(id int PRIMARY KEY, entity int, event_at int, available_at int, value int) and insert (1,1,8,9,10),(2,1,9,12,99). At cutoff 10, filter entity=1, event_at<=10 and available_at<=10, then ORDER BY event_at DESC, available_at DESC, id DESC LIMIT 1: get 10, not 99. Separately use VALUES (1,8,10),(2,8,20) as (id,event_at,value): SUM(value) OVER(ORDER BY event_at) returns 30,30, while ORDER BY event_at,id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW returns 10,30. On one NULL::int row, COUNT(*),COUNT(value),SUM(value) is 1,0,NULL. Export the eligible rows with an explicit ORDER BY inside one read-only REPEATABLE READ transaction; record the SQL, cutoff and SHA-256 of the export. Recheck the saved bytes after changing the live table.

Traps

  • Ranking before filtering availability. A late newer row can win and then remove an entity whose older eligible feature should have been used.
  • Treating event-time correctness as availability correctness. A later backfill can have an old event timestamp.
  • Using a timestamp alone to break ties, or expecting last_value with the default frame to return the partition's final value.

Practice

The section mini-project covers this: null, tie and exact-cutoff tests, late backfills, and an immutable point-in-time export with query and digest provenance.

Self-test

  1. Why are both default-frame prefix sums 30 in the tie fixture?

  2. Does a row at event_at=9, available_at=12 belong to an as-served snapshot at 10?

  3. Does a stable MVCC snapshot prevent historical leakage?

Completion criterion

Stop when

The three fixtures match the stated results and the saved export remains verifiable after a live-table backfill.

Mark passed, then open 4.3 Only mark this when you can do it without notes.

Leads to

Resources for this unit

  • CMU 15-445/645 - database and storage core
    Carnegie Mellon Database Groupprimarycourse
    Use Fall 2025 Lectures 1-9, 11-18 and 20-22 with their notes: relational model, SQL, storage, buffer pools, layouts, indexes, execution, planning, concurrency, MVCC, logging and recovery. Complete the matching SQL, Storage, Indexes and Filters, Transactions and Recovery homeworks before considering a BusTub project.
  • PostgreSQL - EXPLAIN and transaction isolation lab
    PostgreSQL Global Development Grouprequiredpractice
    Create one normalized schema, joins, an aggregation and a window query. Compare EXPLAIN ANALYZE before and after one justified index. In two sessions, reproduce one documented isolation anomaly and prevent it with a stated database or application invariant.
  • Point-in-time joins
    Feastreferencedocumentation
    Read Point-in-time joins and Retrieving features as of the event time. Separate event-time eligibility from actual feature availability; implement the predicates in SQL, not a Feast installation.

Also in this section

  • Designing Data-Intensive Applications, 2nd edition - storage and transactions
    Martin Kleppmann and Chris Riccominireferencetheory
    Read only the sections on data models and query languages, storage and retrieval, encoding and evolution, and transactions that answer a live design question from the CMU route. Write one comparison table covering layout, index, isolation and recovery trade-offs.
  • Operating Systems: Three Easy Pieces - persistence and integrity
    Remzi and Andrea Arpaci-Dusseausupporttheory
    Use Chapters 36, 39-45 to trace devices, filesystem structures, journaling, log-structured storage, flash and integrity. Apply the crash sequence to your own append-only store rather than repeating the SYS-1 file experiment.
  • CMU 15-445 - one reduced BusTub project slice
    Carnegie Mellon Database Groupdepthpractice
    If a C++ database implementation is the chosen depth lane, complete Project 1 Buffer Pool Manager or Project 2 Database Index, not both during the first pass. Follow the course publication rules and keep code private. The blank-file append-only store remains the core checkpoint.
  • CMU Lecture 19: Timestamp Ordering Concurrency Control
    Carnegie Mellon Database Groupreferencecourse
    Section 1 only, p. 1: timestamp order as a chosen serialization order. The section pool omits Lecture 19; this fills the timestamp-ordering vocabulary gap without assigning all of OCC.
  • SQLite Write-Ahead Logging
    SQLitereferencedocumentation
    Sections 1 and 3 only: rollback journaling remains the default and WAL is an opt-in mode. Correct the dated SQLite statement in CMU Lecture 21; inspect the bundled engine without running concurrent WAL writers.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels