Abstract

Bulk types such as sets, bags, and lists are monads, and therefore support a notation for database queries based on comprehensions. This fact is the basis of much work on database query languages. The monadic structure easily explains most of standard relational algebra---specifically, selections and projections---allowing for an elegant mathematical foundation for those aspects of database query language design. Most, but not all: monads do not immediately offer an explanation of relational join or grouping, and hence important foundations for those crucial aspects of relational algebra are missing. The best they can offer is cartesian product followed by selection. Adjunctions come to the rescue: like any monad, bulk types also arise from certain adjunctions; we show that by paying due attention to other important adjunctions, we can elegantly explain the rest of standard relational algebra. In particular, graded monads provide a mathematical foundation for indexing and grouping, which leads directly to an efficient implementation, even of joins.

Highlights

  • Consider the following SQL query, which computes the names and amounts outstanding of customers with overdue invoices, by joining separate customer and invoice tables: SELECT name, amount FROM customers, invoices WHERE cid = cust AND due < today Standard database techniques [Date 2004] translate this query into applications of relational algebra operations such as projection π, selection σ, and equijoin ▷◁: πname,amount (σdue

  • The novelty in this paper is to show that adjunctions induce monads and comprehensions, which explain relational database selections and projections, and all the other abstract gadgets needed to complete the explanation of the efficient query planÐin particular, of the grouping and merging required for linear-time equijoins

  • Comprehensions as a notation for queries, generalizable to various kinds of collection monad, have for decades been a staple of programming interfaces to data

Read more

Summary

INTRODUCTION

Monads and monad comprehensions provide no direct way to express an equijoin; this can only be expressed indirectly, as a cartesian product followed by a selection This becomes clear if we desugar the Haskell comprehension notation, yielding something equivalent to the following: fmap (λ(c, i) → (c.name, i.amount)) ( filter (λ(c, i) → i.due < today) ( filter (λ(c, i) → c.cid i.cust) ( cp (customers, invoices)))). The novelty in this paper is to show that adjunctions induce monads and comprehensions, which explain relational database selections and projections, and all the other abstract gadgets needed to complete the explanation of the efficient query planÐin particular, of the grouping and merging required for linear-time equijoins. Appendix A (in the online supplementary materials) gives more details of the adjunctions underlying graded monads; Appendix B provides a prototype implementation in HaskellÐintended more as an alternative specification of behaviour than something to be executed

CATEGORY THEORY
Categories
Functors
Natural Transformations
Adjunctions
Monads
Algebras
RELATIONAL ALGEBRA
POINTED SETS
INDEXED TABLES
EQUIJOIN BY INDEXING
GRADED MONADS
QUERY TRANSFORMATION
Projections
Selections
Comprehensions
Combining Joins with Other Operations
CONCLUSION
Full Text
Paper version not known

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.