Efficient Answering of Historical What-if Queries

Felix S. Campbell, Bahareh Sadat Arab, Boris Glavic · DOI

Abstract

Historical What-if Queries (HWQ) allow analysts to determine how hypothetical changes to a database's transactional history would impact its current state. Unlike standard what-if analysis, which focuses on future state projections, HWQs evaluate the long-term consequences of past policy changes or data modifications. Traditional "copy-and-rerun" approaches to HWQs are computationally expensive, requiring massive write I/O and full re-execution of historical logs. This paper introduces Mahif, a middleware system that optimizes HWQ processing through a combination of reenactment, program slicing, and data slicing. By transforming transactional history into optimized read-only queries, Mahif achieves performance improvements several orders of magnitude faster than naive methods.

1. Introduction

Traditional what-if analysis typically addresses the immediate impact of a hypothetical change: "If I change the price of this item now, how will it affect my margin?" However, this does not capture the cumulative effect of past decisions. A more complex and valuable question is the Historical What-if Query (HWQ), such as: "How would our total revenue look today if we had increased the free-shipping threshold six months ago?"

Answering such questions naively requires a four-step process: restoring the database to a specific point in time, modifying the historical transaction, re-executing every subsequent transaction, and comparing the final state. For large-scale transactional databases, the overhead of disk writes and the sheer volume of transactions make this approach impractical for interactive analysis. Mahif addresses these challenges by avoiding physical database copies and minimizing the computational work required to simulate the alternate history.

2. The Mahif Framework

Mahif operates as a middleware layer that utilizes three core techniques to streamline the execution of HWQs.

2.1 Reenactment

Instead of physically re-executing updates on a database clone, Mahif uses a technique called reenactment. It translates the transactional history into a single, complex SELECT query. This allows the system to "replay" the history in a read-only mode, entirely in memory. By avoiding the heavy cost of writing to disk, reenactment provides a significant baseline performance boost over the naive approach.

2.2 Program Slicing

Not every transaction in a historical log is relevant to a specific what-if scenario. Mahif employs Program Slicing to identify and remove updates that are independent of the hypothetical change. This is achieved through:

  • Symbolic Execution: Representing the database as a "symbolic tuple" using VC-tables.
  • Constraint Solving: Utilizing a Mixed Integer Linear Programming (MILP) solver to prove which updates in the history do not affect the target query results.

A key advantage of this approach is that the cost of program slicing depends on the number of updates in the history rather than the number of rows in the database, allowing optimizations to scale effectively.

2.3 Data Slicing

While program slicing removes irrelevant operations, Data Slicing filters the input data itself. If a specific row was never touched by the modified historical update or any subsequent dependent updates, it is filtered out early in the process. This ensures that the reenactment query only processes the specific subset of data affected by the "what-if" change, further reducing I/O and CPU cycles.

3. Experimental Evaluation

The researchers evaluated Mahif across three diverse workloads to test its versatility and scaling properties:

  • Chicago Taxi Trips: A real-world dataset (~100M rows) used to observe scaling across 5M and 50M row samples.
  • TPC-C: The industry-standard benchmark for On-Line Transaction Processing (OLTP), simulating complex inventory and order management.
  • YCSB (Yahoo Cloud Serving Benchmark): A benchmark for simple workloads with high physical data correlation.

3.1 Key Results

The evaluation demonstrated that Mahif consistently outperforms the naive approach by orders of magnitude. Because the slicing optimizations reduce the volume of data processed, Mahif scales linearly with database size. In contrast, the naive approach is often bottlenecked by the fixed, high overhead of copying the entire database. The synergy between program and data slicing was most evident in scenarios with high "selectivity," where only a small percentage of the total data was affected by the hypothetical change.

4. Discussion and Limitations

While Mahif represents a significant advancement in temporal database analysis, several challenges remain:

  • Update Complexity: Current slicing techniques are optimized for "tuple-independent" updates. Updates involving complex joins or nested subqueries are treated as "black boxes," limiting the system's ability to optimize them.
  • Causal Modeling: The system currently requires users to manually specify dependencies if a change (like deleting a customer) should logically trigger other changes (like deleting that customer's orders). Automating the discovery of these causal relationships is a subject for future research.
  • Solver Overhead: In scenarios with extremely long histories involving thousands of unique modifications, the time required for the MILP solver to calculate the slice could potentially diminish the performance gains, though this threshold was not reached in the current study.

5. Conclusion

Mahif demonstrates that historical what-if analysis can be made efficient by decoupling optimization from data size and leveraging the read-only nature of reenactment. By exploiting tuple independence and symbolic execution, Mahif provides a scalable solution for analysts to explore the long-term impacts of historical decisions without the prohibitive costs of traditional database re-execution.

Summary updated

BibTeX
@inproceedings{campbell2022efficient,
  author = {Felix S. Campbell and Bahareh Sadat Arab and Boris Glavic},
  title = {{Efficient Answering of Historical What-if Queries}},
  booktitle = {SIGMOD},
  year = {2022},
  url = {https://openreview.net/forum?id=6-xJBTdLt39},
}
Figure