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

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

百科 / Index AM / SP-GiST

SP-GiST

可扩展检索

SP-GiST 与 GiST 一样,提供支持多种搜索方式的基础框架。SP-GiST 可实现多种基于磁盘的非平衡数据结构,例如四叉树、k-d 树和基数树(tries)。例如,PostgreSQL 标准发行版提供二维点的 SP-GiST 操作符类,支持使用下列运算符的索引查询:

当前查看 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

按距离排序有条件

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

同版本英文证据

Like GiST, SP-GiST supports “ nearest-neighbor ” searches. For SP-GiST operator classes that support distance ordering, the corresponding operator is listed in the “ Ordering Operators ” column in Table 65.2 .

PostgreSQL 18.6 · indexes-types

并行索引扫描不支持

多个进程协作扫描同一索引,不同于并行位图堆扫描,也不同于 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 spgist (column_name);

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

SP-GiST 与 GiST 一样,提供支持多种搜索方式的基础框架。SP-GiST 可实现多种基于磁盘的非平衡数据结构,例如四叉树、k-d 树和基数树(tries)。例如,PostgreSQL 标准发行版提供二维点的 SP-GiST 操作符类,支持使用下列运算符的索引查询:

<<   >>   ~=   <@   <<|   |>>

(这些操作符的含义见 第 9.11 节 。)标准发布版自带的 SP-GiST 操作符类记录在 表 65.2 中。更多信息见 第 65.3 节 。

与 GiST 一样,SP-GiST 支持 “ 最近邻 ” 搜索。对于支持距离排序的 SP-GiST 操作符类,相应操作符列在 表 65.2 的 “ 排序操作符 ” 列中。

存储参数

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

fillfactor

控制索引方法尝试将索引页填充到多满。对于 B-树,在初始构建索引时,以及在右侧扩展索引(加入新的最大键值)时,叶子页都会填充到这一百分比。如果页面随后变成全满,就会发生分裂,从而导致磁盘上的索引结构碎片化。B-树默认使用 90 的填充因子,但也可以选择 10 到 100 之间的任意整数值。

对预计会有大量插入和/或更新的表,在 CREATE INDEX 时为 B-树索引设置较低的填充因子会有好处(即在向表批量装载数据之后)。50 到 90 范围内的值可以有效地 “ 平滑 ” B-树索引生命周期早期页面分裂的 速率 (这样降低填充因子甚至可能减少页面分裂的绝对数量,不过这一效果高度依赖工作负载)。 第 65.1.4.2 节 中描述的 B-树自底向上索引删除技术依赖于页面上有一些 “ 额外 ” 空间来存储 “ 额外 ” 的元组版本,因此也会受到填充因子影响(不过通常影响不大)。

在某些其他特定情况下,在 CREATE INDEX 时将填充因子提高到 100 可能有助于最大化空间利用率。只有在完全确定该表是静态的(即永远不会受到插入或更新影响)时,才应考虑这样做。否则,将填充因子设为 100 有 损害 性能的风险:即便只有少量更新或插入,也会导致页面突然大量分裂。

其他索引方法以不同但大致类似的方式使用填充因子;默认填充因子因方法而异。

同版本参数定义

版本比较

目标 PostgreSQL 18.6

这些样本的文档能力状态和存储参数清单没有差异.

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

文档记录的历史

PostgreSQL 13 → 14

  • INCLUDE 附加列: 不支持 → 支持

PostgreSQL 11 → 12

  • 距离排序: 未确定 → 有条件 (来源覆盖变化)

PostgreSQL 10 → 11

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

PostgreSQL 9.6 → 10

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

PostgreSQL 9.5 → 9.6

  • 仅索引扫描: 未确定 → 有条件 (来源覆盖变化)

PostgreSQL 9.1 → 9.2

首次出现在当前样本清单中。

    相关文档与对象

    来源与构建标识

    原始证据来自英文手册构建 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.2 至 20;最早样本不代表实际引入版本。