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

被引:0
|
作者
Rompf, Tiark [1 ]
Amin, Nada [1 ]
机构
[1] 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 open-source 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
相关论文
共 1 条