This page in other versions: Development versions: devel / 11

32.1. What is JIT compilation?

Just-in-time compilation (JIT) is the process of turning some form of interpreted program evaluation into a native program, and doing so at run time. For example, instead of using a facility that can evaluate arbitrary SQL expressions to evaluate an SQL predicate like WHERE a.col = 3, it is possible to generate a function than can be natively executed by the CPU that just handles that expression, yielding a speedup.

PostgreSQL has builtin support to perform JIT compilation using LLVM when PostgreSQL was built with --with-llvm (see --with-llvm).

See src/backend/jit/README for further details.

32.1.1. JIT Accelerated Operations

Currently PostgreSQL's JIT implementation has support for accelerating expression evaluation and tuple deforming. Several other operations could be accelerated in the future.

Expression evaluation is used to evaluate WHERE clauses, target lists, aggregates and projections. It can be accelerated by generating code specific to each case.

Tuple deforming is the process of transforming an on-disk tuple (see Section 68.6.1) into its in-memory representation. It can be accelerated by creating a function specific to the table layout and the number of columns to be extracted.

32.1.2. Optimization

LLVM has support for optimizing generated code. Some of the optimizations are cheap enough to be performed whenever JIT is used, while others are only beneficial for longer running queries. See https://llvm.org/docs/Passes.html#transform-passes for more details about optimizations.

32.1.3. Inlining

PostgreSQL is very extensible and allows new data types, functions, operators and other database objects to be defined; see Chapter 38. In fact the built-in ones are implemented using nearly the same mechanisms. This extensibility implies some overhead, for example due to function calls (see Section 38.3). To reduce that overhead JIT compilation can inline the body for small functions into the expression using them. That allows a significant percentage of the overhead to be optimized away.

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group