blob: 944aa8d840cb0b5929873492f90aaa22f1b53328 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!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>32.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 32. Just-in-Time Compilation (JIT)" /><link rel="next" href="jit-decision.html" title="32.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">32.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 32. Just-in-Time Compilation (JIT)">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="jit.html" title="Chapter 32. Just-in-Time Compilation (JIT)">Up</a></td><th width="60%" align="center">Chapter 32. Just-in-Time Compilation (<acronym class="acronym">JIT</acronym>)</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.2 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="jit-decision.html" title="32.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">32.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">32.1.1. <acronym class="acronym">JIT</acronym> Accelerated Operations</a></span></dt><dt><span class="sect2"><a href="jit-reason.html#JIT-INLINING">32.1.2. Inlining</a></span></dt><dt><span class="sect2"><a href="jit-reason.html#JIT-OPTIMIZATION">32.1.3. Optimization</a></span></dt></dl></div><p>
Just-in-Time (<acronym class="acronym">JIT</acronym>) compilation 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 general-purpose code that can evaluate
arbitrary SQL expressions to evaluate a particular SQL predicate
like <code class="literal">WHERE a.col = 3</code>, it is possible to generate a
function that is specific to that expression and can be natively executed
by the CPU, yielding a speedup.
</p><p>
<span class="productname">PostgreSQL</span> has builtin support to perform
<acronym class="acronym">JIT</acronym> compilation using <a class="ulink" href="https://llvm.org/" target="_top"><span class="productname">LLVM</span></a> when
<span class="productname">PostgreSQL</span> is built with
<a class="link" href="install-make.html#CONFIGURE-WITH-LLVM"><code class="literal">--with-llvm</code></a>.
</p><p>
See <code class="filename">src/backend/jit/README</code> for further details.
</p><div class="sect2" id="JIT-ACCELERATED-OPERATIONS"><div class="titlepage"><div><div><h3 class="title">32.1.1. <acronym class="acronym">JIT</acronym> Accelerated Operations <a href="#JIT-ACCELERATED-OPERATIONS" class="id_link">#</a></h3></div></div></div><p>
Currently <span class="productname">PostgreSQL</span>'s <acronym class="acronym">JIT</acronym>
implementation has support for accelerating expression evaluation and
tuple deforming. Several other operations could be accelerated in the
future.
</p><p>
Expression evaluation is used to evaluate <code class="literal">WHERE</code>
clauses, target lists, aggregates and projections. It can be accelerated
by generating code specific to each case.
</p><p>
Tuple deforming is the process of transforming an on-disk tuple (see <a class="xref" href="storage-page-layout.html#STORAGE-TUPLE-LAYOUT" title="73.6.1. Table Row Layout">Section 73.6.1</a>) 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.
</p></div><div class="sect2" id="JIT-INLINING"><div class="titlepage"><div><div><h3 class="title">32.1.2. Inlining <a href="#JIT-INLINING" class="id_link">#</a></h3></div></div></div><p>
<span class="productname">PostgreSQL</span> is very extensible and allows new
data types, functions, operators and other database objects to be defined;
see <a class="xref" href="extend.html" title="Chapter 38. Extending SQL">Chapter 38</a>. In fact the built-in objects are implemented
using nearly the same mechanisms. This extensibility implies some
overhead, for example due to function calls (see <a class="xref" href="xfunc.html" title="38.3. User-Defined Functions">Section 38.3</a>).
To reduce that overhead, <acronym class="acronym">JIT</acronym> compilation can inline the
bodies of small functions into the expressions using them. That allows a
significant percentage of the overhead to be optimized away.
</p></div><div class="sect2" id="JIT-OPTIMIZATION"><div class="titlepage"><div><div><h3 class="title">32.1.3. Optimization <a href="#JIT-OPTIMIZATION" class="id_link">#</a></h3></div></div></div><p>
<span class="productname">LLVM</span> has support for optimizing generated
code. Some of the optimizations are cheap enough to be performed whenever
<acronym class="acronym">JIT</acronym> is used, while others are only beneficial for
longer-running queries.
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
more details about optimizations.
</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 32. Just-in-Time Compilation (JIT)">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="jit.html" title="Chapter 32. Just-in-Time Compilation (JIT)">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="jit-decision.html" title="32.2. When to JIT?">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 32. Just-in-Time Compilation (<acronym class="acronym">JIT</acronym>) </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.2 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 32.2. When to <acronym class="acronym">JIT</acronym>?</td></tr></table></div></body></html>
|