HISTORY¶
Description¶
The HISTORY statement displays the complete version timeline for one or more rows. It retrieves every record version ever committed to disk for the matching row, including the initial INSERT, subsequent UPDATEs, and any DELETE tombstone.
Syntax¶
(See the Syntax Notation Guide for notation rules).
Basic syntax¶
Full syntax¶
[!IMPORTANT] A
WHEREclause is required. You cannot execute a bareHISTORY <table>;without a condition.
Parameters¶
| Parameter | Description |
|---|---|
<table> |
Target table name. |
WHERE <condition> |
A filter condition identifying the target row (typically <pk_col> = <val>). |
Example¶
Output Structure¶
The output displays each version in chronological order, showing:
1. Timestamp: High-resolution creation time (YYYY-MM-DD HH:MM:SS.mmm).
2. Deleted: Tombstone flag (NO for active records, YES for deleted records).
3. Column values as they existed in that specific version.
(Note: Timestamps reflect the actual system time when each record was inserted or updated).
---------------------------------------------------------------------------------------------------------
Timestamp Deleted id name title salary
---------------------------------------------------------------------------------------------------------
[Runtime Timestamp 1] NO 1 Elena Rostova Junior Engineer 75000.00
[Runtime Timestamp 2] NO 1 Elena Rostova Software Engineer 95000.00
[Runtime Timestamp 3] YES 1 Elena Rostova Software Engineer 95000.00
---------------------------------------------------------------------------------------------------------
3 version(s) across 1 row(s)
In this output:
* Version 1 represents the initial INSERT.
* Version 2 represents an UPDATE that changed the title and salary.
* Version 3 represents a subsequent DELETE (marked with Deleted = YES).
How It Works¶
- Resolve Primary Keys: The executor evaluates the
WHEREcondition to find all matching primary keys. - Retrieve Version Chains: For each primary key,
Table::showHistory(pk)iterates through allRecordVersionentries in theHistoryIndex. - Read Records from Disk: For each version, the executor reads the record from its byte offset in
data.dband prints the formatted timestamp, tombstone flag, and column payload.
Errors & Edge Cases¶
| Error Condition | Error Message |
|---|---|
| Missing WHERE Clause | Parse error (after table name in HISTORY (WHERE is required here)). |
| Unknown Column in WHERE | Unknown column '<col>' on table '<table>' |
| No Matching Rows | No rows matched |