A historical dimension keeps effective-time versions so a fact can be interpreted with the attributes that were valid when the event occurred.
Warehouse history: join facts to the dimension version valid at event time
Keep the old meaning
A store moves to a new operating region in September. A report of August receipts should use the August region when the question asks what was known then. Replacing the store row in place rewrites every past fact. A type-2 dimension stores non-overlapping validity intervals for the business key; the fact joins to the interval containing its event time. Decide whether a report instead wants today’s region, and name that distinct question.
Enforce one interval per fact
For one store and timestamp, exactly one dimension row should match. Gaps create unmatched facts; overlapping intervals multiply them. Use half-open validity periods to avoid a boundary timestamp matching two versions. Check active interval uniqueness and row counts around the join. Cardinality checks] are a correctness requirement, not an optimization.
Handle corrections deliberately
A late source correction may change a past interval and every derived aggregate it touched. Rebuild affected partitions or publish a restated version. Preserve the raw change trail and dimension history for audit. CDC replay] can feed the versions, but a CDC event alone does not define business effective time.
Test the boundary
Construct two store versions with an exact change timestamp and three receipts before, at and after that instant. Assert each fact matches one version. Then create a deliberate overlap and make the quality gate fail before report publication.
Implementation
SELECT r.receipt_id, r.submitted_at, d.operating_region
FROM receipt_fact AS r
JOIN store_region_history AS d
ON r.store_id = d.store_id
AND r.submitted_at >= d.valid_from
AND (d.valid_to IS NULL OR r.submitted_at < d.valid_to);Performance and operating cost
An indexed lookup on (store_id, valid_from) costs about O(log H) per fact among H history rows; an unbounded range join can be much more expensive. Retaining history increases storage but prevents silent rewriting of past context.
Common Mistakes
- Do not overwrite a historical dimension if past reports need past attributes.
- Do not allow interval overlaps to multiply fact rows.
- Do not equate CDC arrival time with business effective time.
Read next
- Change data capture: apply updates and deletes by source order
- Backfills: rebuild history without exposing a half-written result
- Dataset grain and join cardinality: protect the unit of analysis
- Metric denominators and cohorts: make a rate reproducible
Continue the workflow: Historical feature retrieval: point-in-time joins without future leakage.
Continue the workflow: Calibration drift: compare sensor readings with a reference.
Continue the workflow: Table snapshots and atomic publication.
Continue the workflow: Late-arriving dimensions and fact repair.
Continue the workflow: Stream-table joins and reference versions.
