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

# 36.16.2. 索引方法策略

## 36.16.2. 索引方法策略 [#](#xindex-strategies) <a href="#xindex-strategies" id="xindex-strategies"></a>

與運算子類別相關聯的運算子，是以「策略編號」（strategy number） 來識別的，這些編號用來在其運算子類別的情境中識別 每個運算子的語意。 舉例來說，B-tree 對鍵值強制施加嚴格的排序，由小到大， 因此諸如「小於」與「大於等於」 這類的運算子，對 B-tree 而言相當重要。 由於 PostgreSQL 允許使用者自行定義運算子， PostgreSQL 無法單憑運算子的名稱 （例如 `<` 或 `>=`）來判斷它是哪一種 比較方式。因此，索引方法定義了一組 「策略」，可以將其視為廣義化的運算子。 每個運算子類別會針對特定的資料型別與索引語意的解讀方式， 指定哪一個實際的運算子對應到哪一種策略。

B-tree 索引方法定義了五種策略，如[表 36.3](#xindex-btree-strat-table)所示。

### 表 36.3. B-Tree 策略 [#](#xindex-btree-strat-table) <a href="#xindex-btree-strat-table" id="xindex-btree-strat-table"></a>

| 操作   | 策略編號 |
| ---- | ---- |
| 小於   | 1    |
| 小於等於 | 2    |
| 等於   | 3    |
| 大於等於 | 4    |
| 大於   | 5    |

<br>

雜湊索引只支援相等比較，因此它們只使用一種 策略，如[表 36.4](#xindex-hash-strat-table)所示。

### 表 36.4. 雜湊策略 [#](#xindex-hash-strat-table) <a href="#xindex-hash-strat-table" id="xindex-hash-strat-table"></a>

| 操作 | 策略編號 |
| -- | ---- |
| 等於 | 1    |

<br>

GiST 索引更具彈性：它們根本沒有固定的一組 策略。取而代之，每個特定 GiST 運算子類別的「一致性」（consistency）支援常式， 會以自己的方式解讀策略編號。舉例來說，內建 GiST 索引 運算子類別中有幾個是用來對二維幾何物件建立索引，提供了 [表 36.5](#xindex-rtree-strat-table)所示的「R-tree」策略。其中四種是真正的 二維測試（重疊、相同、包含、被包含）； 另外四種只考慮 X 方向；其餘四種 則是在 Y 方向提供相同的測試。

### 表 36.5. GiST 二維「R-tree」策略 [#](#xindex-rtree-strat-table) <a href="#xindex-rtree-strat-table" id="xindex-rtree-strat-table"></a>

| 操作     | 策略編號 |
| ------ | ---- |
| 嚴格在左側  | 1    |
| 不延伸至右側 | 2    |
| 重疊     | 3    |
| 不延伸至左側 | 4    |
| 嚴格在右側  | 5    |
| 相同     | 6    |
| 包含     | 7    |
| 被包含    | 8    |
| 不延伸至上方 | 9    |
| 嚴格在下方  | 10   |
| 嚴格在上方  | 11   |
| 不延伸至下方 | 12   |

<br>

SP-GiST 索引在彈性方面與 GiST 索引類似：它們同樣沒有 固定的一組策略。取而代之，每個運算子 類別的支援常式會依照該運算子類別的定義來解讀策略編號。舉例來說， 內建點（point）運算子類別所使用的策略編號如 [表 36.6](#xindex-spgist-point-strat-table)所示。

### 表 36.6. SP-GiST 點策略 [#](#xindex-spgist-point-strat-table) <a href="#xindex-spgist-point-strat-table" id="xindex-spgist-point-strat-table"></a>

| 操作    | 策略編號 |
| ----- | ---- |
| 嚴格在左側 | 1    |
| 嚴格在右側 | 5    |
| 相同    | 6    |
| 被包含   | 8    |
| 嚴格在下方 | 10   |
| 嚴格在上方 | 11   |

<br>

GIN 索引與 GiST、SP-GiST 索引類似，同樣沒有 固定的一組策略。取而代之，每個運算子類別的支援常式 會依照該運算子類別的定義來解讀策略編號。舉例來說， 內建陣列運算子類別所使用的策略編號如 [表 36.7](#xindex-gin-array-strat-table)所示。

### 表 36.7. GIN 陣列策略 [#](#xindex-gin-array-strat-table) <a href="#xindex-gin-array-strat-table" id="xindex-gin-array-strat-table"></a>

| 操作  | 策略編號 |
| --- | ---- |
| 重疊  | 1    |
| 包含  | 2    |
| 被包含 | 3    |
| 等於  | 4    |

<br>

BRIN 索引與 GiST、SP-GiST 及 GIN 索引類似，同樣沒有 固定的一組策略。取而代之，每個運算子類別的支援常式 會依照該運算子類別的定義來解讀策略編號。舉例來說， 內建 `Minmax` 運算子類別所使用的策略編號如 [表 36.8](#xindex-brin-minmax-strat-table)所示。

### 表 36.8. BRIN Minmax 策略 [#](#xindex-brin-minmax-strat-table) <a href="#xindex-brin-minmax-strat-table" id="xindex-brin-minmax-strat-table"></a>

| 操作   | 策略編號 |
| ---- | ---- |
| 小於   | 1    |
| 小於等於 | 2    |
| 等於   | 3    |
| 大於等於 | 4    |
| 大於   | 5    |

<br>

請注意，以上所列出的所有運算子都會傳回布林值。實際上， 所有被定義為索引方法搜尋運算子的運算子都必須 傳回 `boolean` 型別，因為它們必須出現在 `WHERE` 子句的最上層，才能搭配索引使用。 （有些索引存取方法也支援*排序運算子*， 這類運算子通常不會傳回布林值；此功能會在 [第 36.16.7 節](https://docs.postgresql.tw/19/server-programming/extend/xindex.md#xindex-ordering-ops)討論。）

[返回 36.16. 將擴充功能與索引介接](https://docs.postgresql.tw/19/server-programming/extend/xindex.md#xindex)

***

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


---

# 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-programming/extend/xindex/xindex-strategies.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.
