Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 9b6cc37ce608401d44f6535a0c7cb777 > files > 460

postgresql11-docs-11.5-1.mga7.noarch.rpm

<?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.2. When to JIT?</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-reason.html" title="32.1. What is JIT compilation?" /><link rel="next" href="jit-configuration.html" title="32.3. Configuration" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">32.2. When to <acronym xmlns="http://www.w3.org/1999/xhtml" class="acronym">JIT</acronym>?</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="jit-reason.html" title="32.1. What is JIT compilation?">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 xmlns="http://www.w3.org/1999/xhtml" class="acronym">JIT</acronym>)</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 11.5 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="jit-configuration.html" title="32.3. Configuration">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="JIT-DECISION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">32.2. When to <acronym class="acronym">JIT</acronym>?</h2></div></div></div><p>
   <acronym class="acronym">JIT</acronym> compilation is beneficial primarily for long-running
   CPU-bound queries. Frequently these will be analytical queries.  For short
   queries the added overhead of performing <acronym class="acronym">JIT</acronym> compilation
   will often be higher than the time it can save.
  </p><p>
   To determine whether <acronym class="acronym">JIT</acronym> compilation should be used,
   the total estimated cost of a query (see
   <a class="xref" href="planner-stats-details.html" title="Chapter 70. How the Planner Uses Statistics">Chapter 70</a> and
   <a class="xref" href="runtime-config-query.html#RUNTIME-CONFIG-QUERY-CONSTANTS" title="19.7.2. Planner Cost Constants">Section 19.7.2</a>) is used.
   The estimated cost of the query will be compared with the setting of <a class="xref" href="runtime-config-query.html#GUC-JIT-ABOVE-COST">jit_above_cost</a>. If the cost is higher,
   <acronym class="acronym">JIT</acronym> compilation will be performed.
   Two further decisions are then needed.
   Firstly, if the estimated cost is more
   than the setting of <a class="xref" href="runtime-config-query.html#GUC-JIT-INLINE-ABOVE-COST">jit_inline_above_cost</a>, short
   functions and operators used in the query will be inlined.
   Secondly, if the estimated cost is more than the setting of <a class="xref" href="runtime-config-query.html#GUC-JIT-OPTIMIZE-ABOVE-COST">jit_optimize_above_cost</a>, expensive optimizations are
   applied to improve the generated code.
   Each of these options increases the <acronym class="acronym">JIT</acronym> compilation
   overhead, but can reduce query execution time considerably.
  </p><p>
   These cost-based decisions will be made at plan time, not execution
   time. This means that when prepared statements are in use, and a generic
   plan is used (see <a class="xref" href="sql-prepare.html" title="PREPARE"><span class="refentrytitle">PREPARE</span></a>), the values of the
   configuration parameters in effect at prepare time control the decisions,
   not the settings at execution time.
  </p><div class="note"><h3 class="title">Note</h3><p>
    If <a class="xref" href="runtime-config-query.html#GUC-JIT">jit</a> is set to <code class="literal">off</code>, or if no
    <acronym class="acronym">JIT</acronym> implementation is available (for example because
    the server was compiled without <code class="literal">--with-llvm</code>),
    <acronym class="acronym">JIT</acronym> will not be performed, even if it would be
    beneficial based on the above criteria.  Setting <a class="xref" href="runtime-config-query.html#GUC-JIT">jit</a>
    to <code class="literal">off</code> has effects at both plan and execution time.
   </p></div><p>
   <a class="xref" href="sql-explain.html" title="EXPLAIN"><span class="refentrytitle">EXPLAIN</span></a> can be used to see whether
   <acronym class="acronym">JIT</acronym> is used or not.  As an example, here is a query that
   is not using <acronym class="acronym">JIT</acronym>:
</p><pre class="screen">
=# EXPLAIN ANALYZE SELECT SUM(relpages) FROM pg_class;
                                                 QUERY PLAN
-------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=16.27..16.29 rows=1 width=8) (actual time=0.303..0.303 rows=1 loops=1)
   -&gt;  Seq Scan on pg_class  (cost=0.00..15.42 rows=342 width=4) (actual time=0.017..0.111 rows=356 loops=1)
 Planning Time: 0.116 ms
 Execution Time: 0.365 ms
(4 rows)
</pre><p>
   Given the cost of the plan, it is entirely reasonable that no
   <acronym class="acronym">JIT</acronym> was used; the cost of <acronym class="acronym">JIT</acronym> would
   have been bigger than the potential savings. Adjusting the cost limits
   will lead to <acronym class="acronym">JIT</acronym> use:
</p><pre class="screen">
=# SET jit_above_cost = 10;
SET
=# EXPLAIN ANALYZE SELECT SUM(relpages) FROM pg_class;
                                                 QUERY PLAN
-------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=16.27..16.29 rows=1 width=8) (actual time=6.049..6.049 rows=1 loops=1)
   -&gt;  Seq Scan on pg_class  (cost=0.00..15.42 rows=342 width=4) (actual time=0.019..0.052 rows=356 loops=1)
 Planning Time: 0.133 ms
 JIT:
   Functions: 3
   Options: Inlining false, Optimization false, Expressions true, Deforming true
   Timing: Generation 1.259 ms, Inlining 0.000 ms, Optimization 0.797 ms, Emission 5.048 ms, Total 7.104 ms
 Execution Time: 7.416 ms
</pre><p>
   As visible here, <acronym class="acronym">JIT</acronym> was used, but inlining and
   expensive optimization were not. If <a class="xref" href="runtime-config-query.html#GUC-JIT-INLINE-ABOVE-COST">jit_inline_above_cost</a> or <a class="xref" href="runtime-config-query.html#GUC-JIT-OPTIMIZE-ABOVE-COST">jit_optimize_above_cost</a> were also lowered,
   that would change.
  </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jit-reason.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="jit.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="jit-configuration.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">32.1. What is <acronym class="acronym">JIT</acronym> compilation? </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 32.3. Configuration</td></tr></table></div></body></html>