Time-travel queries

An appendable table records every append and compaction as a link in a hash-chained ledger. Because the history is preserved and tamper-evident, you can reconstruct the table as it was at any past point — and the answer is exact while the underlying segments still exist.

scan_as_of

scan_as_of(event_idx, ...) runs the same predicate/projection scan, but against the segment set as it stood after a given event in the audit log. The returned stats carry an as_of_event marker so a result is always attributable to a point in history.

from at1_table import AppendableTable

t = AppendableTable("trades_dir")
# the table as it stood right after event 3 (0-based over the audit log)
rows, stats = t.scan_as_of(3, where={"c0": (lo, hi)}, select=["c0", "c1"])
stats["as_of_event"]   # -> 3

How it stays exact

Under the hood it replays the event log to a chosen point: segments_as_of() walks the chain, applying appends (add a segment) and compactions (replace inputs with the merged segment), to recover exactly which files existed then. Before serving anything it:

  • verifies the chain— refuses if the history doesn't recompute end-to-end (possible tampering);
  • re-hashes each segment against the sha256 the verified chain recorded, so the bytes served are the bytes history says they were;
  • refuses if a segment that existed then has since been physically reclaimed by compaction.
paths = t.segments_as_of(3)   # the exact segment files live at event 3
# verifies the chain first, then re-hashes each file against its chained digest

Immutability makes time travel exact while the files exist; reclamation by compaction is the explicit, logged trade-off — a reclaimed past point raises rather than returning a wrong answer.

Use cases

  • Compliance & audit— show the exact state on record at a past instant, backed by a tamper-evident ledger that proves the history wasn't edited.
  • Debugging— answer "what did this table look like then?" without restoring a backup.
  • Reproducible analytics — pin a query to a point in history so a result can be regenerated bit-for-bit.

See appendable tables for how segments and the audit chain are built.