GIN(Generalized Inverted Index,广义倒排索引)是一种索引类型,它比通常的键/值关系(例如 btree 索引所支持的)能处理更复杂的数据类型。 GIN 的常见应用包括对 数组 值和 全文搜索 进行索引。
GIN 索引支持在 PostgreSQL 8.2 中引入。
函数
以下系统函数可用于 GIN 管理
Contrib 模块支持
以下 contrib 模块 提供了函数,用于提供有关 GIN 索引的更多详细信息
pageinspectgin_metapage_info()gin_page_opaque_info()gin_leafpage_items()
pgstattuplepgstatginindex()
btree_gin 为某些数据类型提供了 btree 等效行为的支持。
变更历史
- PostgreSQL 18
- 支持
CREATE INDEX CONCURRENTLY ...(提交 8492feb9)
- 支持
- PostgreSQL 13
- PostgreSQL 12
- PostgreSQL 11
- 添加了谓词锁定(提交 43d1ed60)
- PostgreSQL 10
- 在 vacuum 操作期间减少了页面锁定(提交 218f5158)
- PostgreSQL 9.6
- 可以使用大于
1GB的maintenance_work_mem值进行GIN索引构建(提交 30bb26b5) - 从 GIN 索引的待处理列表中删除的页面立即添加到空闲空间映射中(提交 e9568083 和 dc943ad9)
- 添加了函数
gin_clean_pending_list()(提交 7f46eaf0)
- 可以使用大于
- PostgreSQL 9.5
- 添加了
gin_pending_list_limit配置参数(提交 a1b395b6) - 以下用于检查
GIN索引的函数已添加到pageinspect(提交 3a82bc6f)gin_metapage_info()gin_page_opaque_info()gin_leafpage_items()
- 添加了
- PostgreSQL 9.4
- PostgreSQL 9.3
- 函数
pgstatginindex()已添加到pgstattuple(提交 357cbaae)
- 函数
- PostgreSQL 9.1
- PostgreSQL 9.0
- 使用红黑二叉树进行索引创建(提交 5209c084)
- PostgreSQL 8.4
- PostgreSQL 8.3
- PostgreSQL 8.2
- 已添加(提交 8a3631f8)
参考资料
- PostgreSQL documentation: GIN indexes
- PostgreSQL documentation: GiST and GIN Index Types
有用链接
- Understanding Postgres GIN Indexes: The Good and the Bad - December 2021 blog article by Lukas Fittl / pganalyze
- GIN - Just A Kind Of Index - explanation from Cybertec Schönig & Schönig GmbH
- Original developer documentation (outdated)
