{"Entry":{"collection":"guc","key":"jit_optimize_above_cost","name":"jit_optimize_above_cost","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Query Tuning / Planner Cost Constants","category_zh":"","changed_in":["14"],"changes":[{"documentation_changed":false,"fields":{},"from":"10","status":"added","to":"11"},{"documentation_changed":false,"fields":{"short_desc":{"from":"Optimize JITed functions if query is more expensive.","to":"Optimize JIT-compiled functions if query is more expensive."}},"from":"13","status":"changed","to":"14"}],"content_hash":"e5a385d456e10a17eeb1e7964aa0252d02b5875a93c93daf1f58c538048dc4f9","context":"","default_changed_in":[],"default_history":[{"from":"11","to":"19","value":"500000"}],"editorial":{"advice":{"olap":"For long CPU-bound queries, benchmark total elapsed time on both sides of jit_optimize_above_cost. Lowering the threshold is useful only when saved execution CPU consistently exceeds compilation overhead.","oltp":"Do not lower jit_optimize_above_cost globally to chase a single CPU-heavy statement. Compilation latency is visible in short-query tails; test at statement or role scope and include JIT generation time in the result.","small":"Keep the default or disable the stage with -1 when LLVM work competes with a small CPU budget. Estimated cost alone does not prove that JIT will pay back its startup cost."},"mechanism":["jit_optimize_above_cost compares the finished plan's estimated cost with a threshold to decide whether PostgreSQL may run expensive JIT optimization passes. The cost is the planner's arbitrary estimate, not milliseconds.","The decision occurs at plan time and only matters when JIT is enabled and a provider is available. Generic prepared plans retain the decision made when the generic plan was generated.","A value of -1 disables this stage. jit_inline_above_cost and jit_optimize_above_cost are additional gates after jit_above_cost, so setting either below the base compilation threshold is not meaningful. Its user context permits session- or transaction-local changes; newly performed or newly planned work sees the value."],"pitfalls":["Reading the threshold as milliseconds rather than arbitrary planner cost units.","Ignoring JIT generation, inlining, optimization, and emission time when benchmarking.","Expecting a changed value to alter a generic plan that was already generated.","Setting an advanced-stage threshold below jit_above_cost and expecting that stage to run by itself."],"references":[{"title":"PostgreSQL 19 Beta 4: jit_optimize_above_cost","url":"https://www.postgresql.org/docs/19/runtime-config-query.html#GUC-JIT-OPTIMIZE-ABOVE-COST"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["jit","jit_above_cost","jit_inline_above_cost","jit_expressions"],"summary":"jit_optimize_above_cost — Optimize JIT-compiled functions if query is more expensive. Observed in PG11–19 Beta 4; its last measured boot default is 500000 in PG19 Beta 4, with user context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA."},"enumvals":[],"first_version":"11","group":"Query Tuning","group_slug":"query","imported_at":"2026-09-27T17:57:31.43697+08:00","intro_commit":{"authored_at":"2018-03-22T11:45:07-07:00","discussion":["https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de"],"hash":"cc415a56d09a8da7c919088036b6097b70f10791","subject":"Basic planner and executor integration for JIT.","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=cc415a56d09a8da7c919088036b6097b70f10791"},"key":"jit_optimize_above_cost","last_version":"20","max_val":"","min_val":"","name":"jit_optimize_above_cost","position":196,"present_in":["11","12","13","14","15","16","17","18","19","20"],"short_desc":"Sets the query cost above which JIT compilation applies expensive optimizations.","short_desc_zh":"","source_rev":"english-manuals:f8ebb4ef7a9ef7db43a37fe172cc5bac958af7e66f02ab949a4fef5eb88ee424","unit":"","vartype":"real"}},"Definition":{"Collection":"guc","Key":"jit_optimize_above_cost","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"jit_optimize_above_cost","SourceRevision":"english-manuals:f8ebb4ef7a9ef7db43a37fe172cc5bac958af7e66f02ab949a4fef5eb88ee424","Facts":{"boot_val":"500000","category":"Query Tuning / Planner Cost Constants","context":"user","description":"Sets the query cost above which JIT compilation applies expensive optimizations. Such optimization adds planning time, but can improve execution speed. It is not meaningful to set this to less than jit_above_cost, and it is unlikely to be beneficial to set it to more than jit_inline_above_cost. Setting this to -1 disables expensive optimizations. The default is 500000.","doc":{"anchor":"GUC-JIT-OPTIMIZE-ABOVE-COST","file":"runtime-config-query.html","lang":"en","sha256":"33456ca7ef52bf28e93e34b932a411db7a1b95800179add2cf867dc6ec9144bc","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"-1 disables optimization.","lang":"en","max_val":"1.79769e+308","metadata_version":"18","min_val":"-1","name":"jit_optimize_above_cost","short_desc":"Optimize JIT-compiled functions if query is more expensive.","source":"pg-settings-source-snapshot","unit":null,"vartype":"real"},"ManualEvidence":{"doc":{"anchor":"GUC-JIT-OPTIMIZE-ABOVE-COST","file":"runtime-config-query.html","lang":"en","sha256":"33456ca7ef52bf28e93e34b932a411db7a1b95800179add2cf867dc6ec9144bc","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"jit_optimize_above_cost","SourceDatabase":"center","Version":"18","Locale":"en","Title":"jit_optimize_above_cost","Summary":"Sets the query cost above which JIT compilation applies expensive optimizations. Such optimization adds planning time, but can improve execution speed. It is not meaningful to set this to less than jit_above_cost, and it is unlikely to be beneficial to set it to more than jit_inline_above_cost. Setting this to -1 disables expensive optimizations. The default is 500000.","BodyHTML":"\u003cp\u003eSets the query cost above which JIT compilation applies expensive optimizations. Such optimization adds planning time, but can improve execution speed. It is not meaningful to set this to less than jit_above_cost, and it is unlikely to be beneficial to set it to more than jit_inline_above_cost. Setting this to -1 disables expensive optimizations. The default is 500000.\u003c/p\u003e","SourceRevision":"english-manuals:f8ebb4ef7a9ef7db43a37fe172cc5bac958af7e66f02ab949a4fef5eb88ee424","ContentHash":"a9304d83d5380c4fe4b887de17e401b5b43d1bd08dcc1677333b45504345e0a3","Payload":{"description":"Sets the query cost above which JIT compilation applies expensive optimizations. Such optimization adds planning time, but can improve execution speed. It is not meaningful to set this to less than jit_above_cost, and it is unlikely to be beneficial to set it to more than jit_inline_above_cost. Setting this to -1 disables expensive optimizations. The default is 500000."}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
