# Mixing set and bag semantics

**Authors:** Wilmer Ricciotti, James Cheney

arXiv: 1905.02069 · 2019-05-07

## TL;DR

This paper explores the formal foundations of queries that combine set and bag semantics, introducing a calculus, rewrite rules, and translation considerations, highlighting open questions about their expressiveness.

## Contribution

It formalizes the problem of mixed set and bag query semantics, proposes a calculus with rewrite rules, and characterizes queries translatable to SQL.

## Key findings

- Introduces a calculus with set and multiset types
- Provides rewrite rules for query normalization
- Characterizes queries translatable to SQL

## 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 normalization have not been studied for queries that mix set and bag collections, or provide duplicate-elimination operations such as SQL's $\mathtt{SELECT}~\mathtt{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.

## Full text

_Full body text omitted from this summary view._ Fetch the complete paper as Markdown: https://tomesphere.com/paper/1905.02069/full.md

## Figures

4 figures with captions in the complete paper: https://tomesphere.com/paper/1905.02069/full.md

## References

12 references — full list in the complete paper: https://tomesphere.com/paper/1905.02069/full.md

---
Source: https://tomesphere.com/paper/1905.02069