ABSTRACT
The conservativity theorem for nested relational calculus implies that query expressions can freely use nesting and unnesting, yet as long as the query result type is a flat relation, these capabilities do not lead to an increase in expressiveness over flat relational queries. Moreover, Wong showed how such queries can be translated to SQL via a constructive rewriting algorithm. While this result holds for queries over either set or multiset semantics, to the best of our knowledge, the questions of conservativity and ormalization have not been studied for queries that mix set and bag collections, or provide duplicate-elimination operations such as SQL's SELECT DISTINCT. In this paper we formalize the problem, and present partial progress: specifically, we introduce a calculus with both set and multiset collection types, along with natural mappings from sets to bags and vice versa, present a set of valid rewrite rules for normalizing such queries, and give an inductive characterization of a set of queries whose normal forms can be translated to SQL. We also consider examples that do not appear straightforward to translate to SQL, illustrating that the relative expressiveness of flat and nested queries with mixed set and multiset semantics remains an open question.
- P. Buneman, S. Naqvi, V. Tannen, and L. Wong. Principles of programming with complex objects and collection types. Theor. Comput. Sci., 149(1), 1995.Google Scholar
- J. Cheney, S. Lindley, and P. Wadler. Query shredding: efficient relational evaluation of queries over nested multisets. In SIGMOD, pages 1027–1038. ACM, 2014. Google ScholarDigital Library
- E. Cooper. The script-writer’s dream: How to write great SQL in your own language, and be sure it will succeed. In DBPL, 2009. Google ScholarDigital Library
- E. Cooper, S. Lindley, P. Wadler, and J. Yallop. Links: web programming without tiers. In FMCO, 2007. Google ScholarDigital Library
- L. Fegaras and D. Maier. Optimizing object queries using an effective calculus. ACM Trans. Database Syst., 25(4):457–516, 2000. Google ScholarDigital Library
- S. Fehrenbach and J. Cheney. Language-integrated provenance by trace analysis. 2019. arXiv:1905.02051.Google Scholar
- S. K. Lellahi and V. Tannen. A calculus for collections and aggregates. In CTCS, pages 261–280, 1997. Google ScholarDigital Library
- E. Meijer, B. Beckman, and G. M. Bierman. LINQ: reconciling object, relations and XML in the .NET framework. In SIGMOD, 2006. Google ScholarDigital Library
- J. Paredaens and D. V. Gucht. Converting nested algebra expressions into flat algebra expressions. ACM Trans. Database Syst., 17(1), 1992. Google ScholarDigital Library
- W. Ricciotti and J. Cheney. Mixing set and bag semantics. 2019. arXiv:1905.02069.Google Scholar
- A. Ulrich and T. Grust. The flatter, the better: Query compilation based on the flattening transformation. In SIGMOD, pages 1421–1426. ACM, 2015. Google ScholarDigital Library
- L. Wong. Normal forms and conservative extension properties for query languages over collection types. J. Comput. Syst. Sci., 52(3), 1996. Google ScholarDigital Library
- L. Wong. Kleisli, a functional query system. J. Funct. Programming, 10(1), 2000.Google ScholarDigital Library
Index Terms
- Mixing set and bag semantics
Recommendations
Equivalence of queries combining set and bag-set semantics
PODS '06: Proceedings of the twenty-fifth ACM SIGMOD-SIGACT-SIGART symposium on Principles of database systemsThe query equivalence problem has been studied extensively for set-semantics and, more recently, for bag-set semantics. However, SQL queries often combine set and bag-set semantics. For example, an SQL query that returns a multiset of elements may call ...
Query shredding: efficient relational evaluation of queries over nested multisets
SIGMOD '14: Proceedings of the 2014 ACM SIGMOD International Conference on Management of DataNested relational query languages have been explored extensively, and underlie industrial language-integrated query systems such as Microsoft's LINQ. However, relational databases do not natively support nested collections in query results. This can ...
Query containment under bag and bag-set semantics
Conjunctive queries (CQs) are at the core of query languages encountered in many logic-based research fields such as AI, or database systems. The majority of existing work assumes set semantics but often in real applications the manipulation of ...
Comments