1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>30.1. What Is JIT compilation?</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="jit.html" title="Chapter 30. Just-in-Time Compilation (JIT)" /><link rel="next" href="jit-decision.html" title="30.2. When to JIT?" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">30.1. What Is <acronym class="acronym">JIT</acronym> compilation?</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="jit.html" title="Chapter 30. Just-in-Time Compilation (JIT)">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="jit.html" title="Chapter 30. Just-in-Time Compilation (JIT)">Up</a></td><th width="60%" align="center">Chapter 30. Just-in-Time Compilation (<acronym class="acronym">JIT</acronym>)</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="jit-decision.html" title="30.2. When to JIT?">Next</a></td></tr></table><hr /></div><div class="sect1" id="JIT-REASON"><div class="titlepage"><div><div><h2 class="title" style="clear: both">30.1. What Is <acronym class="acronym">JIT</acronym> compilation? <a href="#JIT-REASON" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="jit-reason.html#JIT-ACCELERATED-OPERATIONS">30.1.1. <acronym class="acronym">JIT</acronym> Accelerated Operations</a></span></dt><dt><span class="sect2"><a href="jit-reason.html#JIT-INLINING">30.1.2. Inlining</a></span></dt><dt><span class="sect2"><a href="jit-reason.html#JIT-OPTIMIZATION">30.1.3. Optimization</a></span></dt></dl></div><p>
3 Just-in-Time (<acronym class="acronym">JIT</acronym>) compilation is the process of turning
4 some form of interpreted program evaluation into a native program, and
6 For example, instead of using general-purpose code that can evaluate
7 arbitrary SQL expressions to evaluate a particular SQL predicate
8 like <code class="literal">WHERE a.col = 3</code>, it is possible to generate a
9 function that is specific to that expression and can be natively executed
10 by the CPU, yielding a speedup.
12 <span class="productname">PostgreSQL</span> has builtin support to perform
13 <acronym class="acronym">JIT</acronym> compilation using <a class="ulink" href="https://llvm.org/" target="_top"><span class="productname">LLVM</span></a> when
14 <span class="productname">PostgreSQL</span> is built with
15 <a class="link" href="install-make.html#CONFIGURE-WITH-LLVM"><code class="literal">--with-llvm</code></a>.
17 See <code class="filename">src/backend/jit/README</code> for further details.
18 </p><div class="sect2" id="JIT-ACCELERATED-OPERATIONS"><div class="titlepage"><div><div><h3 class="title">30.1.1. <acronym class="acronym">JIT</acronym> Accelerated Operations <a href="#JIT-ACCELERATED-OPERATIONS" class="id_link">#</a></h3></div></div></div><p>
19 Currently <span class="productname">PostgreSQL</span>'s <acronym class="acronym">JIT</acronym>
20 implementation has support for accelerating expression evaluation and
21 tuple deforming. Several other operations could be accelerated in the
24 Expression evaluation is used to evaluate <code class="literal">WHERE</code>
25 clauses, target lists, aggregates and projections. It can be accelerated
26 by generating code specific to each case.
28 Tuple deforming is the process of transforming an on-disk tuple (see <a class="xref" href="storage-page-layout.html#STORAGE-TUPLE-LAYOUT" title="66.6.1. Table Row Layout">Section 66.6.1</a>) into its in-memory representation.
29 It can be accelerated by creating a function specific to the table layout
30 and the number of columns to be extracted.
31 </p></div><div class="sect2" id="JIT-INLINING"><div class="titlepage"><div><div><h3 class="title">30.1.2. Inlining <a href="#JIT-INLINING" class="id_link">#</a></h3></div></div></div><p>
32 <span class="productname">PostgreSQL</span> is very extensible and allows new
33 data types, functions, operators and other database objects to be defined;
34 see <a class="xref" href="extend.html" title="Chapter 36. Extending SQL">Chapter 36</a>. In fact the built-in objects are implemented
35 using nearly the same mechanisms. This extensibility implies some
36 overhead, for example due to function calls (see <a class="xref" href="xfunc.html" title="36.3. User-Defined Functions">Section 36.3</a>).
37 To reduce that overhead, <acronym class="acronym">JIT</acronym> compilation can inline the
38 bodies of small functions into the expressions using them. That allows a
39 significant percentage of the overhead to be optimized away.
40 </p></div><div class="sect2" id="JIT-OPTIMIZATION"><div class="titlepage"><div><div><h3 class="title">30.1.3. Optimization <a href="#JIT-OPTIMIZATION" class="id_link">#</a></h3></div></div></div><p>
41 <span class="productname">LLVM</span> has support for optimizing generated
42 code. Some of the optimizations are cheap enough to be performed whenever
43 <acronym class="acronym">JIT</acronym> is used, while others are only beneficial for
44 longer-running queries.
45 See <a class="ulink" href="https://llvm.org/docs/Passes.html#transform-passes" target="_top">https://llvm.org/docs/Passes.html#transform-passes</a> for
46 more details about optimizations.
47 </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jit.html" title="Chapter 30. Just-in-Time Compilation (JIT)">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="jit.html" title="Chapter 30. Just-in-Time Compilation (JIT)">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="jit-decision.html" title="30.2. When to JIT?">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 30. Just-in-Time Compilation (<acronym class="acronym">JIT</acronym>) </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 30.2. When to <acronym class="acronym">JIT</acronym>?</td></tr></table></div></body></html>