How to Comprehend Queries Functionally

Compilers and optimizers for declarative query languages use some form of intermediate language to represent user-level queries. The advent of compositional query languages for orthogonal type systems (e.g., OQL) calls for internal query representations beyond extensions of relational algebra. This work adopts a view of query processing which is greatly influenced by ideas from the functional programming domain. A uniform formal framework is presented which covers all query translation phases, including user-level query language compilation, query optimization, and execution plan generation. We pursue the type-based design—based on initial algebras—of a core functional language which is then developed into an intermediate representation that fits the needs of advanced query processing. Based on the principle of structural recursion we extend the language by monad comprehensions (which provide us with a calculus-style sublanguage that proves to be useful during the optimization of nested queries) and combinators (abstractions of the query operators implemented by the underlying target query engine). Due to its functional nature, the language is susceptible to program transformation techniques that were developed by the functional programming as well as the functional data model communities. We show how database query processing can substantially benefit from these techniques.

[1]  David J. DeWitt,et al.  A transformation-based approach to optimizing loops in database programming languages , 1992, SIGMOD '92.

[2]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1988, Theoretical Computer Science.

[3]  Goetz Graefe,et al.  Query evaluation techniques for large databases , 1993, CSUR.

[4]  David Jordan,et al.  The Object Database Standard: ODMG 2.0 , 1997 .

[5]  Limsoon Wong,et al.  Naturally Embedded Query Languages , 1992, ICDT.

[6]  Alexandra Poulovassilis,et al.  Algebraic query optimisation for database programming languages , 1996, The VLDB Journal.

[7]  Philip Wadler,et al.  Comprehending monads , 1990, LISP and Functional Programming.

[8]  Goetz Graefe,et al.  Encapsulation of parallelism in the Volcano query processing system , 1990, SIGMOD '90.

[9]  Guido Moerkotte,et al.  Optimizing Queries with Universal Quantification in Object-Oriented and Object-Relational Databases , 1997, VLDB.

[10]  Maarten M. Fokkinga,et al.  Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire , 1991, FPCA.

[11]  Limsoon Wong,et al.  Querying Nested Collections , 1994 .

[12]  Alexandra Poulovassilis,et al.  Formal Foundations for Optimising Aggregation Functions in Database Programming Languages , 1997, DBPL.

[13]  Hans-Jörg Schek,et al.  The relational model with relation-valued attributes , 1986, Inf. Syst..

[14]  Alexandra Poulovassilis,et al.  Extending the Functional Data Model to Computational Completeness , 1990, EDBT.

[15]  Simon L. Peyton Jones,et al.  Report on the programming language Haskell: a non-strict, purely functional language version 1.2 , 1992, SIGP.

[16]  Ryohei Nakano Translation with optimization from relational calculus to relational algebra having aggregate functions , 1990, TODS.

[17]  Guido Moerkotte,et al.  Bypassing Joins in Disjunctive Queries , 1995, VLDB.

[18]  Query Deforestation , 1998 .

[19]  Torsten Grust,et al.  Incremental Updates for Materialized OQL Views , 1997, DOOD.

[20]  R. G. G. Cattell,et al.  The Object Database Standard: ODMG-93 , 1993 .

[21]  Guido Moerkotte,et al.  Nested Queries in Object Bases , 1993, DBPL.

[22]  John Darlington,et al.  A Transformation System for Developing Recursive Programs , 1977, J. ACM.

[23]  H. J. Steenhagen,et al.  Optimization of Object Query Languages , 1995 .

[24]  Bennet Vance,et al.  Towards an object-oriented query algebra , 1992 .

[25]  Peter M. G. Apers,et al.  From Nested-Loop to Join Queries in OODB , 1994, VLDB.

[26]  Dan Suciu,et al.  On Two Forms of Structural Recursion , 1995, ICDT.

[27]  Grant Malcolm Homomorphisms and Promotability , 1989, MPC.

[28]  Torsten Grust,et al.  Query Evaluation in CROQUE - Calculus and Algebra Coincide , 1997, BNCOD.

[29]  Peter M. D. Gray,et al.  Efficient Access to FDM Objects Stored in a Relational Database , 1994, BNCOD.

[30]  Simon L. Peyton Jones,et al.  A short cut to deforestation , 1993, FPCA '93.

[31]  Leonidas Fegaras A Uniform Calculus for Collection Types , 1994 .

[32]  Nathan Goodman,et al.  Translating Aggregate Queries into Iterative Programs , 1986, VLDB.

[33]  Arnon Rosenthal,et al.  Reducing Duplicate Work in Relational Join(s): A Unified Approach , 1993, CISMOD.

[34]  Richard S. Bird,et al.  An introduction to the theory of lists , 1987 .

[35]  Dan Suciu,et al.  Comprehension syntax , 1994, SGMD.

[36]  Torsten Grust,et al.  Translating OQL into Monoid Comprehensions : Stuck with Nested Loops? , 1996 .

[37]  Philip W. Trinder,et al.  Comprehensions, a Query Notation for DBPLs , 1992, DBPL.

[38]  Won Kim,et al.  On optimizing an SQL-like nested query , 1982, TODS.

[39]  Andrew John Gill,et al.  Cheap deforestation for non-strict functional languages , 1996 .

[40]  Nathan Goodman,et al.  On the translation of relational queries into iterative programs , 1989, TODS.

[41]  WadlerPhilip,et al.  Report on the programming language Haskell , 1992 .

[42]  Val Tannen,et al.  Logical and Computational Aspects of Programming with Sets/Bags/Lists , 1991, ICALP.

[43]  Nathan Goodman,et al.  Rule-based transformation of relational queries into iterative programs , 1986, SIGMOD '86.

[44]  John Hughes,et al.  Report on the Programming Language Haskell 98 , 1999 .

[45]  Norman W. Paton,et al.  Optimising and Executing DAPLEX Queries Using Prolog , 1990, Comput. J..

[46]  Atsushi Ohori,et al.  Representing Object Identity in a Pure Functional Language , 1990, ICDT.

[47]  David Maier,et al.  Towards an effective calculus for object query languages , 1995, SIGMOD '95.

[48]  John Launchbury,et al.  Warm fusion: deriving build-catas from recursive definitions , 1995, FPCA '95.

[49]  Leonidas Fegaras Efficient Optimization of Iterative Queries , 1993, DBPL.

[50]  Limsoon Wong,et al.  Principles of Programming with Complex Objects and Collection Types , 1995, Theor. Comput. Sci..