Change Tracking
A dimension that only knows today
Take a rental marketplace's warehouse. dim_host has one row per host. fact_booking has one row per booking and points at its host through host_key. Every night a load copies each host's latest values from the application database into the dimension.
| host_key | host_id | host_name | tier |
|---|---|---|---|
| 101 | 4417 | Marta Reis | Standard |
| 102 | 5230 | Jonas Weber | Superhost |
| booking_id | host_key | booking_date | amount |
|---|---|---|---|
| 9001 | 101 | 2025-02-14 | 300 |
| 9002 | 101 | 2025-03-20 | 500 |
| 9003 | 102 | 2025-03-22 | 400 |
| 9004 | 101 | 2025-04-10 | 600 |
On April 1, 2025 Marta earns the Superhost tier. The application updates her record, and that night's load writes Superhost over Standard in row 101. Nothing in fact_booking changes. Now run the first-quarter revenue report twice, once before that load and once after.
| tier | revenue |
|---|---|
| Standard | 800 |
| Superhost | 400 |
| tier | revenue |
|---|---|
| Superhost | 1200 |
Why the join cannot recover the past
The fact row stores a pointer, host_key = 101, and the tier lives on the other side of that pointer. When the dimension row is overwritten, every fact pointing at row 101 picks up the new value at once, including bookings from years ago. The old value is gone from the warehouse, so no query can bring it back. A fact table is append-only, like the event logs you have modeled before. An overwritten dimension is the one mutable table in the star, and its edits reach backwards through every join.
- ▸The value that was true when each past event happened.
- ▸The date of the change, so before and after cannot be told apart.
- ▸Repeatability: the same query over the same closed period returns a different answer next week.
Slowly changing dimensions
dim_host is overwritten nightly. A host with 12 bookings in May moves from Lisbon to Porto on June 20, and the load updates city. On July 1 an analyst reruns May's bookings-by-city report. What does it show for this host?
| host_key | host_id | host_name | city |
|---|---|---|---|
| 103 | 6102 | Aiko Tanka | Osaka |
| host_key | host_id | host_name | city |
|---|---|---|---|
| 103 | 6102 | Aiko Tanaka | Osaka |
Where overwriting is the right answer
- The old value was never trueCorrectionsA typo, a wrong birth year, a city entered by mistake. Old facts should show the fixed value, and restating past reports is the goal.
- No report groups or filters by itContact and display fieldsEmail, phone number, profile photo. These are read for their current value and never used to slice revenue.
- The business wants history under today's labelsAs-is questionsA product team asks how the hosts who are Superhosts today performed over the last 3 years. Applying today's tier to every old booking is the point.
The cost of overwriting
Type 1 is the cheapest rule to run. The load compares incoming values with stored ones and updates the rows that differ. The dimension's row count equals the number of entities, so joins stay small and counting hosts is COUNT(*).
The cost arrives later, in other tables. Any table computed from the old value keeps showing it until rebuilt. Suppose a nightly aggregate, agg_revenue_by_city, holds 900 of revenue under Osaka from host 6102's bookings. Support then learns she hosts in Kyoto and corrects city with a Type 1 update. The dimension says Kyoto, the aggregate still says Osaka, and a dashboard reading the aggregate disagrees with a query on the star. A Type 1 change to any column that aggregates group by has to trigger a rebuild of those aggregates across their full history.
- Use Type 1 for corrections, where the old value was never true.
- Rebuild every aggregate grouped by a column after overwriting it.
- Record which columns are Type 1 in the table's documentation.
- Overwrite a column that finance, billing or commission reports group by.
- Assume history is safe because the fact table was left untouched.
- Pick Type 1 for a tracked attribute because the load is shorter to write.
A host dimension has these 4 columns. Which one should the load overwrite with Type 1?
3 columns do the bookkeeping. valid_from is the first day a version applies. valid_to is the day the next version takes over, so a version covers valid_from up to but excluding valid_to. is_current flags the open version. The open row carries valid_to = 9999-12-31, a far-future date that lets one range condition match open and closed rows alike.
| host_key | host_id | tier | valid_from | valid_to | is_current |
|---|---|---|---|---|---|
| 101 | 4417 | Standard | 2023-06-12 | 2025-04-01 | false |
| 104 | 4417 | Superhost | 2025-04-01 | 9999-12-31 | true |
| 102 | 5230 | Superhost | 2022-09-05 | 9999-12-31 | true |
Marta now has 2 rows. host_id 4417 appears twice, which is why the natural key can no longer be the primary key. The surrogate host_key identifies a version, and host_id ties the versions of one host together.
What the load does on a change
How facts find the right version
The source system sends each booking with a host_id and a date. The fact load translates that pair into a host_key by finding the version whose window contains the booking date.
Bookings 9001 and 9002 happened in February and March, so they keep host_key = 101, the Standard version. Booking 9004 on April 10 receives 104. The date logic runs once, at load time. After that, reports use the same equality join on host_key as before, and the first-quarter report returns Standard 800 and Superhost 400 no matter when it runs.
Both views from one table
A Type 2 dimension still answers as-is questions. Join each fact to its version, then hop through host_id to the same host's current row and group by that row's tier.
- ▸Count hosts with
COUNT(DISTINCT host_id)or a filter onis_current.COUNT(*)counts versions. - ▸Look up fact keys by event date.
is_currentis for as-is reports, and using it in the fact load mislabels any booking that arrives late. - ▸Expect growth. 40,000 hosts with 3 tracked changes each occupy 160,000 rows.
Host 4417 has version 101 (Standard, 2023-06-12 up to 2025-04-01) and version 104 (Superhost, from 2025-04-01). A booking dated March 28, 2025 is delayed in the source system and reaches the fact load on April 3. Which host_key belongs on its fact row?
Type 3 keeps history in a column. The dimension gains a previous_ column next to the tracked attribute, and usually a date for when the switch happened. On a change, the current value moves into the previous column and the new value takes its place. The table stays at one row per entity.
A change that hits everyone at once
In standard SQL, each SET expression reads the row as it was before the statement ran, so previous_region receives Iberia. The tables in this section use a one-row-per-host dim_host so the Type 3 columns stand alone.
| host_id | host_name | region | previous_region | region_changed_on |
|---|---|---|---|---|
| 4417 | Marta Reis | Southern Europe | Iberia | 2025-07-01 |
| 5230 | Jonas Weber | Central Europe | DACH | 2025-07-01 |
| region | previous_region | total_revenue |
|---|---|---|
| Southern Europe | Iberia | 1400 |
| Central Europe | DACH | 400 |
The limit of a single previous column
The column holds one earlier value. Suppose Southern Europe is renamed Mediterranean in 2026. The update moves Southern Europe into previous_region, and Iberia is gone.
| After | region | previous_region |
|---|---|---|
| Initial load | Iberia | NULL |
| July 2025 redraw | Southern Europe | Iberia |
| 2026 rename | Mediterranean | Southern Europe |
Adding previous_region_2 postpones the problem and widens the table for every tracked attribute. A second limit is per-fact truth. Which region applied to a given booking is missing from the row. Comparing booking_date with region_changed_on recovers it for the latest change and for nothing earlier.
- Which value was in force when this fact happened?
- How many times has this host changed, and when?
- What did the dimension look like on a given past date?
- What do all facts total under the previous labels?
- Which entities moved in the latest change?
- How do the old and new groupings compare over one period?
A streaming service keeps plan and previous_plan on its one-row-per-member dimension. A member moves from Basic to Standard in 2024, then from Standard to Premium in 2025. Finance asks how much this member paid while on Basic. What can the dimension contribute?
The choice is made per column, and one dimension usually mixes rules. On dim_host, payout_email can be Type 1, tier Type 2 and region Type 3, all in the same table. A dimension is called Type 2 when at least one of its columns creates new rows.
| Property | Type 1 | Type 2 | Type 3 |
|---|---|---|---|
| On a change | Replace the value | Close the row, add a row | Shift the value into a previous column |
| One row means | The entity as known today | One version, valid for a window | The entity today plus one earlier value |
| Rows per entity | 1 | 1 per version | 1 |
| History kept | None | Every version, with dates | The latest change only |
| Past facts show | Today's value | The value at event time | Either label, across all facts |
| Breaks when | A closed period must stay fixed | The attribute changes daily | A second change arrives |
3 questions for each column
- Does any report group, filter or price facts by this column? If none does, choose Type 1 and stop.
- After the value changes, must reports on closed periods keep their published numbers? If yes, the column needs Type 2.
- Is the change a rare, planned relabeling, with people wanting all facts under both old and new labels? That is the Type 3 case.
- If reports group by the column but only ever want today's labels (as-is), Type 1 still fits. If that need may change, see When you are unsure below.
Mixing rules on one table
Mixing has one mechanical consequence. When a Type 1 column changes on a table that also has Type 2 columns, the update must reach every version of that entity. If Marta's host_name is corrected, rows 101 and 104 both receive the fix and no new version is created. A name that differed between versions would split her bookings in any report grouped by name.
When you are unsure
You own the warehouse at a subscription software company. `dim_customer` has one row per customer and is overwritten every night. `fact_invoice` has one row per invoice. 2 requests arrive this year.
| customer_keyBIGINTPK | customer_idBIGINT | emailVARCHAR | planVARCHAR | territoryVARCHAR |
|---|
| invoice_idBIGINTPK | customer_keyBIGINTFK | invoice_dateDATE | amountDECIMAL(10,2) |
|---|
Finance wants monthly revenue by plan, using the plan each customer was on when each invoice was issued. Customers switch plans whenever they like, some of them several times a year. How should `plan` be tracked?
> A food delivery marketplace keeps a restaurant dimension. Restaurants negotiate new commission tiers a few times a year, operations redraws delivery zones once each January, owners update phone numbers weekly, and star ratings move with every order. Finance must reproduce any closed month's commission revenue, and zone managers want this year's orders under last year's zones and this year's.
zone and previous_zone and one query totals the year's orders under either map.Decide what a dimension remembers when a value changes: overwrite it, version it, or keep the one before.
- Category
- Data Modeling
- Difficulty
- intermediate
- Duration
- 17 minutes
- Challenges
- 12 hands-on challenges
Topics covered: The History Problem, Type 1: Overwrite Old Value, Type 2: Preserve Full History, Type 3: Keep Previous Value, Choosing Your Strategy
Lesson Sections
- The History Problem
A star schema holds 2 kinds of rows that age differently. A fact row records an event, and an event that has happened stays the way it happened. A dimension row describes a person, a product or a place, and those keep changing long after the event is over. Change tracking is the set of rules for what a dimension does when a source value changes. A dimension that only knows today The quarter was closed, no booking was added or edited, and the answer still moved. Marta's 2 first-quarter bookings,
- Type 1: Overwrite Old Value
Type 1 is the rule from the previous section, applied on purpose. When a source value changes, the load updates the dimension row in place and discards the old value. The table keeps one row per entity, the surrogate key stays the same, and no fact row is touched. Read one row of a Type 1 dimension as: this host, as the business knows them right now. That meaning covers every column in the row. A report that joins to it describes all of history using today's values, a style called as-is reportin
- Type 2: Preserve Full History
Type 2 keeps the old row and adds a new one. Each change to a tracked attribute produces a fresh row with its own surrogate key, and the row it replaces is marked as closed. One row now means one version of a host, valid for a stated window of time. What the load does on a change When the nightly load finds that host 4417's incoming tier differs from her open row, it runs 2 statements. The first closes the open version. The second statement inserts the new version under a new surrogate key, star
- Type 3: Keep Previous Value
A change that hits everyone at once On July 1, 2025 the marketplace redraws its sales regions. Iberia is folded into a new Southern Europe region, and DACH becomes Central Europe. Regional managers hold targets set under the old map and need this year's reports under both maps while they adjust. Every host changes on the same day, for the same reason, and the business wants the old and new labels side by side. In standard SQL, each SET expression reads the row as it was before the statement ran,
- Choosing Your Strategy
3 questions for each column The second question separates as-was reporting from as-is reporting. As-was shows each fact with the attribute value from its own date, and finance, billing and compensation nearly always require it. As-is shows all facts under today's values, which suits questions about the entities themselves, such as how today's Superhosts grew over time. Mixing rules on one table When you are unsure The 2 main rules differ in what can be undone later. A Type 2 dimension can always