In the world of databases, writing the perfect query can be a daunting task. The "Query-By-Example" (QBE) paradigm offers a solution: instead of writing code, a user provides examples of what they want (positive examples) and what they don't (negative examples), and the system infers the query.
But there’s a catch. Usually, there isn't just one query that fits the data—there are infinitely many. Which one should the system choose? A new paper by Balder ten Cate and colleagues, titled "Extremal Fitting Problems for Conjunctive Queries," provides a rigorous mathematical framework for finding the "best" possible queries—the most general and the most specific ones.
TL;DR
This paper tackles the challenge of inferring database queries from labeled examples by defining and characterizing "extremal" queries—those that are as general or as specific as possible. The authors map out the computational complexity of finding these queries for Conjunctive Queries (CQs), Unions of CQs (UCQs), and Tree CQs, revealing a deep connection between query learning and graph theory.
What Problem Does This Paper Address?
The core challenge is the fitting problem: given a set of labeled data examples, construct a query $q$ that returns all positive examples and none of the negative ones.
While finding any fitting query is a well-studied problem, this paper focuses on extremal versions. Imagine the set of all fitting queries as a "convex" space ordered by query containment (where query $A$ is contained in $B$ if $A$ always returns a subset of $B$'s results).
- Most-General (MG) queries are the maximal elements: they capture the broadest possible logic that still excludes the negative examples.
- Most-Specific (MS) queries are the minimal elements: they are as "tight" as possible to the positive examples.
Understanding these extremal queries is vital for automatic feature generation in machine learning and for assisting users in refining their search intent.
Methods
The authors use a mix of order theory, graph theory, and automata theory to characterize these queries.
- Homomorphism Pre-order: The authors leverage the fact that for Conjunctive Queries, query containment is equivalent to the existence of a homomorphism between their "canonical" database instances. This allows them to translate a logical problem into a structural graph problem.
- Frontiers and Dualities: To find most-general queries, the authors use the concept of a frontier—a finite set of queries that "separate" a query from everything strictly more general than it. They also employ homomorphism dualities, which are pairs of sets that partition the entire space of possible data instances.
- Direct Products: Most-specific queries are often constructed using the direct product of all positive examples. If you think of a query as a description, the direct product is the most detailed description that still applies to all positive cases.
- Tree Automata: For the more restricted class of Tree CQs (queries whose structure forms a tree), the authors use two-way alternating parity automata to decide if a fitting query exists and to construct it.
Datasets
As a theoretical study in computer science, this paper does not use traditional "big data" benchmarks. Instead, it uses synthetic constructions to prove complexity bounds. The authors design specific database instances and sets of examples (like cliques or paths of varying lengths) to demonstrate the limits of what can be computed. For example, they use prime-length cycles to prove that fitting queries can sometimes be exponentially larger than the input data.
Key Insights and Ideas
- The Convexity of Fitting: Fitting queries form a convex set. If $q_1$ and $q_2$ both fit the data, then any query $q$ "between" them ($q_1 \subseteq q \subseteq q_2$) also fits.
- UCQs are "Easier": Moving from CQs to Unions of CQs (UCQs) significantly reduces computational complexity—often by an entire exponential factor. For instance, finding if a fitting CQ exists is coNExpTime-complete, while for UCQs, it is only coNP-complete.
- The Power of Acyclicity: Tree CQs are much better behaved because they are "c-acyclic." This property guarantees they always have a frontier, making the search for most-general queries much more tractable.
- Size Matters: A surprising "aha" moment is that even if a fitting query is small, the extremal fitting query might be massive—sometimes doubly exponential in the size of the input examples.
Key Results
The paper provides a comprehensive "complexity map" across three query languages:
| Query Class | Verification Complexity | Existence Complexity |
|---|---|---|
| General CQs | DP-complete to NExpTime-c | coNExpTime-c to NExpTime-c |
| UCQs | DP-complete | coNP-complete to NP-complete |
| Tree CQs | PTime to ExpTime-c | ExpTime-complete |
Specifically, for Tree CQs, the authors show that verifying a weakly most-general fitting query can be done in Polynomial Time, a significant win for practical applications.
Limitations and Future Work
The primary limitation is the high computational complexity for general CQs. NExpTime-completeness suggests that finding these queries in large, complex databases will require significant optimization or heuristic approaches.
The authors suggest several exciting paths forward:
- Ontologies: How do these problems change when we add background knowledge (like a description logic ontology)?
- Approximate Fitting: In the real world, data is noisy. What if we want a query that fits most examples rather than all of them?
- Size Constraints: Can we find the most general query that is also under a certain character limit?
This work lays the foundational theory for the next generation of intelligent database interfaces that can truly "understand" a user's intent through examples.
Summary updated