Language-Integrated Query with Nested Data Structures and Grouping

被引:3
|
作者
Okura, Rui [1 ]
Kameyama, Yukiyoshi [1 ]
机构
[1] Univ Tsukuba, Tsukuba, Ibaraki, Japan
关键词
Database; Language-integrated query; Grouping; Aggregation; Normalization; Type safety;
D O I
10.1007/978-3-030-59025-3_9
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Language-integrated query adds to database query the power of highlevel programming languages such as abstraction, compositionality, and nested data structures. Cheney et al. designed a two-level typed language for it and showed that any closed term of suitable type can be normalized to a single SQL query which does not have nested data structures nor nested SELECT clauses. This paper extends their language to cover the GROUP BY clause in SQL to express grouping and aggregate functions. Although the GROUP BY clause is frequently used, it is not covered by existing studies on efficient implementation of language-integrated queries. In fact, it seems impossible to express composition of two aggregate functions by a single aggregate function, therefore, there exists a query with nested GROUP BY clauses which has no equivalent query without nested one. However, since several database engines such as PostgreSQL allow nested queries, we can still ask if it is possible to convert an arbitrary query with grouping and aggregation to a single query in SQL which allows nested queries, but disallows nested data structures such as a table of tables. This paper solves the latter question affirmatively. Our key observation is that the GROUP BY clause in SQL does two different kinds of things: manipulating input/output data and grouping with aggregation, the former can be transformed, but may have complex types, while the latter cannot be transformed, but has simple types. Hence, we decouple the GROUP BY clause and introduce primitives into our language-integrated query to obtain a calculus which can express GROUP BY. We then show our language has the normalization property that every query is converted to a single query which does not have nested data structures. We conduct simple benchmarks which show that queries in our language can be transformed to efficient SQL queries.
引用
收藏
页码:139 / 158
页数:20
相关论文
共 50 条
  • [1] Query Lifting Language-integrated query for heterogeneous nested collections
    Ricciotti, Wilmer
    Cheney, James
    [J]. PROGRAMMING LANGUAGES AND SYSTEMS, ESOP 2021, 2021, 12648 : 579 - 606
  • [2] Language-Integrated Query with Ordering, Grouping and Outer Joins (Poster Paper)
    Katsushima, Tatsuya
    Kiselyov, Oleg
    [J]. PROCEEDINGS OF THE 2017 ACM SIGPLAN WORKSHOP ON PARTIAL EVALUATION AND PROGRAM MANIPULATION (PEPM'17), 2017, : 123 - 124
  • [3] The optics of language-integrated query
    Lopez-Gonzalez, J.
    Serrano, Juan M.
    [J]. SCIENCE OF COMPUTER PROGRAMMING, 2020, 190 (190)
  • [4] A Practical Theory of Language-Integrated Query
    Cheney, James
    Lindley, Sam
    Wadler, Philip
    [J]. ACM SIGPLAN NOTICES, 2013, 48 (09) : 403 - 416
  • [5] Optimisation of language-integrated queries by query unnesting
    Kowalski, Tomasz Marek
    Adamus, Radoslaw
    [J]. COMPUTER LANGUAGES SYSTEMS & STRUCTURES, 2017, 47 : 131 - 150
  • [6] Effective Quotation Relating approaches to language-integrated query
    Cheney, James
    Lindley, Sam
    Radanne, Gabriel
    Wadler, Philip
    [J]. PEPM '14: PROCEEDINGS OF THE ACM SIGPLAN WORKSHOP ON PARTIAL EVALUATION AND PROGRAM MANIPULATION, 2014, : 15 - 26
  • [7] Sound and Efficient Language-Integrated Query Maintaining the ORDER
    Kiselyov, Oleg
    Katsushima, Tatsuya
    [J]. PROGRAMMING LANGUAGES AND SYSTEMS (APLAS 2017), 2017, 10695 : 364 - 383
  • [8] Finally, Safely-Extensible and Efficient Language-Integrated Query
    Suzuki, Kenichi
    Kiselyov, Oleg
    Kameyama, Yukiyoshi
    [J]. PEPM'16: PROCEEDINGS OF THE 2016 ACM SIGPLAN WORKSHOP ON PARTIAL EVALUATION AND PROGRAM MANIPULATION, 2016, : 37 - 48
  • [9] Rhyme: A Data-Centric Expressive Query Language for Nested Data Structures
    Abeysinghe, Supun
    Rompf, Tiark
    [J]. PRACTICAL ASPECTS OF DECLARATIVE LANGUAGES, PADL 2024, 2023, 14512 : 64 - 81
  • [10] Language-integrated Provenance
    Fehrenbach, Stefan
    Cheney, James
    [J]. PROCEEDINGS OF THE 18TH INTERNATIONAL SYMPOSIUM ON PRINCIPLES AND PRACTICE OF DECLARATIVE PROGRAMMING (PPDP 2016), 2016, : 214 - 227