codekingpro/portable-devtools
115k
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>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 id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">32.2. When to <acronym 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 class="acronym">JIT</acronym>)</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 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 /></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>? <a href="#JIT-DECISION" class="id_link">#</a></h2></div></div></div><p>3 <acronym class="acronym">JIT</acronym> compilation is beneficial primarily for long-running4 CPU-bound queries. Frequently these will be analytical queries. For short5 queries the added overhead of performing <acronym class="acronym">JIT</acronym> compilation6 will often be higher than the time it can save.7 </p><p>8 To determine whether <acronym class="acronym">JIT</acronym> compilation should be used,9 the total estimated cost of a query (see10 <a class="xref" href="planner-stats-details.html" title="Chapter 76. How the Planner Uses Statistics">Chapter 76</a> and11 <a class="xref" href="runtime-config-query.html#RUNTIME-CONFIG-QUERY-CONSTANTS" title="20.7.2. Planner Cost Constants">Section 20.7.2</a>) is used.12 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,13 <acronym class="acronym">JIT</acronym> compilation will be performed.14 Two further decisions are then needed.15 Firstly, if the estimated cost is more16 than the setting of <a class="xref" href="runtime-config-query.html#GUC-JIT-INLINE-ABOVE-COST">jit_inline_above_cost</a>, short17 functions and operators used in the query will be inlined.18 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 are19 applied to improve the generated code.20 Each of these options increases the <acronym class="acronym">JIT</acronym> compilation21 overhead, but can reduce query execution time considerably.22 </p><p>23 These cost-based decisions will be made at plan time, not execution24 time. This means that when prepared statements are in use, and a generic25 plan is used (see <a class="xref" href="sql-prepare.html" title="PREPARE"><span class="refentrytitle">PREPARE</span></a>), the values of the26 configuration parameters in effect at prepare time control the decisions,27 not the settings at execution time.28 </p><div class="note"><h3 class="title">Note</h3><p>29 If <a class="xref" href="runtime-config-query.html#GUC-JIT">jit</a> is set to <code class="literal">off</code>, or if no30 <acronym class="acronym">JIT</acronym> implementation is available (for example because31 the server was compiled without <code class="literal">--with-llvm</code>),32 <acronym class="acronym">JIT</acronym> will not be performed, even if it would be33 beneficial based on the above criteria. Setting <a class="xref" href="runtime-config-query.html#GUC-JIT">jit</a>34 to <code class="literal">off</code> has effects at both plan and execution time.35 </p></div><p>36 <a class="xref" href="sql-explain.html" title="EXPLAIN"><span class="refentrytitle">EXPLAIN</span></a> can be used to see whether37 <acronym class="acronym">JIT</acronym> is used or not. As an example, here is a query that38 is not using <acronym class="acronym">JIT</acronym>:39</p><pre class="screen">40=# EXPLAIN ANALYZE SELECT SUM(relpages) FROM pg_class;41 QUERY PLAN42-------------------------------------------------------------------------------------------------------------43 Aggregate (cost=16.27..16.29 rows=1 width=8) (actual time=0.303..0.303 rows=1 loops=1)44 -> Seq Scan on pg_class (cost=0.00..15.42 rows=342 width=4) (actual time=0.017..0.111 rows=356 loops=1)45 Planning Time: 0.116 ms46 Execution Time: 0.365 ms47(4 rows)48</pre><p>49 Given the cost of the plan, it is entirely reasonable that no50 <acronym class="acronym">JIT</acronym> was used; the cost of <acronym class="acronym">JIT</acronym> would51 have been bigger than the potential savings. Adjusting the cost limits52 will lead to <acronym class="acronym">JIT</acronym> use:53</p><pre class="screen">54=# SET jit_above_cost = 10;55SET56=# EXPLAIN ANALYZE SELECT SUM(relpages) FROM pg_class;57 QUERY PLAN58-------------------------------------------------------------------------------------------------------------59 Aggregate (cost=16.27..16.29 rows=1 width=8) (actual time=6.049..6.049 rows=1 loops=1)60 -> Seq Scan on pg_class (cost=0.00..15.42 rows=342 width=4) (actual time=0.019..0.052 rows=356 loops=1)61 Planning Time: 0.133 ms62 JIT:63 Functions: 364 Options: Inlining false, Optimization false, Expressions true, Deforming true65 Timing: Generation 1.259 ms, Inlining 0.000 ms, Optimization 0.797 ms, Emission 5.048 ms, Total 7.104 ms66 Execution Time: 7.416 ms67</pre><p>68 As visible here, <acronym class="acronym">JIT</acronym> was used, but inlining and69 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,70 that would change.71 </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" title="32.1. What Is JIT compilation?">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-configuration.html" title="32.3. Configuration">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" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 32.3. Configuration</td></tr></table></div></body></html>