> 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/internals/custom-scan.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 第 60 章 撰寫自訂掃描提供者

### 第 60 章 撰寫自訂掃描提供者

**目錄**

* [60.1. 建立自訂掃描路徑](https://docs.postgresql.tw/19/internals/custom-scan/custom-scan-path.md)
  * [60.1.1. 自訂掃描路徑回呼函式](https://docs.postgresql.tw/19/internals/custom-scan/custom-scan-path.md#custom-scan-path-callbacks)
* [60.2. 建立自訂掃描計畫](https://docs.postgresql.tw/19/internals/custom-scan/custom-scan-plan.md)
  * [60.2.1. 自訂掃描計畫回呼函式](https://docs.postgresql.tw/19/internals/custom-scan/custom-scan-plan.md#custom-scan-plan-callbacks)
* [60.3. 執行自訂掃描](https://docs.postgresql.tw/19/internals/custom-scan/custom-scan-execution.md)
  * [60.3.1. 自訂掃描執行回呼函式](https://docs.postgresql.tw/19/internals/custom-scan/custom-scan-execution.md#custom-scan-execution-callbacks)

PostgreSQL 支援一組實驗性的功能，目的是讓擴充模組能夠在系統中加入新的掃描類型。[外部資料包裝器](https://docs.postgresql.tw/19/internals/fdwhandler.md)只負責知道如何掃描它自己的外部資料表；與之不同，自訂掃描提供者可以提供另一種方法來掃描系統中的任何關聯。撰寫自訂掃描提供者的動機，通常是為了使用核心系統不支援的某些最佳化，例如快取或某種形式的硬體加速。本章概述如何撰寫新的自訂掃描提供者。

實作新類型的自訂掃描分為三個步驟。首先，在規劃期間，必須產生代表以所提議策略進行掃描的存取路徑。其次，如果規劃器選中其中一條存取路徑，作為掃描特定關聯的最佳策略，就必須將該存取路徑轉換為計畫。最後，必須能夠執行該計畫，並產生與以同一關聯為目標的任何其他存取路徑所會產生的相同結果。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/custom-scan.html)（原文版本：18.6；核對日期：2026-10-17）


---

# 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/internals/custom-scan.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.
