Skip to main content
Springer Nature - PMC COVID-19 Collection logoLink to Springer Nature - PMC COVID-19 Collection
. 2021 Mar 23;12648:579–606. doi: 10.1007/978-3-030-72019-3_21

Query Lifting

Language-integrated query for heterogeneous nested collections

Wilmer Ricciotti 9,✉, James Cheney 9,10
Editor: Nobuko Yoshida1
PMCID: PMC7984574

Abstract

Language-integrated query based on comprehension syntax is a powerful technique for safe database programming, and provides a basis for advanced techniques such as query shredding or query flattening that allow efficient programming with complex nested collections. However, the foundations of these techniques are lacking: although SQL, the most widely-used database query language, supports heterogeneous queries that mix set and multiset semantics, these important capabilities are not supported by known correctness results or implementations that assume homogeneous collections. In this paper we study language-integrated query for a heterogeneous query language NRCλ(Set,Bag) that combines set and multiset constructs. We show how to normalize and translate queries to SQL, and develop a novel approach to querying heterogeneous nested collections, based on the insight that “local” query subexpressions that calculate nested subcollections can be “lifted” to the top level analogously to lambda-lifting for local function definitions.

Keywords: language-integrated query, nested relations, multisets

Contributor Information

Nobuko Yoshida, Email: tenko.yoshida@gmail.com.

Wilmer Ricciotti, Email: research@wilmer-ricciotti.net.

James Cheney, Email: jcheney@inf.ed.ac.uk.

References

  • 1.Benedikt, M., Pradic, P.: Generating collection transformations from proofs. Proc. ACM Program. Lang. 5(POPL) (Jan 2021), 10.1145/3434295 [DOI]
  • 2.Blelloch, G.E.: Vector Models for Data-Parallel Computing. MIT Press (1990)
  • 3.Buneman, P., Libkin, L., Suciu, D., Tannen, V., Wong, L.: Comprehension syntax. SIGMOD Record 23 (1994)
  • 4.Buneman, P., Naqvi, S., Tannen, V., Wong, L.: Principles of programming with complex objects and collection types. Theor. Comput. Sci. 149(1) (1995). 10.1016/0304-3975(95)00024-Q [DOI]
  • 5.Cao, B., Badia, A.: SQL query optimization through nested relational algebra. ACM Trans. Database Syst. 32(3), 18–es (Aug 2007). 10.1145/1272743.1272748 [DOI]
  • 6.Carette, J., Kiselyov, O., Shan, C.: Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program. 19(5), 509–543 (2009). 10.1017/S0956796809007205 [DOI]
  • 7.Cheney, J., Lindley, S., Wadler, P.: A practical theory of language-integrated query. In: ICFP (2013). 10.1145/2500365.2500586 [DOI]
  • 8.Cheney, J., Lindley, S., Wadler, P.: Query shredding: efficient relational evaluation of queries over nested multisets. In: SIGMOD. pp. 1027–1038. ACM (2014). 10.1145/2588555.2612186 [DOI]
  • 9.Cheney, J., Lindley, S., Wadler, P.: Query shredding: Efficient relational evaluation of queries over nested multisets (extended version). CoRR abs/1404.7078 (2014), http://arxiv.org/abs/1404.7078
  • 10.Chu, S., Weitz, K., Cheung, A., Suciu, D.: HoTTSQL: Proving query rewrites with univalent SQL semantics. In: PLDI. pp. 510–524. ACM (2017). 10.1145/3062341.3062348 [DOI]
  • 11.Cooper, E.: The script-writer’s dream: How to write great SQL in your own language, and be sure it will succeed. In: DBPL (2009). 10.1007/978-3-642-03793-1_3 [DOI]
  • 12.Cooper, E., Lindley, S., Wadler, P., Yallop, J.: Links: web programming without tiers. In: FMCO (2007). 10.1007/978-3-540-74792-5_12 [DOI]
  • 13.Copeland, G., Maier, D.: Making Smalltalk a database system. SIGMOD Rec. 14(2) (1984)
  • 14.Fegaras, L.: An algebra for distributed big data analytics. J. Funct. Program. 27,  e27 (2017). 10.1017/S0956796817000193 [DOI]
  • 15.Fegaras, L., Maier, D.: Optimizing object queries using an effective calculus. ACM Trans. Database Syst. 25(4), 457–516 (2000)
  • 16.Fegaras, L., Srinivasan, C., Rajendran, A., Maier, D.: lambda-DB: An ODMG-based object-oriented DBMS. In: Chen, W., Naughton, J.F., Bernstein, P.A. (eds.) SIGMOD. p. 583. ACM (2000). 10.1145/342009.335494 [DOI]
  • 17.Fehrenbach, S., Cheney, J.: Language-integrated provenance. Science of Computer Programming 155, 103–145 (2018)
  • 18.Foster, J.N., Green, T.J., Tannen, V.: Annotated XML: queries and provenance. In: PODS. pp. 271–280 (2008)
  • 19.Fowler, S., Harding, S., Sharman, J., Cheney, J.: Cross-tier web programming for curated databases: a case study. International Journal of Digital Curation 15(1) (2020). 10.2218/ijdc.v15i1.717, pre-print presented at IDCC 2020 [DOI]
  • 20.Gibbons, J., Henglein, F., Hinze, R., Wu, N.: Relational algebra by way of adjunctions. Proc. ACM Program. Lang. 2(ICFP) (Jul 2018). 10.1145/3236781 [DOI]
  • 21.Giorgidze, G., Grust, T., Schreiber, T., Weijers, J.: Haskell boards the Ferry - database-supported program execution for Haskell. In: IFL. pp. 1–18. No. 6647 in LNCS, Springer-Verlag (2010)
  • 22.Giorgidze, G., Grust, T., Ulrich, A., Weijers, J.: Algebraic data types for language-integrated queries. In: DDFP. pp. 5–10 (2013)
  • 23.Green, T.J., Karvounarakis, G., Tannen, V.: Provenance semirings. In: PODS (2007)
  • 24.Grust, T., Mayr, M., Rittinger, J.: Let SQL drive the XQuery workhorse (XQuery join graph isolation). In: EDBT. pp. 147–158 (2010). 10.1145/1739041.1739062 [DOI]
  • 25.Grust, T., Mayr, M., Rittinger, J., Schreiber, T.: Ferry: Database-supported program execution. In: SIGMOD (June 2009)
  • 26.Grust, T., Rittinger, J., Schreiber, T.: Avalanche-safe LINQ compilation. PVLDB 3(1) (2010)
  • 27.Grust, T., Rittinger, J., Teubner, J.: Pathfinder: XQuery off the relational shelf. IEEE Data Eng. Bull. 31(4) (2008)
  • 28.Grust, T., Scholl, M.H.: How to comprehend queries functionally. J. Intell. Inf. Syst. 12(2-3), 191–218 (1999). 10.1023/A:1008705026446 [DOI]
  • 29.Grust, T., Ulrich, A.: First-class functions for first-order database engines. In: DBPL (2013), http://arxiv.org/abs/1308.0158
  • 30.Johnsson, T.: Lambda lifting: Treansforming programs to recursive equations. In: FPCA. pp. 190–203 (1985). 10.1007/3-540-15975-4_37 [DOI]
  • 31.Katsushima, T., Kiselyov, O.: Language-integrated query with ordering, grouping and outer joins (poster paper). In: PEPM. pp. 123–124 (2017)
  • 32.Kiselyov, O., Katsushima, T.: Sound and efficient language-integrated query - maintaining the ORDER. In: APLAS 2017. pp. 364–383 (2017). 10.1007/978-3-319-71237-6_18 [DOI]
  • 33.Libkin, L., Wong, L.: Query languages for bags and aggregate functions. J. Comput. Syst. Sci. 55(2) (1997). 10.1006/jcss.1997.1523 [DOI]
  • 34.Lindley, S., Cheney, J.: Row-based effect types for database integration. In: TLDI (2012). 10.1145/2103786.2103798 [DOI]
  • 35.Lindley, S., Wadler, P.: The audacity of hope: Thoughts on reclaiming the database dream. In: ESOP (2010)
  • 36.Meijer, E., Beckman, B., Bierman, G.M.: LINQ: reconciling object, relations and XML in the .NET framework. In: SIGMOD (2006). 10.1145/1142473.1142552 [DOI]
  • 37.Minamide, Y., Morrisett, J.G., Harper, R.: Typed closure conversion. In: POPL. pp. 271–283 (1996). 10.1145/237721.237791 [DOI]
  • 38.Neumann, T., Kemper, A.: Unnesting arbitrary queries. In: Datenbanksysteme für Business, Technologie und Web (BTW). pp. 383–402 (2015)
  • 39.Okura, R., Kameyama, Y.: Language-integrated query with nested data structures and grouping. In: FLOPS. pp. 139–158 (2020). 10.1007/978-3-030-59025-3_9 [DOI]
  • 40.Paredaens, J., Van Gucht, D.: Converting nested algebra expressions into flat algebra expressions. ACM Trans. Database Syst. 17(1) (1992). 10.1145/128765.128768 [DOI]
  • 41.Quill: Compile-time language integrated queries for Scala. Open source project, https://github.com/getquill/quill
  • 42.Ricciotti, W., Cheney, J.: Mixing set and bag semantics. In: DBPL. pp. 70–73 (2019). 10.1145/3315507.3330202 [DOI]
  • 43.Ricciotti, W., Cheney, J.: Strongly normalizing higher-order relational queries. In: FSCD. pp. 28:1–28:22 (2020). 10.4230/LIPIcs.FSCD.2020.28 [DOI]
  • 44.Ricciotti, W., Cheney, J.: Query lifting: Language-integrated query for heterogeneous nested collections. ArXiv e-prints (2021), https://arxiv.org/abs/2101.04102
  • 45.Russell, C.: Bridging the object-relational divide. Queue 6 (May 2008). 10.1145/1394127.1394139 [DOI]
  • 46.Schek, H., Scholl, M.H.: The relational model with relation-valued attributes. Inf. Syst. 11(2), 137–147 (1986). 10.1016/0306-4379(86)90003-7 [DOI]
  • 47.Stolarek, J., Cheney, J.: Language-integrated provenance in Haskell. The Art, Science, and Engineering of Programming 2(3),  A11 (2018)
  • 48.Suzuki, K., Kiselyov, O., Kameyama, Y.: Finally, safely-extensible and efficient language-integrated query. In: PEPM. pp. 37–48 (2016). 10.1145/2847538.2847542 [DOI]
  • 49.Syme, D.: Leveraging .NET meta-programming components from F#: integrated queries and interoperable heterogeneous execution. In: ML Workshop (2006)
  • 50.Trinder, P., Wadler, P.: Improving list comprehension database queries. In: TENCON ’89. (1989). 10.1109/TENCON.1989.176921 [DOI]
  • 51.Ulrich, A.: A Ferry-based query backend for the Links programming language. Master’s thesis, University of Tübingen (2011)
  • 52.Ulrich, A.: Query Flattening and the Nested Data Parallelism Paradigm. Ph.D. thesis, University of Tübingen, Germany (2019)
  • 53.Ulrich, A., Grust, T.: The flatter, the better: Query compilation based on the flattening transformation. In: SIGMOD. pp. 1421–1426. ACM (2015). 10.1145/2723372.2735359 [DOI]
  • 54.Van den Bussche, J.: Simulation of the nested relational algebra by the flat relational algebra, with an application to the complexity of evaluating powerset algebra expressions. Theor. Comput. Sci. 254(1-2) (2001)
  • 55.Wong, L.: Normal forms and conservative extension properties for query languages over collection types. J. Comput. Syst. Sci. 52(3) (1996). 10.1006/jcss.1996.0037 [DOI]
  • 56.Wong, L.: Kleisli, a functional query system. J. Funct. Program. 10(1) (2000). 10.1017/S0956796899003585 [DOI]

Articles from Programming Languages and Systems are provided here courtesy of Nature Publishing Group

RESOURCES