PostgreSQL with JIT compiler for expressions
This is a modified version of PostgreSQL with just-in-time compiler for expressions. Current base version is 9.6.1. Just-in-time compiler (JIT for short) improves database performance significantly on OLAP queries. This version uses LLVM JIT for query compilation and shows up to 20% improvement on TPC-H tests.
- LLVM version 3.7
The easiest way is to follow the process of building vanilla PostgreSQL. LLVM JIT compiler for expressions is enabled by default.
The most basic procedure is as follows:
$ git clone https://github.com/ispras/postgres $ cd postgres $ ./configure [configure options] $ make [make options] -jN
||Disables expression compilation with LLVM JIT.|
||Specify your own
||Parallelize compilation by splitting LLVM backend file, N — number of functions in each file (50 by default).|
PostgreSQL GUC settings
||Enable LLVM JIT of expressions (enabled by default).|
||Dump compiled LLVM IR (developer option, disabled by default).|
||Disable optimization of generated LLVM modules (developer option, disabled by default).|
Internally, evaluation of each individual expression in PostgreSQL happens by means of calling a function pointer which is stored in the expression object and initialized during expression initialization phase with the address of the corresponding execution function.
Expression JIT presented here works by hooking into expression initialization phase and replacing this pointer with address of a function generated for the expression at run time.
Advice for developers
- Enabling assertions (configure with
--enable-cassertoption) also turns on LLVM module verification.
debug_llvm_jitto on to explore compiled code.
LLVM dumps are stored in the
llvm_dump subdirectory in the database directory. Each compiled expression is written into three files (substitute
### with expression number):
expr.###— expression tree, in the “pretty-print” format.
dump.###.opt.ll— LLVM assembly files generated for expression.
- LLVM Cauldron 2016: Speeding up query execution in PostgreSQL using LLVM JIT (slides)
- PgCon 2016 Lighting Talks presentation (slides)
- Dynamic compilation of expressions in SQL queries for PostgreSQL (paper in Russian, abstract in English)
- PgConf.Russia 2016: Speeding up query execution in PostgreSQL using LLVM JIT compiler (slides in Russian)