↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / Index AM / GIN

GIN

元素检索

GIN 索引是 “ 倒排索引 ” ,适用于包含多个组成值的数据值,例如数组。倒排索引会为每个组成值保存单独的项,因此能够高效处理测试特定组成值是否存在的查询。

当前查看 PostgreSQL 18.6。

能力 · PostgreSQL 18.6

能力结论来自对应版本的文档。有条件支持取决于操作符类、索引类型或查询,不能视为普遍保证。

能力支持状态条件与证据
有序输出不支持

普通的有序输出与按运算符排序是不同能力,例如按近邻距离排序。

同版本英文证据

In addition to simply finding the rows to be returned by a query, an index may be able to deliver them in a specific sorted order. This allows a query's ORDER BY specification to be honored without a separate sorting step. Of the index types currently supported by PostgreSQL , only B-tree can produce sorted output — the other index types return matching rows in an unspecified, implementation-dependent order.

PostgreSQL 18.6 · indexes-ordering

唯一键不支持

这里指唯一索引,排除约束采用不同的约定。

同版本英文证据

Currently, only B-tree indexes can be declared unique.

PostgreSQL 18.6 · indexes-unique

多键列支持

多个检索键与不参与检索的 INCLUDE 附加列是不同概念。

同版本英文证据

Currently, only the B-tree, GiST, GIN, and BRIN index types support multiple-key-column indexes. Whether there can be multiple key columns is independent of whether INCLUDE columns can be added to the index. Indexes can have up to 32 columns, including INCLUDE columns. (This limit can be altered when building PostgreSQL ; see the file pg_config_manual.h .)

PostgreSQL 18.6 · indexes-multicolumn

INCLUDE 附加列不支持

附加列不会成为检索键。过宽的附加数据可能超过索引元组大小限制。

同版本英文证据

Currently, the B-tree, GiST and SP-GiST index access methods support this feature. In these indexes, the values of columns listed in the INCLUDE clause are included in leaf tuples which correspond to heap tuples, but are not included in upper-level index entries used for tree navigation.

PostgreSQL 18.6 · sql-createindex

仅索引扫描不支持

查询必须使用索引覆盖的值;能否避免访问堆取决于可见性映射状态。

同版本英文证据

The index type must support index-only scans. B-tree indexes always do. GiST and SP-GiST indexes support index-only scans for some operator classes but not others. Other index types have no support. The underlying requirement is that the index must physically store, or else be able to reconstruct, the original data value for each index entry. As a counterexample, GIN indexes cannot support index-only scans because each index entry typically holds only part of the original data value.

PostgreSQL 18.6 · indexes-index-only-scans

按距离排序未确定

可用性取决于所选操作符类和排序运算符。

现有来源不足以确定此项能力,不能据此判断为“不支持”。

并行索引扫描不支持

多个进程协作扫描同一索引,不同于并行位图堆扫描,也不同于 Parallel Append 下各自独立的串行扫描。

同版本英文证据

In a parallel index scan or parallel index-only scan , the cooperating processes take turns reading data from the index. Currently, parallel index scans are supported only for btree indexes. Each process will claim a single index block and will scan and return all tuples referenced by that block; other processes can at the same time be returning tuples from a different index block. The results of a parallel btree scan are returned in sorted order within each worker process.

PostgreSQL 18.6 · parallel-plans

并行构建索引支持

并行构建与并行扫描分别记录,还取决于工作进程是否可用、配置和构建阶段。

同版本英文证据

PostgreSQL can build indexes while leveraging multiple CPUs in order to process the table rows faster. This feature is known as parallel index build . For index methods that support building indexes in parallel (currently, B-tree, GIN, and BRIN), maintenance_work_mem specifies the maximum amount of memory that can be used by each index build operation as a whole, regardless of how many worker processes were started. Generally, a cost model automatically determines how many worker processes should be requested, if any.

PostgreSQL 18.6 · sql-createindex

查询、运算符与限制

CREATE INDEX name ON table_name USING gin (column_name);

这是语法模板;使用时请替换表、列占位符,并选择兼容的操作符类。

GIN 索引是 “ 倒排索引 ” ,适用于包含多个组成值的数据值,例如数组。倒排索引会为每个组成值保存单独的项,因此能够高效处理测试特定组成值是否存在的查询。

与 GiST 和 SP-GiST 一样,GIN 也能支持多种不同的用户定义索引策略,GIN 索引可使用哪些具体操作符同样取决于索引策略。例如, PostgreSQL 标准发布版中包含一个用于数组的 GIN 操作符类,它支持使用下列操作符的索引化查询:

<@   @>   =   &&

(这些操作符的含义见 第 9.19 节 。)标准发布版自带的 GIN 操作符类记录在 表 65.3 中。还有许多其他 GIN 操作符类可在 contrib 集合或独立项目中获得。更多信息见 第 65.4 节 。

存储参数

通过 CREATE INDEX … WITH 或 ALTER INDEX … SET 设置索引参数。默认值和实际行为取决于访问方法及所选 PostgreSQL 版本。

fastupdate

控制 第 65.4.4.1 节 中描述的快速更新技术的使用。 ON 启用快速更新, OFF 禁用快速更新。默认值为 ON 。

通过 ALTER INDEX 关闭 fastupdate 后,新插入的条目不会再进入待处理索引条目列表,但此操作本身不会清理已有条目。之后可对表执行 VACUUM 或调用 gin_clean_pending_list 函数,以确保待处理列表清空。

同版本参数定义

gin_pending_list_limit

为该索引覆盖 gin_pending_list_limit 的全局设置。该值以千字节为单位。

同版本参数定义

版本比较

目标 PostgreSQL 18.6

GIN

  • 并行索引构建: 不支持 → 支持

比较范围为能力状态和文档中的存储参数名称,不覆盖全部算法、性能特点、参数定义和发布说明变化。

文档记录的历史

PostgreSQL 17 → 18

  • 并行索引构建: 不支持 → 支持

PostgreSQL 10 → 11

  • 并行索引构建: 未确定 → 不支持 (来源覆盖变化)

PostgreSQL 9.6 → 10

  • 并行索引扫描: 未确定 → 不支持 (来源覆盖变化)

PostgreSQL 9.5 → 9.6

  • 仅索引扫描: 未确定 → 不支持 (来源覆盖变化)

PostgreSQL 9.4 → 9.5

  • 新增记录的存储参数: gin_pending_list_limit

相关文档与对象

来源与构建标识

原始证据来自英文手册构建 18.6。中文译文另列来源,不将文档结论作为运行时能力测量。

来源指纹
手册构建
PostgreSQL 18.6 Documentation
组合页面 SHA-256
0e39ebd4fddbd990280e62f4503f0bd18765bbd990dccf4cba976b5d47da45e7
手册清单记录的源码归档
18.6
手册清单记录的归档 SHA-256
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f
  • indexes-types.html: cee340145a2ef5fbd807f66755b10d22bb049e328c460f572f45ad6193e7e4a1
  • catalog-pg-am.html: 579364179365a51945e2edb6481df5d198916c2c725e506f166824dedf08994c
  • hash-index.html: b994550220e1ee05648d09804c9eb2302834e07e261932420a96605d7c9c6140
  • indexam.html: 0a38f7c0ac0541f31e086c83a624e782c15367456578a6dd3329882516bc1080
  • indexes-index-only-scans.html: 2322ec12b82f3fd01ee4072049caaa5a0190148ac68d98c0fcd6eda958828a83
  • indexes-multicolumn.html: c0a799ec49b8ef057a63d465fb1d72a3b81e16d652c28a71734d45592d081202
  • indexes-opclass.html: 07de06abf3a2aff2a891a2789def434d9b76705e54d45ca5338dc13451ae2962
  • indexes-ordering.html: 85fac99c7c66ed19dd021f12b5cc53ce18aa5bfa4b56c8c168317f99b8f12d3b
  • indexes-unique.html: 7c3eac7fa180b22534ff01df0c68155f15b6b360ffe35507c5266059116840db
  • parallel-plans.html: 62207d207bead82b01b59dc119c4f95856f08655cc11d4699a05a40867ed2070
  • sql-createindex.html: 6aa00da55815d13d0355dd25cb1cdb603fa36964993f164d1b6f486011282580

返回 Index AM · 已记录于 PostgreSQL 9.0 至 20;最早样本不代表实际引入版本。