{"status":"ok","message-type":"work","message-version":"1.0.0","message":{"indexed":{"date-parts":[[2026,5,26]],"date-time":"2026-05-26T23:05:51Z","timestamp":1779836751831,"version":"3.53.1"},"reference-count":77,"publisher":"Cambridge University Press (CUP)","license":[{"start":{"date-parts":[[2019,6,3]],"date-time":"2019-06-03T00:00:00Z","timestamp":1559520000000},"content-version":"unspecified","delay-in-days":153,"URL":"https:\/\/www.cambridge.org\/core\/terms"}],"content-domain":{"domain":[],"crossmark-restriction":false},"short-container-title":["J. Funct. Prog."],"published-print":{"date-parts":[[2019]]},"abstract":"<jats:title>Abstract<\/jats:title>\n                  <jats:p>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 \u2013 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.<\/jats:p>","DOI":"10.1017\/s0956796819000054","type":"journal-article","created":{"date-parts":[[2019,6,3]],"date-time":"2019-06-03T04:10:53Z","timestamp":1559535053000},"source":"Crossref","is-referenced-by-count":3,"title":["A SQL to C compiler in 500 lines of code"],"prefix":"10.1017","volume":"29","author":[{"given":"TIARK","family":"ROMPF","sequence":"first","affiliation":[],"role":[{"vocabulary":"crossref","role":"author"}]},{"given":"NADA","family":"AMIN","sequence":"additional","affiliation":[],"role":[{"vocabulary":"crossref","role":"author"}]}],"member":"56","published-online":{"date-parts":[[2019,6,3]]},"reference":[{"key":"S0956796819000054_ref75","volume-title":"PLDI","author":"Tobin-Hochstadt","year":"2011"},{"key":"S0956796819000054_ref74","volume-title":"Partial evaluation for higher-order languages with state","author":"Thiemann","year":"1999"},{"key":"S0956796819000054_ref72","volume-title":"SIGMOD","author":"Tahboub","year":"2018"},{"key":"S0956796819000054_ref67","volume-title":"ECOOP","author":"Sujeeth","year":"2013"},{"key":"S0956796819000054_ref64","volume-title":"PLDI","author":"Sperber","year":"1996"},{"key":"S0956796819000054_ref63","volume-title":"OOPSLA","author":"Shali","year":"2011"},{"key":"S0956796819000054_ref62","volume-title":"SIGMOD","author":"Shaikhha","year":"2016"},{"key":"S0956796819000054_ref60","volume-title":"SNAPL","author":"Rompf","year":"2015"},{"key":"S0956796819000054_ref58","volume-title":"POPL","author":"Rompf","year":"2013"},{"key":"S0956796819000054_ref65","volume-title":"ICDE","author":"Stonebraker","year":"2005"},{"key":"S0956796819000054_ref56","volume-title":"IFIP Working Conference on Domain-Specific Languages (DSL)","volume":"66","author":"Rompf","year":"2011"},{"key":"S0956796819000054_ref55","doi-asserted-by":"publisher","DOI":"10.1145\/2184319.2184345"},{"key":"S0956796819000054_ref54","volume-title":"GPCE","author":"Rompf","year":"2010"},{"key":"S0956796819000054_ref53","doi-asserted-by":"crossref","DOI":"10.1145\/2808091","volume-title":"ICFP","author":"Rompf","year":"2015"},{"key":"S0956796819000054_ref48","author":"Reynolds","year":"1972","journal-title":"Proceedings of the ACM Annual Conference"},{"key":"S0956796819000054_ref46","volume-title":"GPCE","author":"Ofenbeck","year":"2017"},{"key":"S0956796819000054_ref45","doi-asserted-by":"publisher","DOI":"10.1145\/2591013"},{"key":"S0956796819000054_ref44","article-title":"Efficiently compiling efficient query plans for modern hardware","volume":"4","author":"Neumann","year":"2011","journal-title":"PVLDB"},{"key":"S0956796819000054_ref43","volume-title":"SysML","author":"Moldovan","year":"2019"},{"key":"S0956796819000054_ref41","volume-title":"SIGMOD","author":"Mehta","year":"1995"},{"key":"S0956796819000054_ref69","volume-title":"Trends in Functional Programming (TFP)","author":"Svenningsson","year":"2012"},{"key":"S0956796819000054_ref40","volume-title":"ICFP","author":"McDonell","year":"2013"},{"key":"S0956796819000054_ref38","doi-asserted-by":"publisher","DOI":"10.1109\/MM.2011.68"},{"key":"S0956796819000054_ref36","volume-title":"CIDR","author":"Kornacker","year":"2015"},{"key":"S0956796819000054_ref35","article-title":"Building efficient query engines in a high-level language","volume":"7","author":"Klonatos","year":"2014","journal-title":"VLDB"},{"key":"S0956796819000054_ref34","volume-title":"Ershov Memorial Conference","author":"Klimov","year":"2009"},{"key":"S0956796819000054_ref33","volume-title":"EMSOFT","author":"Kiselyov","year":"2004"},{"key":"S0956796819000054_ref31","volume-title":"OOPSLA","author":"Jonnalagedda","year":"2014"},{"key":"S0956796819000054_ref66","volume-title":"PVLDB","author":"Stonebraker","year":"2007"},{"key":"S0956796819000054_ref30","volume-title":"Partial Evaluation and Automatic Program Generation","author":"Jones","year":"1993"},{"key":"S0956796819000054_ref28","doi-asserted-by":"publisher","DOI":"10.1017\/S0960129597002405"},{"key":"S0956796819000054_ref26","volume-title":"ICDE","author":"Graefe","year":"1993"},{"key":"S0956796819000054_ref57","doi-asserted-by":"publisher","DOI":"10.1007\/s10990-013-9096-9"},{"key":"S0956796819000054_ref25","doi-asserted-by":"publisher","DOI":"10.1109\/69.273032"},{"key":"S0956796819000054_ref23","article-title":"Partial evaluation of computation process\u2014An approach to a compiler-compiler","volume":"54","author":"Futamura","year":"1971","journal-title":"Trans. Inst. Electron. Commun. Eng. Jpn"},{"key":"S0956796819000054_ref22","volume-title":"OSDI","author":"Essertel","year":"2018"},{"key":"S0956796819000054_ref16","volume-title":"POPL","author":"Consel","year":"1993"},{"key":"S0956796819000054_ref15","doi-asserted-by":"publisher","DOI":"10.1016\/j.scico.2005.10.013"},{"key":"S0956796819000054_ref14","volume-title":"Workload Characterization and Optimization of tpc-h Queries on Apache Spark","author":"Chiba","year":"2015"},{"key":"S0956796819000054_ref13","doi-asserted-by":"publisher","DOI":"10.1145\/358769.358784"},{"key":"S0956796819000054_ref12","volume-title":"PPoPP","author":"Catanzaro","year":"2011"},{"key":"S0956796819000054_ref11","volume-title":"GPCE","author":"Calcagno","year":"2003"},{"key":"S0956796819000054_ref10","volume-title":"CGO","author":"Brown","year":"2016"},{"key":"S0956796819000054_ref50","unstructured":"Rompf, T. (2012) Lightweight Modular Staging and Embedded Compilers: Abstraction Without Regret for High-Level High-Performance Programming. Ph.D. thesis, EPFL."},{"key":"S0956796819000054_ref7","volume-title":"SIGMOD","author":"Boncz","year":"2006"},{"key":"S0956796819000054_ref6","volume-title":"Domain-Specific Program Generation","volume":"3016","author":"Beckmann","year":"2003"},{"key":"S0956796819000054_ref5","volume-title":"IFL\u201910","author":"Axelsson","year":"2011"},{"key":"S0956796819000054_ref3","volume-title":"SIGMOD","author":"Armbrust","year":"2015"},{"key":"S0956796819000054_ref2","volume-title":"PACMPL","volume":"2","author":"Amin","year":"2018"},{"key":"S0956796819000054_ref1","unstructured":"Ackermann, S. , Jovanovic, V. , Rompf, T. & Odersky, M. (2012) Jet: An embedded DSL for high performance big data processing. In International Workshop on End-to-end Management of Big Data (BigData 2012)."},{"key":"S0956796819000054_ref71","volume-title":"SIGSPATIAL","author":"Tahboub","year":"2016"},{"key":"S0956796819000054_ref42","volume-title":"Partial Evaluation and Mixed Computation","author":"Mogensen","year":"1988"},{"key":"S0956796819000054_ref4","doi-asserted-by":"publisher","DOI":"10.1145\/320455.320457"},{"key":"S0956796819000054_ref59","volume-title":"PLDI","author":"Rompf","year":"2014"},{"key":"S0956796819000054_ref9","volume-title":"PACT","author":"Brown","year":"2011"},{"key":"S0956796819000054_ref70","doi-asserted-by":"publisher","DOI":"10.1016\/S0304-3975(00)00053-0"},{"key":"S0956796819000054_ref8","unstructured":"Bondorf, A. (1990) Self-applicable partial evaluation. Ph.D. thesis, DIKU, Department of Computer Science, University of Copenhagen."},{"key":"S0956796819000054_ref32","volume-title":"POPL","author":"J\u00f8rring","year":"1986"},{"key":"S0956796819000054_ref29","volume-title":"EuroSys","author":"Isard","year":"2007"},{"key":"S0956796819000054_ref18","article-title":"An architecture for compiling UDF-centric workflows","volume":"8","author":"Crotty","year":"2015","journal-title":"PVLDB"},{"key":"S0956796819000054_ref20","volume-title":"PLDI","author":"DeVito","year":"2014"},{"key":"S0956796819000054_ref76","article-title":"MonetDB\/X100 - a DBMS in the CPU cache","volume":"28","author":"Zukowski","year":"2005","journal-title":"IEEE Data Eng. Bull"},{"key":"S0956796819000054_ref27","doi-asserted-by":"publisher","DOI":"10.1016\/S0304-3975(00)00051-7"},{"key":"S0956796819000054_ref73","volume-title":"PEPM","author":"Thiemann","year":"2013"},{"key":"S0956796819000054_ref51","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-319-30936-1_17"},{"key":"S0956796819000054_ref77","volume-title":"ICDE","author":"Krikellas","year":"2010"},{"key":"S0956796819000054_ref39","volume-title":"Haskell Symposium","author":"Mainland","year":"2010"},{"key":"S0956796819000054_ref68","volume-title":"GPCE","author":"Sujeeth","year":"2013b"},{"key":"S0956796819000054_ref37","volume-title":"TACS","volume":"1281","author":"Lawall","year":"1997"},{"key":"S0956796819000054_ref52","volume-title":"Scala Symposium","author":"Rompf","year":"2016"},{"key":"S0956796819000054_ref47","volume-title":"ICDE","author":"Rao","year":"2006"},{"key":"S0956796819000054_ref61","doi-asserted-by":"publisher","DOI":"10.1145\/778559.778561"},{"key":"S0956796819000054_ref24","volume-title":"SIGMOD","author":"Gedik","year":"2008"},{"key":"S0956796819000054_ref17","volume-title":"ACM Trans. Program. Lang. Syst","volume":"15","author":"Consel","year":"1993"},{"key":"S0956796819000054_ref19","volume-title":"PLDI","author":"DeVito","year":"2013"},{"key":"S0956796819000054_ref21","volume-title":"SIGMOD","author":"Diaconu","year":"2013"},{"key":"S0956796819000054_ref49","article-title":"Definitional interpreters for higher-order programming languages","volume":"11","author":"Reynolds","year":"1998","journal-title":"Higherorder Symb. Comput"}],"container-title":["Journal of Functional Programming"],"original-title":[],"language":"en","link":[{"URL":"https:\/\/www.cambridge.org\/core\/services\/aop-cambridge-core\/content\/view\/S0956796819000054","content-type":"unspecified","content-version":"vor","intended-application":"similarity-checking"}],"deposited":{"date-parts":[[2026,5,26]],"date-time":"2026-05-26T22:36:41Z","timestamp":1779835001000},"score":1,"resource":{"primary":{"URL":"https:\/\/www.cambridge.org\/core\/product\/identifier\/S0956796819000054\/type\/journal_article"}},"subtitle":[],"short-title":[],"issued":{"date-parts":[[2019]]},"references-count":77,"alternative-id":["S0956796819000054"],"URL":"https:\/\/doi.org\/10.1017\/s0956796819000054","relation":{},"ISSN":["0956-7968","1469-7653"],"issn-type":[{"value":"0956-7968","type":"print"},{"value":"1469-7653","type":"electronic"}],"subject":[],"published":{"date-parts":[[2019]]},"article-number":"e9"}}