32.2. When to JIT?
Was this helpful?
Was this helpful?
JIT compilation is beneficial primarily for long-running CPU-bound queries. Frequently these will be analytical queries. For short queries the added overhead of performing JIT compilation will often be higher than the time it can save.
To determine whether JIT compilation should be used, the total estimated cost of a query (see and ) is used. The estimated cost of the query will be compared with the setting of . If the cost is higher, JIT compilation will be performed. Two further decisions are then needed. Firstly, if the estimated cost is more than the setting of , short functions and operators used in the query will be inlined. Secondly, if the estimated cost is more than the setting of , expensive optimizations are applied to improve the generated code. Each of these options increases the JIT compilation overhead, but can reduce query execution time considerably.
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 ), the values of the configuration parameters in effect at prepare time control the decisions, not the settings at execution time.
If is set to off
, or if no JIT implementation is available (for example because the server was compiled without --with-llvm
), JIT will not be performed, even if it would be beneficial based on the above criteria. Setting to off
has effects at both plan and execution time.
can be used to see whether JIT is used or not. As an example, here is a query that is not using JIT:
Given the cost of the plan, it is entirely reasonable that no JIT was used; the cost of JIT would have been bigger than the potential savings. Adjusting the cost limits will lead to JIT use:
As visible here, JIT was used, but inlining and expensive optimization were not. If or were also lowered, that would change.