gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

71 行
7.3KB

  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>31.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 V1.79.1" /><link rel="prev" href="jit-reason.html" title="31.1. What Is JIT compilation?" /><link rel="next" href="jit-configuration.html" title="31.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">31.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="31.1. What Is JIT compilation?">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="jit.html" title="Chapter 31. Just-in-Time Compilation (JIT)">Up</a></td><th width="60%" align="center">Chapter 31. 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 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="jit-configuration.html" title="31.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">31.2. When to <acronym class="acronym">JIT</acronym>?</h2></div></div></div><p>
  3. <acronym class="acronym">JIT</acronym> compilation is beneficial primarily for long-running
  4. CPU-bound queries. Frequently these will be analytical queries. For short
  5. queries the added overhead of performing <acronym class="acronym">JIT</acronym> compilation
  6. 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 (see
  10. <a class="xref" href="planner-stats-details.html" title="Chapter 70. How the Planner Uses Statistics">Chapter 70</a> and
  11. <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.
  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 more
  16. than the setting of <a class="xref" href="runtime-config-query.html#GUC-JIT-INLINE-ABOVE-COST">jit_inline_above_cost</a>, short
  17. 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 are
  19. applied to improve the generated code.
  20. Each of these options increases the <acronym class="acronym">JIT</acronym> compilation
  21. overhead, but can reduce query execution time considerably.
  22. </p><p>
  23. These cost-based decisions will be made at plan time, not execution
  24. time. This means that when prepared statements are in use, and a generic
  25. plan is used (see <a class="xref" href="sql-prepare.html" title="PREPARE"><span class="refentrytitle">PREPARE</span></a>), the values of the
  26. 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 no
  30. <acronym class="acronym">JIT</acronym> implementation is available (for example because
  31. 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 be
  33. 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 whether
  37. <acronym class="acronym">JIT</acronym> is used or not. As an example, here is a query that
  38. is not using <acronym class="acronym">JIT</acronym>:
  39. </p><pre class="screen">
  40. =# EXPLAIN ANALYZE SELECT SUM(relpages) FROM pg_class;
  41. QUERY PLAN
  42. -------------------------------------------------------------------------------------------------------------
  43. Aggregate (cost=16.27..16.29 rows=1 width=8) (actual time=0.303..0.303 rows=1 loops=1)
  44. -&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)
  45. Planning Time: 0.116 ms
  46. Execution Time: 0.365 ms
  47. (4 rows)
  48. </pre><p>
  49. Given the cost of the plan, it is entirely reasonable that no
  50. <acronym class="acronym">JIT</acronym> was used; the cost of <acronym class="acronym">JIT</acronym> would
  51. have been bigger than the potential savings. Adjusting the cost limits
  52. will lead to <acronym class="acronym">JIT</acronym> use:
  53. </p><pre class="screen">
  54. =# SET jit_above_cost = 10;
  55. SET
  56. =# EXPLAIN ANALYZE SELECT SUM(relpages) FROM pg_class;
  57. QUERY PLAN
  58. -------------------------------------------------------------------------------------------------------------
  59. Aggregate (cost=16.27..16.29 rows=1 width=8) (actual time=6.049..6.049 rows=1 loops=1)
  60. -&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)
  61. Planning Time: 0.133 ms
  62. JIT:
  63. Functions: 3
  64. Options: Inlining false, Optimization false, Expressions true, Deforming true
  65. Timing: Generation 1.259 ms, Inlining 0.000 ms, Optimization 0.797 ms, Emission 5.048 ms, Total 7.104 ms
  66. Execution Time: 7.416 ms
  67. </pre><p>
  68. As visible here, <acronym class="acronym">JIT</acronym> was used, but inlining and
  69. 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">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">31.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"> 31.3. Configuration</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1