# Conjunctive query containment revisited

## Abstract

We consider the problems of conjunctive query containment and minimization, which are known to be NP-complete, and show that these problems can be solved in polynomial time for the class of *acyclic queries*. We then generalize the notion of acyclicity and define a parameter called *query width* that captures the “degree of cyclicity” of a query: in particular, a query is acyclic if and only if its query width is 1. We give algorithms for containment and minimization that run in time polynomial in n^{k}, where *n* is the input size and *k* is the query width. These algorithms naturally generalize those for acyclic queries, and are of practical significance because many queries have small query width compared to their sizes. We show that we can obtain good bounds on the query width of *Q* using the *treewidth* of the incidence graph of *Q*. Finally, we apply our containment algorithm to the practically important problem of finding equivalent rewritings of a query using a set of materialized views.

## Keywords

Partial Mapping Tree Decomposition Large Data Base Conjunctive Query Connectedness Property## Preview

Unable to display preview. Download preview PDF.

## References

- [ASU79a]A.V. Aho, Y. Sagiv, and J.D. Ullman. Efficient optimization of a class of relational expressions.
*ACM Transactions on Database Systems*, 4(4):435–454, December 1979.Google Scholar - [ASU79b]A.V. Aho, Y. Sagiv, and J.D. Ullman. Equivalence of relational expressions.
*SIAM Journal on Computing*, 8(2):218–246, May 1979.Google Scholar - [Bod93]H.L. Bodlaender. A linear time algorithm for finding tree-decompositions of small treewidth. In
*Proceedings of the 25th ACM Symposium on the Theory of Computing*, pages 226–234, 1993.Google Scholar - [CKPS95]S. Chaudhuri, R. Krishnamurthy, S. Potamianos, and K. Shim. Optimizing queries with materialized views. In
*Proceedings of the Eleventh International Conference on Data Engineering*, pages 190–200, 1995.Google Scholar - [CM77]A.K. Chandra and P.M. Merlin. Optimal implementation of conjunctive queries in relational databases. In
*Proceedings of the Ninth ACM Symposium on Theory of Computing*, pages 77–90, 1977.Google Scholar - [Gra79]M.H. Graham. On the universal relation. Technical report, University of Toronto, Ontario, Canada, 1979.Google Scholar
- [JK83]D.S. Johnson and A. Klug. Optimizing conjunctive queries that contain untyped variables.
*SIAM Journal on Computing*, 12(4):616–640, November 1983.Google Scholar - [KM96]S. Khanna and R. Motwani. Towards a syntactic characterization of PTAS. In
*Proceedings of the 28th ACM Symposium on the Theory of Computing*, 1996.Google Scholar - [LMSS95]A.Y. Levy, A.O. Mendelzon, Y. Sagiv, and D. Srivastava. Answering queries using views. In
*Proceedings of the Fourteenth ACM Symposium on Principles of Database Systems*, pages 95–104, 1995.Google Scholar - [LRO96]A.Y. Levy, A. Rajaraman, and J.J. Ordille. Querying heterogeneous information sources using source descriptions. In
*Proceedings of the 22nd International Conference on Very Large Data Bases*, 1996.Google Scholar - [LRU96]A.Y. Levy, A. Rajaraman, and J.D. Ullman. Answering queries using limited external query processors. In
*Proceedings of the Fifteenth ACM Symposium on Principles of Database Systems*, pages 227–237, 1996.Google Scholar - [LY85]P.A. Larson and H.Z. Yang. Computing queries from derived relations. In
*Proceedings of the Eleventh International Conference on Very Large Data Bases*, pages 259–269, 1985.Google Scholar - [Qia96]X. Qian. Query folding. In
*Proceedings of the Twelfth International Conference on Data Engineering*, 1996.Google Scholar - [RSU95]A. Rajaraman, Y. Sagiv, and J.D. Ullman. Answering queries using templates with binding patterns. In
*Proceedings of the Fourteenth ACM Symposium on Principles of Database Systems*, pages 105–112, 1995.Google Scholar - [TY84]R.E. Tarjan and M. Yannakakis. Simple linear-time algorithms to test chordality of graphs, test acyclicity of hypergraphs, and selectively reduce acyclic hypergraphs.
*SIAM Journal on Computing*, 13(3):566–579, 1984.Google Scholar - [Ull89]J.D. Ullman.
*Principles of Database and Knowledge-Base Systems*,*Volume II: The New Technologies*. Computer Science Press, Rockville, MD, 1989.Google Scholar - [Yan81]M. Yannakakis. Algorithms for acyclic database schemes. In
*Proceedings of the Seventh International Conference on Very Large Data Bases*, pages 82–94, 1981.Google Scholar - [YL87]H.Z. Yang and P.A. Larson. Query transformation for PSJ-queries. In
*Proceedings of the Thirteenth International Conference on Very Large Data Bases*, pages 245–254, 1987.Google Scholar - [YO79]C.T. Yu and M.Z. Ozsoyoglu. An algorithm for tree-query membership of a distributed query. In
*Proceedings of IEEE COMPSAC*, pages 306–312, 1979.Google Scholar