Theoremadvanced
Sagiv-Yannakakis theorem
Also called containment of unions of conjunctive queries.
A union of conjunctive queries is contained in another union exactly when each of its members is contained in some member of the other.
The Sagiv-Yannakakis theorem extends the Chandra-Merlin theorem from one conjunctive query to a finite union of them. A union is contained in a union if and only if each is contained in some single . So no member of the first union needs two members of the second union to cover it, and query containment for unions of conjunctive queries reduces to tests for single queries. Sagiv and Yannakakis proved it in 1980, in the language of tableaux.
Statement
We use set semantics: a relation is a set of tuples, and a query returns a set of tuples. A conjunctive query (CQ) is a rule in which each variable of the head occurs in the body. A union of conjunctive queries (UCQ) is a finite union of CQs whose heads have the same arity, with . means for every database .
Theorem (Sagiv and Yannakakis 1980). Let and be UCQs over the same schema with heads of the same arity. Then if and only if for each there is with , that is, with a homomorphism from to .
In plain words
A union of queries returns every answer that any one of its parts returns. Say you want to know whether one union never gives an answer that a second union misses.
You might expect that a part of the first union could be covered by several parts of the second union together, each catching some of its answers. The theorem says that this never happens for these simple queries. Each part of the first union must be covered by one single part of the second union.
The reason is that each simple query has one most typical database, the query itself read as data. On that database the query finds its own pattern, and one part of the second union must find that answer. That part then finds all the answers.
Proof
If. Let each be contained in some . For a database ,
Only if. Let , and fix . Let be the head of , and let be the canonical database of : one fact for each atom of the body, with each variable read as a new constant of its own. The identity valuation maps the body of into , so . So for some . By the Chandra-Merlin theorem, form (3) implies form (1), so , and there is a homomorphism from to .
The only property of a single CQ that the proof uses is that one database, , decides containment of in every query that is preserved by homomorphisms of databases. Each UCQ is such a query.
Consequences
- Containment and equivalence are NP-complete. For the upper bound, guess for each an index and a homomorphism from to , and check the guess in polynomial time. The lower bound holds already for , by the reduction from 3-coloring on the Chandra-Merlin page. Equivalence is containment in both directions.
- An example. Let and . Let and . The map , sends into , so . alone does not cover , because the canonical database has no loop.
- Minimization of UCQs. Delete each member that is contained in another member that stays, and minimize each remaining member as in conjunctive query minimization. Call the result irredundant. If two irredundant UCQs are equivalent, the theorem gives maps and with . Irredundancy gives , so the members match one to one, and each pair is equivalent. So the irredundant form is unique up to renaming, and it has the fewest members and the fewest atoms.
- Relational expressions with union. A select, project, join and union expression is a UCQ, but writing it as a UCQ can multiply out unions inside joins and give exponentially many members. Sagiv and Yannakakis showed that equivalence of such expressions is -complete, a level of the polynomial hierarchy above NP.
- Non-recursive Datalog. A non-recursive Datalog program unfolds into a UCQ, so containment between such programs is decidable by the theorem, although the unfolding can be large.
- Rewriting with views. The rewritings of a query by views in answering queries using views are often UCQs, and the test for a correct rewriting is this theorem.
Tightness
- Bag semantics. Count each answer with its multiplicity and use the bag union. Let with and , and let . Each member of is contained in , but on a relation with one tuple, returns it twice and once. So the "if" direction fails. Already for single CQs under bag semantics, Chaudhuri and Vardi (1993) showed that equivalence means isomorphism, and containment is harder, with cases that are still open.
- Comparisons. With in the bodies, let , and . Each pair of values is ordered one way or the other, so , but is contained in neither nor .
- Negation. In the same way, is contained in the union of and , but in neither member. The canonical database argument needs queries that are preserved by homomorphisms.
- Infinite unions. A recursive Datalog program is an infinite union of CQs. Containment of a CQ in such a program is still decidable, by evaluating the program on the canonical database. Containment of one Datalog program in another is undecidable (Shmueli 1993).
History
Yehoshua Sagiv and Mihalis Yannakakis proved the theorem in their 1980 paper on relational expressions with union and difference, written in terms of tableaux, which are another notation for CQs. The same paper showed -completeness of equivalence for expressions with union and studied expressions with difference. The result extends the homomorphism theorem of Chandra and Merlin (1977), and the textbook of Abiteboul, Hull and Vianu presents both together.
References
- Yehoshua Sagiv and Mihalis Yannakakis, Equivalences among relational expressions with the union and difference operators, Journal of the ACM 27(4), 633 to 655 (1980), the containment test for unions of tableaux, and the Pi-2-p-completeness of equivalence for select, project, join and union expressions
- Ashok K. Chandra and Philip M. Merlin, Optimal implementation of conjunctive queries in relational data bases, Proceedings of the 9th Annual ACM Symposium on Theory of Computing (STOC), 77 to 90 (1977), the homomorphism criterion and the canonical database for one conjunctive query
- Surajit Chaudhuri and Moshe Y. Vardi, Optimization of real conjunctive queries, Proceedings of the 12th ACM Symposium on Principles of Database Systems (PODS), 59 to 70 (1993), containment and equivalence of conjunctive queries under bag semantics
- Oded Shmueli, Equivalence of DATALOG queries is undecidable, Journal of Logic Programming 15(3), 231 to 241 (1993), containment and equivalence of Datalog programs are undecidable
- Serge Abiteboul, Richard Hull and Victor Vianu, Foundations of Databases, Addison-Wesley (1995), Chapter 6 (static analysis and optimization), the section on unions of conjunctive queries
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 45C56P Edit this page History Report an error Markdown