Functional Pearl: A SQL to C Compiler in 500 Lines of Code

被引:0
|
作者
Rompf, Tiark [1 ]
Amin, Nada [2 ]
机构
[1] Purdue Univ, W Lafayette, IN 47907 USA
[2] Ecole Polytech Fed Lausanne, Lausanne, Switzerland
关键词
SQL; Query Compilation; Staging; Generative Programming; Futamura Projections;
D O I
暂无
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
We present the design and implementation of a SQL query processor that outperforms existing database systems and is written in just about 500 lines of Scala code -a convincing case study that high-level functional programming can handily beat C for systems-level programming where the last drop of performance matters. The key enabler is a shift in perspective towards generative programming. The core of the query engine is an interpreter for relational algebra operations, written in Scala. Using the opensource LMS Framework (Lightweight Modular Staging), we turn this interpreter into a query compiler with very low effort. To do so, we capitalize on an old and widely known result from partial evaluation known as Futamura projections, which state that a program that can specialize an interpreter to any given input program is equivalent to a compiler. In this pearl, we discuss LMS programming patterns such as mixed-stage data structures (e.g. data records with static schema and dynamic field components) and techniques to generate low-level C code, including specialized data structures and data loading primitives.
引用
下载
收藏
页码:2 / 9
页数:8
相关论文
共 47 条
  • [1] Functional Pearl: A SQL to C Compiler in 500 Lines of Code
    Rompf, Tiark
    Amin, Nada
    ACM SIGPLAN NOTICES, 2015, 50 (09) : 2 - 9
  • [2] A SQL to C compiler in 500 lines of code
    Rompf, Tiark
    Amin, Nada
    JOURNAL OF FUNCTIONAL PROGRAMMING, 2019, 29
  • [3] Monadic Compiler Calculation (Functional Pearl)
    Bahr, Patrick
    Hutton, Graham
    PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2022, 6 (ICFP):
  • [4] The Next 700 Compiler Correctness Theorems (Functional Pearl)
    Patterson, Daniel
    Ahmed, Amal
    PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2019, 3 (ICFP):
  • [5] 'C and tcc: A language and compiler for dynamic code generation
    Poletto, M
    Hsieh, WC
    Engler, DR
    Kaashoek, MF
    ACM TRANSACTIONS ON PROGRAMMING LANGUAGES AND SYSTEMS, 1999, 21 (02): : 324 - 369
  • [6] DSP C compiler raises the bar in code density
    Bindra, A
    ELECTRONIC DESIGN, 2001, 49 (20) : 28 - 28
  • [7] C-COMPILER IN ONE PASS OPTIMIZES SOURCE CODE
    WALLER, L
    ELECTRONICS-US, 1983, 56 (21): : 48 - 49
  • [8] hcc - A portable ANSI C compiler (with a code generator for the PowerPCs)
    Abdullah, MH
    ACM SIGPLAN NOTICES, 1996, 31 (08) : 52 - 59
  • [9] PLINER: Isolating Lines of Floating-Point Code for Compiler-Induced Variability
    Guo, Hui
    Laguna, Ignacio
    Rubio-Gonzalez, Cindy
    PROCEEDINGS OF SC20: THE INTERNATIONAL CONFERENCE FOR HIGH PERFORMANCE COMPUTING, NETWORKING, STORAGE AND ANALYSIS (SC20), 2020,
  • [10] The Impact of Compiler Warnings on Code Quality in C plus plus Projects
    Johansson, Albin
    Holmberg, Carl
    Neto, Francisco G. de Oliveira
    Leitner, Philipp
    PROCEEDINGS 2024 32ND IEEE/ACM INTERNATIONAL CONFERENCE ON PROGRAM COMPREHENSION, ICPC 2024, 2024, : 270 - 279