Postgresql 中文操作指南
Chapter 64. Index Access Method Interface Definition
Table of Contents
本章定义了 PostgreSQL 核心系统与 index access methods 之间的接口,后者管理单独的索引类型。除了此处指定的索引之外,核心系统并不知道其他任何索引,因此可以编写附加代码来开发全新的索引类型。
This chapter defines the interface between the core PostgreSQL system and index access methods, which manage individual index types. The core system knows nothing about indexes beyond what is specified here, so it is possible to develop entirely new index types by writing add-on code.
PostgreSQL 中的所有索引在技术上都称为 secondary indexes ;这意味着索引在物理上与其描述的表文件分开。每个索引都作为其自己的物理 relation 存储,因此由 pg_class 目录中的某个条目来描述。索引的内容完全由其索引访问方法控制。实际上,所有索引访问方法都将索引分为标准大小的页面,以便它们可以使用常规存储管理器和缓冲区管理器来访问索引内容。(所有现有的索引访问方法还使用 Section 73.6 中描述的标准页面布局,并且大多数使用相同的索引元组头格式;但访问方法无需采用这些决策。)
All indexes in PostgreSQL are what are known technically as secondary indexes; that is, the index is physically separate from the table file that it describes. Each index is stored as its own physical relation and so is described by an entry in the pg_class catalog. The contents of an index are entirely under the control of its index access method. In practice, all index access methods divide indexes into standard-size pages so that they can use the regular storage manager and buffer manager to access the index contents. (All the existing index access methods furthermore use the standard page layout described in Section 73.6, and most use the same format for index tuple headers; but these decisions are not forced on an access method.)
索引实际上是从某些数据键值到索引所在父表的行版本(元组)的 tuple identifiers 或 TID 的映射。TID 包含块编号和该块内的项目编号(请参见 Section 73.6 )。这些信息足以从表中获取某个特定的行版本。索引并不知道在 MVCC 中同一个逻辑行可能存在多个现有版本;对索引而言,每个元组都是一个独立对象,需要有自己的索引条目。因此,即使键值未发生更改,对行的更新也总是为该行创建全新的索引条目。( HOT tuples 是该语句的例外;但索引也不会处理它们。)死元组的索引条目在死元组本身被回收时进行回收(通过 Vacuum)。
An index is effectively a mapping from some data key values to tuple identifiers, or TIDs, of row versions (tuples) in the index’s parent table. A TID consists of a block number and an item number within that block (see Section 73.6). This is sufficient information to fetch a particular row version from the table. Indexes are not directly aware that under MVCC, there might be multiple extant versions of the same logical row; to an index, each tuple is an independent object that needs its own index entry. Thus, an update of a row always creates all-new index entries for the row, even if the key values did not change. (HOT tuples are an exception to this statement; but indexes do not deal with those, either.) Index entries for dead tuples are reclaimed (by vacuuming) when the dead tuples themselves are reclaimed.