Preview

Proceedings of the Institute for System Programming of the RAS (Proceedings of ISP RAS)

Advanced search

Beyond LLVM: Evaluating Fast Code Generation Alternatives for Query Compilation in PostgreSQL

https://doi.org/10.15514/ISPRAS-2025-37(6)-21

Abstract

The evolution of query compilation in database management systems traces back to System R, which pioneered a code generation scheme where small machine code fragments were stitched together to form a specialized routine to process a given SQL statement. Subsequent approaches shifted to generating C code, compiling it with system compilers like GCC into dynamic libraries, and loading them at runtime. The current state-of-the-art standard for dynamic query compilation is the LLVM framework, which bypasses frontend compiler overhead by directly generating intermediate representation, enabling machine-independent optimizations and efficient machine code generation. LLVM's resource-intensive nature, primarily designed as an optimizing compiler, however, can lead to compilation times that are orders of magnitude longer than query execution times, particularly problematic for queries with millisecond-level interpretation costs. This paper evaluates two lightweight code generation frameworks for x86-64 architecture as alternatives to LLVM in PostgreSQL, assessing their code generation speed and the quality of emitted machine code. We present a qualitative comparison with LLVM, analyzing trade-offs between compilation latency and runtime performance across databases of varying sizes. Experimental results demonstrate that lightweight code generation can not only outperform LLVM on small-scale datasets but also maintain competitive performance on larger ones.

About the Authors

Mikhail Vyacheslavovich PANTILIMONOV
Ivannikov Institute for System Programming of the Russian Academy of Sciences
Russian Federation

Researcher at Compiler Technology department of ISP RAS. Research interests: static analysis, compiler technologies, DBMS.



Ruben Arturovich BUCHATSKIY
Ivannikov Institute for System Programming of the Russian Academy of Sciences
Russian Federation

Cand. Sci. (Tech.), researcher at Compiler Technology department of ISP RAS. Research interests: static analysis, compiler technologies, optimizations.



Denis Vladislavovich ZAVEDEEV
Ivannikov Institute for System Programming of the Russian Academy of Sciences
Russian Federation

Postgraduate student at Ivannikov Institute for System Programming of the Russian Academy of Sciences. Research interests: compilers, language virtual machines.



References

1. PostgreSQL – open Source DBMS. [Online], Available at: https://www.postgresql.org, accessed 05.05.2025.

2. G. Graefe, “Volcano - An Extensible and Parallel Query Evaluation System,” IEEE Trans. Knowl. Data Eng., vol. 6, no. 1, pp. 120-135, 1994. DOI: 10.1109/69.273032. [Online], Available at:

3. https://doi.org/10.1109/69.273032.

4. T. Neumann, “Efficiently Compiling Efficient Query Plans for Modem Hardware,” PVLDB, vol. 4, no. 9, pp. 539-550, 2011. DOI: 10.14778/2002938.2002940. [Online], Available at: http://www.vldb.org/pvldb/vol4/p539-neumann.pdf.

5. PostgreSQL mailing lists, “[GSoC] Push-based query executor discussion.” [Online], Available at: https://www.postgresql.org/message-id/87shm1zfnz.fsf%40ispras.ru, accessed 05.05.2025.

6. A. Shaikhha, M. Dashti and C. Koch, «Push vs. pull-based loop fusion in query engines», CoRR, abs/1610.09166, 2016 arXiv: 1610.09166. Available at: https://arxiv.org/abs/1610.09166.

7. PostgreSQL 10.0 Release Notes, [Online] Available at: https://www.postgresql.org/docs/release/10.0, accessed 05.05.2025.

8. GitHub, Mirror of the official PostgreSQL GIT repository, “Faster expression evaluation and targetlist projection.” Commit SHA: b8d7f053c5c2bf2a7e8734fe3327f6a8bc711755 [Online], Available at: https://github.com/postgres/postgres/commit/b8d7f053c5c2bf2a7e8734fe3327f6a8bc711755, accessed 05.05.2025.

9. PGCon 2017. A. Freund Integrating Just In Time Compilation, [Online] Available at: https://www.pgcon.org/2017/schedule/attachments/462_jit-pgcon-2017-05-25.pdf, accessed 05.05.2025.

10. The LLVM Foundation, The LLVM Compiler Infrastructure. [Online] Available at: https://llvm.org, accessed 05.05.2025.

11. PGCon 2018. A. Freund A.The State of Postgres JIT – 2018 Edition, [Online] Available at: https://anarazel.de/talks/2018-06-01-pgcon-state-of-jit/state-of-jit.pdf, accessed 05.05.2025.

12. A. Engelke and T Schwarz. 2024. Compile-Time Analysis of Compiler Frameworks for Query Compilation. In Proceedings of the 2024 IEEE/ACM International Symposium on Code Generation and Optimization (CGO '24). IEEE Press, 233–244. DOI: https://doi.org/10.1109/CGO57630.2024.10444856.

13. A. Kohn, V. Leis, T. Neumann “Adaptive Execution of Compiled Queries”, 2018 IEEE 34th International Conference on Data Engineering (ICDE), Paris, France, 2018, pp. 197-208, DOI: 10.1109/ICDE.2018.00027.

14. T. Kersten, V. Leis, T. Neumann “Tidy Tuples and Flying Start: fast compilation and fast execution of relational queries in Umbra” The VLDB Journal 30, 5 (Sep 2021), 883–905. [Online], Available at: https://doi.org/10.1007/s00778-020-00643-4.

15. Transaction Processing Performance Council, "TPC-H Benchmark." [Online]. Available at: http://www.tpc.org/tpch, accessed 05.05.2025.

16. GCC, the GNU Compiler Collection, [Online], Available at: https://gcc.gnu.org/, accessed 05.05.2025.

17. V8 JavaScript Engine, [Online], Available at: https://v8.dev/, accessed 05.05.2025.

18. OpenJDK, The HotSpot Group, [Online], Available at: https://openjdk.org/groups/hotspot/, accessed 05.05.2025.

19. DotNet, RyuJIT compiler overview, [Online], Available at: https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/jit/ryujit-overview.md, accessed 05.05.2025.

20. Parrot Virtual Machine, [Online], Available at: http://www.parrot.org/, accessed 05.05.2025.

21. MoarVM, a VM for NQP and Rakudo, [Online], Available at: https://www.moarvm.org/, accessed 05.05.2025.

22. GNU LibJIT – backend for DotGNU Portable.NET JIT engine, [Online], Available at: https://www.gnu.org/software/libjit, accessed 05.05.2025.

23. DynASM – dynamic assembler for code generation engines. [Online], Available at: https://luajit.org/dynasm.html, accessed 05.05.2025.

24. AsmJIT – lightweight library for low-latency machine code generation. [Online], Available at: https://asmjit.com, accessed 05.05.2025.

25. GNU lightning – library that generates assembly language code at run-time. [Online], Available at: https://www.gnu.org/software/lightning/, accessed 05.05.2025.

26. sljit – a low-level, platform-independent JIT compiler. [Online], Available at: https://zherczeg.github.io/sljit/, accessed 05.05.2025.

27. Xbyak – a JIT assembler for x86/x64 architectures. [Online], Available at: https://github.com/herumi/xbyak, accessed 05.05.2025.

28. M. Pall, “LuaJIT 2.0 intellectual property disclosure and research opportunities”, [Online], Available at: http://lua-users.org/lists/lua-l/2009-11/msg00089.html, accessed 05.05.2025.

29. Erlang/OTP documentation “BeamAsm, the Erlang JIT”, [Online] Available at: https://www.erlang.org/doc/apps/erts/beamasm.html, accessed 05.05.2025.


Review

For citations:


PANTILIMONOV M.V., BUCHATSKIY R.A., ZAVEDEEV D.V. Beyond LLVM: Evaluating Fast Code Generation Alternatives for Query Compilation in PostgreSQL. Proceedings of the Institute for System Programming of the RAS (Proceedings of ISP RAS). 2025;37(6):77-92. https://doi.org/10.15514/ISPRAS-2025-37(6)-21



Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 License.


ISSN 2079-8156 (Print)
ISSN 2220-6426 (Online)