Abstract
This paper addresses the challenge of automatically "repairing" database queries that return incorrect results. By formalizing the process of query fitting based on user-provided positive and negative examples, the authors explore various mathematical notions of "closeness" between queries. The research demonstrates that a structural approach based on semantic edit distance provides significantly more reliable and intuitive results than traditional semantic containment-based methods. We present the formal framework, analyze the properties of different proximity metrics, and establish the computational complexity for key decision problems in query repair.
Introduction: The Problem of Query Fitting
Writing precise database queries is a notoriously difficult task, even for experienced users. Often, a query returns a set of results that is "almost" correct but contains unwanted tuples or misses desired ones. In such scenarios, a user can provide feedback in the form of examples: positive examples (tuples that should be in the result) and negative examples (tuples that should not).
The core problem, known as query reverse engineering or query fitting, is to automatically rewrite the original query $q$ into a new query $q'$ that satisfies these examples. However, because many queries could potentially fit a small set of examples, the goal is to find a repair that is "minimal"—one that fixes the errors while remaining as close as possible to the user's original intent.
Methodology: Proximity Pre-orders
The authors propose a formal framework for query repair parameterized by a proximity pre-order ($\\preceq$). A query $q'$ is defined as a valid repair of $q$ if it fits the provided examples and no other fitting query is strictly "closer" to $q$ according to $\\preceq$. Two primary metrics for closeness are investigated:
- Containment of Difference ($\\preceq^{cod}$): A semantic approach where $q'$ is closer to $q$ than $q''$ if the set of database instances where $q'$ disagrees with $q$ is a subset of those where $q''$ disagrees.
- Semantic Edit Distance ($\\preceq^{edit-dist}$): A structural approach. To avoid issues with logically identical but syntactically different queries, the authors first reduce queries to their "homomorphism cores" (their most compressed equivalent form) and then measure the minimum number of structural changes (additions or deletions) required for transformation.
The framework also distinguishes between generalizations (which only expand results) and specializations (which only restrict results).
Key Insights: Why Edit Distance Prevails
A significant contribution of this work is the demonstration that containment-based metrics often fail in practice. While useful for simple generalizations, unconstrained containment-based repairs can be counter-intuitive. The authors prove that for certain queries, a containment-based repair might not even exist, or there might be an infinite number of "minimal" repairs with exponentially large structures.
In contrast, the semantic edit distance metric ($\\preceq^{edit-dist}$) resolves these issues. The paper proves that if any fitting query exists for the given examples, an edit-distance repair is guaranteed to exist. Furthermore, there are always a finite number of such repairs (up to logical equivalence), and their size is strictly bounded, making them more computationally tractable and predictable.
Computational Complexity and Results
The paper provides a rigorous analysis of the computational complexity associated with finding and verifying repairs. These results are centered around three fundamental problems: verification, existence, and construction.
Key findings include:
- Existence: Determining if an edit-distance repair exists is
coNExpTime-completein the general case. However, the complexity drops significantly toPTimeif the user provides only positive or only negative examples. - Verification: Checking if a specific query is a valid edit-distance repair is highly complex, falling between
$\Pi_2^P$-hardand$\Sigma_3^P$. - Theoretical Correspondence: The authors established that containment-based generalizations are mathematically equivalent to finding the "most-specific fitting Conjunctive Query," linking this work to established concepts in database theory.
Conclusion and Future Directions
While this work establishes a solid theoretical foundation for query repairs, several challenges remain for practical implementation. The current algorithms are primarily theoretical; future work must focus on developing optimized versions using SAT solvers or approximation techniques. Additionally, extending the framework beyond Conjunctive Queries to include SQL features like unions, negation, and nested subqueries is a critical next step. Finally, the authors suggest investigating the iterative convergence of this process—whether repeated repairs eventually lead to the user's true intended query.
Summary updated