Skip to content

Commit 687de63

Browse files
authored
Merge pull request #391 from sirlipeng/master
翻译14.1 by sirlipeng 2022/09/01
2 parents 0bb8188 + 976ed19 commit 687de63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1150
-321
lines changed

postgresql/doc/src/sgml/hash.sgml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
<!-- doc/src/sgml/hash.sgml -->
22

33
<chapter id="hash-index">
4+
<!--==========================orignal english content==========================
45
<title>Hash Indexes</title>
6+
____________________________________________________________________________-->
7+
<title>哈希索引</title>
58

9+
<!--==========================orignal english content==========================
610
<indexterm>
711
<primary>index</primary>
812
<secondary>Hash</secondary>
913
</indexterm>
14+
____________________________________________________________________________-->
15+
<indexterm>
16+
<primary>索引</primary>
17+
<secondary>哈希</secondary>
18+
</indexterm>
1019

1120
<sect1 id="hash-intro">
21+
<!--==========================orignal english content==========================
1222
<title>Overview</title>
23+
____________________________________________________________________________-->
24+
<title>概述</title>
1325

26+
<!--==========================orignal english content==========================
1427
<para>
1528
<productname>PostgreSQL</productname>
1629
includes an implementation of persistent on-disk hash indexes,
@@ -20,26 +33,47 @@
2033
indexed, thus there are no restrictions on the size of the data column
2134
being indexed.
2235
</para>
36+
____________________________________________________________________________-->
37+
<para>
38+
<productname>PostgreSQL</productname>
39+
包含永久性磁盘上的哈希索引的实现,这些索引可完全崩溃恢复。任何数据类型都可以通过哈希索引进行索引,包括没有明确定义线性排序的数据类型。哈希索引只存储被索引数据的哈希值,因此对被索引数据列的大小没有限制。
40+
</para>
2341

42+
<!--==========================orignal english content==========================
2443
<para>
2544
Hash indexes support only single-column indexes and do not allow
2645
uniqueness checking.
2746
</para>
47+
____________________________________________________________________________-->
48+
<para>
49+
哈希索引仅支持单列索引并且不允许唯一性检查。
50+
</para>
2851

52+
<!--==========================orignal english content==========================
2953
<para>
3054
Hash indexes support only the <literal>=</literal> operator,
3155
so WHERE clauses that specify range operations will not be able to take
3256
advantage of hash indexes.
3357
</para>
58+
____________________________________________________________________________-->
59+
<para>
60+
哈希索引仅支持<literal>=</literal>运算符,因此使用了范围操作的WHERE子句将无法利用哈希索引。
61+
</para>
3462

63+
<!--==========================orignal english content==========================
3564
<para>
3665
Each hash index tuple stores just the 4-byte hash value, not the actual
3766
column value. As a result, hash indexes may be much smaller than B-trees
3867
when indexing longer data items such as UUIDs, URLs, etc. The absence of
3968
the column value also makes all hash index scans lossy. Hash indexes may
4069
take part in bitmap index scans and backward scans.
4170
</para>
71+
____________________________________________________________________________-->
72+
<para>
73+
每个哈希索引元组只存储4字节的哈希值,而不是实际的列值。因此,当索引较长的数据项(如UUID、URL等)时,哈希索引可能比B树小得多。缺少列值也会使所有哈希索引扫描有损。哈希索引可以参与位图索引扫描和反向扫描。
74+
</para>
4275

76+
<!--==========================orignal english content==========================
4377
<para>
4478
Hash indexes are best optimized for SELECT and UPDATE-heavy workloads
4579
that use equality scans on larger tables. In a B-tree index, searches must
@@ -51,7 +85,12 @@
5185
reduction in "logical I/O" becomes even more pronounced on indexes/data
5286
larger than shared_buffers/RAM.
5387
</para>
88+
____________________________________________________________________________-->
89+
<para>
90+
哈希索引对于在较大表上使用相等扫描的SELECT和UPDATE的繁重工作进行了最佳优化。在B树索引中,搜索必须在树中向下搜索,直到找到叶子页。在具有数百万行的表中,这种向下搜索会增加数据访问时间。哈希索引中叶子页的等价物称为桶页。相反,哈希索引允许直接访问桶页,从而可能减少较大表中的索引访问时间。在大于shared_buffers/RAM的索引/数据上,这种“逻辑I/O”的减少变得更加明显。
91+
</para>
5492

93+
<!--==========================orignal english content==========================
5594
<para>
5695
Hash indexes have been designed to cope with uneven distributions of
5796
hash values. Direct access to the bucket pages works well if the hash
@@ -63,7 +102,12 @@
63102
might actually be worse than a B-tree in terms of number of block
64103
accesses required, for some data.
65104
</para>
105+
____________________________________________________________________________-->
106+
<para>
107+
哈希索引被设计用于处理哈希值的不均匀分布。如果哈希值均匀分布,则直接访问桶页效果良好。当插入使得桶页变满时,额外的溢出页链接到该特定的桶页,本地扩展存储来容纳与该哈希值匹配的索引元组。在查询期间扫描哈希桶时,我们需要扫描所有溢出页。因此,就某些数据所需的块访问数而言,不平衡散列索引实际上可能比B树更差。
108+
</para>
66109

110+
<!--==========================orignal english content==========================
67111
<para>
68112
As a result of the overflow cases, we can say that hash indexes are
69113
most suitable for unique, nearly unique data or data with a low number
@@ -72,7 +116,13 @@
72116
values from the index using a partial index condition, but this may
73117
not be suitable in many cases.
74118
</para>
119+
____________________________________________________________________________-->
120+
<para>
121+
通过溢出情况得到的结论是,我们可以说哈希索引最适合于唯一、几乎唯一的数据或每个哈希桶的行数较少的数据。
122+
避免问题的一种可能方法是使用部分索引条件从索引中排除高度非唯一的值,但这在许多情况下可能不适用。
123+
</para>
75124

125+
<!--==========================orignal english content==========================
76126
<para>
77127
Like B-Trees, hash indexes perform simple index tuple deletion. This
78128
is a deferred maintenance operation that deletes index tuples that are
@@ -82,7 +132,12 @@
82132
index tuples. Removal cannot occur if the page is pinned at that time.
83133
Deletion of dead index pointers also occurs during VACUUM.
84134
</para>
135+
____________________________________________________________________________-->
136+
<para>
137+
与B树一样,哈希索引执行简单的索引元组删除。这是一个延迟维护操作,用于删除已知可以安全删除的索引元组(其项标识符的LP_DEAD位已设置的那些)。如果insert发现页面上没有可用空间,我们会尝试通过删除死索引元组来避免创建新的溢出页面。如果此时页面已被锁定,则无法删除。VACUUM期间也会删除死索引指针。
138+
</para>
85139

140+
<!--==========================orignal english content==========================
86141
<para>
87142
If it can, VACUUM will also try to squeeze the index tuples onto as
88143
few overflow pages as possible, minimizing the overflow chain. If an
@@ -92,7 +147,12 @@
92147
rebuilding it with REINDEX.
93148
There is no provision for reducing the number of buckets, either.
94149
</para>
150+
____________________________________________________________________________-->
151+
<para>
152+
如果可以,VACUUM还将尝试将索引元组压缩到尽可能少的溢出页上,以最小化溢出链。如果溢出页变为空,溢出页可以被回收以在其他桶中重用,尽管我们从未将它们返回到操作系统。目前,除了使用REINDEX重建哈希索引外,没有任何收缩哈希索引的方法。也没有减少桶数量的方法。
153+
</para>
95154

155+
<!--==========================orignal english content==========================
96156
<para>
97157
Hash indexes may expand the number of bucket pages as the number of
98158
rows indexed grows. The hash key-to-bucket-number mapping is chosen so that
@@ -101,26 +161,44 @@
101161
its tuples being transferred to the new bucket according to the updated
102162
key-to-bucket-number mapping.
103163
</para>
164+
____________________________________________________________________________-->
165+
<para>
166+
哈希索引可能会随着索引行数的增加而扩展桶页数。选择哈希键到桶号的映射,以便可以增量扩展索引。当一个新的桶要添加到索引中时,只需要“拆分”一个现有的桶,其中的一些元组将根据更新后的key到桶号的映射转移到新桶。
167+
</para>
104168

169+
<!--==========================orignal english content==========================
105170
<para>
106171
The expansion occurs in the foreground, which could increase execution
107172
time for user inserts. Thus, hash indexes may not be suitable for tables
108173
with rapidly increasing number of rows.
109174
</para>
175+
____________________________________________________________________________-->
176+
<para>
177+
扩展发生在前端,这可能会增加用户插入的执行时间。因此,哈希索引可能不适用于行数快速增加的表。
178+
</para>
110179

111180
</sect1>
112181

113182
<sect1 id="hash-implementation">
183+
<!--==========================orignal english content==========================
114184
<title>Implementation</title>
185+
____________________________________________________________________________-->
186+
<title>实现</title>
115187

188+
<!--==========================orignal english content==========================
116189
<para>
117190
There are four kinds of pages in a hash index: the meta page (page zero),
118191
which contains statically allocated control information; primary bucket
119192
pages; overflow pages; and bitmap pages, which keep track of overflow
120193
pages that have been freed and are available for re-use. For addressing
121194
purposes, bitmap pages are regarded as a subset of the overflow pages.
122195
</para>
196+
____________________________________________________________________________-->
197+
<para>
198+
哈希索引中有四种页面:元页面(零页),其中包含静态分配的控制信息;主桶页;溢出页;和位图页,它们跟踪已释放并可供重用的溢出页。出于寻址目的,位图页被视为溢出页的子集。
199+
</para>
123200

201+
<!--==========================orignal english content==========================
124202
<para>
125203
Both scanning the index and inserting tuples require locating the bucket
126204
where a given tuple ought to be located. To do this, we need the bucket
@@ -131,15 +209,25 @@
131209
mapping as long as the target bucket hasn't been split since the last
132210
cache refresh.
133211
</para>
212+
____________________________________________________________________________-->
213+
<para>
214+
扫描索引和插入元组都需要定位给定元组应该位于的桶。为此,我们需要元页面中的桶计数、highmask和lowmask;然而,出于性能原因,必须为每个此类操作加锁和锁定元页是不可取的。相反,我们在每个后端的relcache条目中保留了元页面的缓存副本。只要目标桶自上次缓存刷新后未被拆分,这将生成正确的桶映射。
215+
</para>
134216

217+
<!--==========================orignal english content==========================
135218
<para>
136219
Primary bucket pages and overflow pages are allocated independently since
137220
any given index might need more or fewer overflow pages relative to its
138221
number of buckets. The hash code uses an interesting set of addressing
139222
rules to support a variable number of overflow pages while not having to
140223
move primary bucket pages around after they are created.
141224
</para>
225+
____________________________________________________________________________-->
226+
<para>
227+
主桶页和溢出页是独立分配的,因为任何给定的索引相对于其桶的数量可能需要更多或更少的溢出页。哈希代码使用一组有趣的寻址规则来支持可变数量的溢出页,而不必在创建主桶页后四处移动。
228+
</para>
142229

230+
<!--==========================orignal english content==========================
143231
<para>
144232
Each row in the table indexed is represented by a single index tuple in
145233
the hash index. Hash index tuples are stored in bucket pages, and if
@@ -148,14 +236,23 @@
148236
used within an index page. Note however that there is *no* assumption about
149237
the relative ordering of hash codes across different index pages of a bucket.
150238
</para>
239+
____________________________________________________________________________-->
240+
<para>
241+
索引表中的每一行由哈希索引中的单个索引元组表示。哈希索引元组存储在桶页中,如果存在,则存储在溢出页中。我们通过将任意一个索引页中的索引项按哈希代码排序来加快搜索速度,从而允许在索引页中使用二进制搜索。但是,请注意,对于一个桶的不同索引页上的哈希代码的相对排序,没有上述排序。
242+
</para>
151243

244+
<!--==========================orignal english content==========================
152245
<para>
153246
The bucket splitting algorithms to expand the hash index are too complex to
154247
be worthy of mention here, though are described in more detail in
155248
<filename>src/backend/access/hash/README</filename>.
156249
The split algorithm is crash safe and can be restarted if not completed
157250
successfully.
158251
</para>
252+
____________________________________________________________________________-->
253+
<para>
254+
用于扩展哈希索引的桶分割算法过于复杂,不值得在此提及,下面有更详细的描述<filename>src/backend/access/hash/README</filename>。拆分算法是崩溃安全的,如果未成功完成,可以重新启动。
255+
</para>
159256

160257
</sect1>
161258

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
<!-- doc/src/sgml/install-binaries.sgml -->
22
<chapter id="install-binaries">
3+
<!--==========================orignal english content==========================
34
<title>Installation from Binaries</title>
5+
____________________________________________________________________________-->
6+
<title>从二进制安装</title>
47

8+
<!--==========================orignal english content==========================
9+
<indexterm>
10+
<primary>installation</primary>
11+
<secondary>binaries</secondary>
12+
</indexterm>
13+
____________________________________________________________________________-->
514
<indexterm>
615
<primary>installation</primary>
716
<secondary>binaries</secondary>
817
</indexterm>
918

19+
<!--==========================orignal english content==========================
1020
<para>
1121
<productname>PostgreSQL</productname> is available in the form of binary
1222
packages for most common operating systems today. When available, this is
1323
the recommended way to install PostgreSQL for users of the system. Building
1424
from source (see <xref linkend="installation" />) is only recommended for
1525
people developing <productname>PostgreSQL</productname> or extensions.
1626
</para>
27+
____________________________________________________________________________-->
28+
<para>
29+
<productname>PostgreSQL</productname>以二进制软件包的形式提供给当今大多数常见的操作系统。如果可用,这是系统用户安装PostgreSQL的推荐方法。仅建议<productname>PostgreSQL</productname>的开发或扩展人员从源代码构建(请参见<xref linkend="installation" />)。
30+
</para>
1731

32+
<!--==========================orignal english content==========================
1833
<para>
1934
For an updated list of platforms providing binary packages, please visit
2035
the download section on the <productname>PostgreSQL</productname> website at
2136
<ulink url="https://www.postgresql.org/download/"></ulink> and follow the
2237
instructions for the specific platform.
2338
</para>
39+
____________________________________________________________________________-->
40+
<para>
41+
有关提供二进制软件包的平台的更新列表,请访问<productname>PostgreSQL</productname>网站上的<ulink url="https://www.postgresql.org/download/"></ulink>并遵循特定平台的说明。
42+
</para>
2443
</chapter>

postgresql/doc/src/sgml/oldsnapshot.sgml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
11
<!-- doc/src/sgml/oldsnapshot.sgml -->
22

33
<sect1 id="oldsnapshot" xreflabel="old_snapshot">
4+
<!--==========================orignal english content==========================
5+
<title>old_snapshot</title>
6+
____________________________________________________________________________-->
47
<title>old_snapshot</title>
58

9+
<!--==========================orignal english content==========================
10+
<indexterm zone="oldsnapshot">
11+
<primary>old_snapshot</primary>
12+
</indexterm>
13+
____________________________________________________________________________-->
614
<indexterm zone="oldsnapshot">
715
<primary>old_snapshot</primary>
816
</indexterm>
917

18+
<!--==========================orignal english content==========================
1019
<para>
1120
The <filename>old_snapshot</filename> module allows inspection
1221
of the server state that is used to implement
1322
<xref linkend="guc-old-snapshot-threshold" />.
1423
</para>
24+
____________________________________________________________________________-->
25+
<para>
26+
The <filename>old_snapshot</filename>模块用来检查用来实现
27+
<xref linkend="guc-old-snapshot-threshold" />的服务器的状态。
28+
</para>
1529

1630
<sect2>
31+
<!--==========================orignal english content==========================
1732
<title>Functions</title>
33+
____________________________________________________________________________-->
34+
<title>函数</title>
1835

1936
<variablelist>
2037
<varlistentry>
38+
<!--==========================orignal english content==========================
2139
<term><function>pg_old_snapshot_time_mapping(array_offset OUT int4, end_timestamp OUT timestamptz, newest_xmin OUT xid) returns setof record</function></term>
40+
____________________________________________________________________________-->
41+
<term><function>pg_old_snapshot_time_mapping(array_offset OUT int4, end_timestamp OUT timestamptz, newest_xmin OUT xid)returns setof record</function></term>
2242
<listitem>
43+
<!--==========================orignal english content==========================
2344
<para>
2445
Returns all of the entries in the server's timestamp to XID mapping.
2546
Each entry represents the newest xmin of any snapshot taken in the
2647
corresponding minute.
2748
</para>
49+
____________________________________________________________________________-->
50+
<para>
51+
返回服务器所有时间戳到XID的映射条目。每个条目表示在相应分钟内拍摄的任何快照的最新xmin。
52+
</para>
2853
</listitem>
2954
</varlistentry>
3055
</variablelist>

0 commit comments

Comments
 (0)