How Historical Tracking Works
Metadb uses temporal columns to track the lifecycle of each record:__start: When this version of the record became active__end: When this version was superseded (or9999-12-31 00:00:00+00if still current)__current: Boolean flag indicating if this is the current version
This approach is known as “temporal table” design or “slowly changing dimension type 2” in data warehousing terminology.
Understanding Record History
Let’s look at a practical example of how changes are tracked:__start | __end | __current | id | groupname | description |
|---|---|---|---|---|---|
| 2022-04-17 21:42:25-00 | 2022-04-18 19:27:18-00 | false | 15 | undergrad | Student |
| 2022-04-18 19:27:18-00 | 9999-12-31 00:00:00+00 | true | 15 | undergrad | Undergraduate Student |
| 2022-04-17 21:42:25-00 | 9999-12-31 00:00:00+00 | true | 10 | graduate | Graduate Student |
| 2022-04-17 21:52:53-00 | 9999-12-31 00:00:00+00 | true | 9 | faculty | Faculty Member |
Reading the History
In this example:Historical record
The old version’s
__end was set to the change timestamp and __current became falseThe
__end value of 9999-12-31 00:00:00+00 represents “infinity” - meaning this version is still active.Querying Historical Data
Current State Only
For most operational queries, you only need current records:All History
To see every version of every record:Point-in-Time Queries
Find out what the data looked like at a specific moment:Point-in-time queries use the pattern
target_time >= __start AND target_time < __end to find records that were active at that moment.Date Range Queries
Find all records that changed within a time period:Change Tracking
Identify records that have been modified:Most Recent Changes
Find the most recently modified records:Temporal Analysis Use Cases
- Audit & Compliance
- Trend Analysis
- Comparative Analysis
- Data Quality
Track who changed what and when for audit trails:This shows the complete audit trail for a single entity.
Working with Date Ranges
When querying date ranges, use the recommended inequality pattern:The pattern
start <= t < end is the most reliable method for date range queries in Metadb.- Includes the start date
- Excludes the end date (making ranges easier to reason about)
- Works correctly across time zones
- Handles edge cases consistently
Historical Data and Transformations
Transformed tables also maintain full history:- Main transformed:
table__t__(with history) - Current transformed:
table__t(current only)
Performance Considerations
Index on Temporal Columns
Metadb automatically creates indexes on
__start, __end, and __current columns for efficient temporal queries.Current Tables for Speed
When you don’t need history, use current tables for better performance. They’re optimized for current-state queries.
Partition Awareness
Main tables are partitioned internally by Metadb. The query planner automatically uses the most efficient partitions based on your temporal filters.
Best Practices
Default to current tables
Use current tables (
table) for operational queries unless you specifically need historical data.Filter early on temporal columns
When querying main tables, add
__start and __end filters early in your WHERE clause to leverage indexes.Monitoring Data Updates
Check when tables were last updated:Limitations
Database views are not supported in Metadb. Views can create dependencies that block schema changes during data updates. Use database functions instead to encapsulate query logic.
