> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/server-administration/jit/jit-reason.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 30.1. 什麼是 JIT 編譯？ \#

### 30.1. 什麼是 JIT 編譯？ [#](#jit-reason) <a href="#jit-reason" id="jit-reason"></a>

[30.1.1. JIT 可加速的操作](#jit-accelerated-operations)

[30.1.2. 內嵌（Inlining）](#jit-inlining)

[30.1.3. 最佳化](#jit-optimization)

即時編譯（Just-in-Time，JIT）是一種在執行期將某種形式的 直譯式程式求值，轉換為原生程式的過程，並且是在執行期進行的。 舉例來說，與其使用可以求值任意 SQL 運算式的通用程式碼，來求值像 `WHERE a.col = 3` 這樣的特定 SQL 判斷式，不如產生一個 專門針對該運算式的函式，讓 CPU 能夠原生執行，藉此提升速度。

當 PostgreSQL 是以 [`--with-llvm`](https://docs.postgresql.tw/19/server-administration/installation/install-make.md#CONFIGURE-WITH-LLVM) 建置時，PostgreSQL 內建支援使用 [LLVM](https://llvm.org/) 進行 JIT 編譯。

詳情請見 `src/backend/jit/README`。

#### 30.1.1. JIT 可加速的操作 [#](#jit-accelerated-operations) <a href="#jit-accelerated-operations" id="jit-accelerated-operations"></a>

目前 PostgreSQL 的 JIT 實作支援加速運算式求值與 tuple 解構。未來可能還會加速其他幾種操作。

運算式求值用於求值 `WHERE` 子句、目標清單、聚合與投影。透過針對每種情況產生 專屬程式碼，可以加速這個過程。

tuple 解構是將磁碟上的 tuple（見[第 66.6.1 節](https://docs.postgresql.tw/19/internals/storage/storage-page-layout/storage-tuple-layout.md#storage-tuple-layout)）轉換為其記憶體內表示形式的過程。 可以透過建立一個專屬於資料表結構 與要擷取欄位數量的函式，來加速這個過程。

#### 30.1.2. 內嵌（Inlining） [#](#jit-inlining) <a href="#jit-inlining" id="jit-inlining"></a>

PostgreSQL 具有高度可擴充性，允許定義新的 資料型別、函式、運算子與其他資料庫物件；見[第 36 章](https://docs.postgresql.tw/19/server-programming/extend.md)。事實上，內建物件也是以幾乎 相同的機制實作的。這種可擴充性隱含了一些額外負擔，例如函式呼叫所帶來的負擔（見[第 36.3 節](https://docs.postgresql.tw/19/server-programming/extend/xfunc.md)）。 為了降低這種額外負擔，JIT 編譯可以將小型函式的 內容內嵌到使用它們的運算式中。這樣一來，就能將 相當大比例的額外負擔最佳化掉。

#### 30.1.3. 最佳化 [#](#jit-optimization) <a href="#jit-optimization" id="jit-optimization"></a>

LLVM 支援對產生的 程式碼進行最佳化。部分最佳化的成本很低，只要使用 JIT 就會執行；而其他最佳化則只有在執行時間較長的查詢中 才有幫助。 更多有關最佳化的細節，請見 <https://llvm.org/docs/Passes.html#transform-passes>。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/jit-reason.html)（原文版本：18.6；核對日期：2026-09-25）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/server-administration/jit/jit-reason.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
