Hostname: page-component-77c78cf97d-rv6c5 Total loading time: 0 Render date: 2026-05-04T01:23:34.750Z Has data issue: false hasContentIssue false

A SQL to C compiler in 500 lines of code

Published online by Cambridge University Press:  03 June 2019

TIARK ROMPF*
Affiliation:
Purdue University, West Lafayette, Indiana, USA (e-mail:tiark@purdue.edu)
NADA AMIN
Affiliation:
University of Cambridge, Computer Laboratory, William Gates Building, 15 JJ Thomson Avenue, Cambridge CB3 0FD, UK (e-mail:na482@cl.cam.ac.uk)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the 'Save PDF' action button.

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 toward generative programming. The core of the query engine is an interpreter for relational-algebra operations, written in Scala. Using the open-source lightweight modular staging framework, 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: the first Futamura projection, which states that a process that can specialize an interpreter to any given input program is equivalent to a compiler. In this context, we discuss lightweight modular staging 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.

Information

Type
Regular Paper
Copyright
© Cambridge University Press 2019 
Submit a response

Discussions

No Discussions have been published for this article.