@@ -118,7 +118,7 @@ CREATE INDEX test1_id_index ON test1 (id);
118
118
</para>
119
119
____________________________________________________________________________-->
120
120
<para>
121
- 为了移除一个索引,可以使用 <command>DROP INDEX</command>命令。索引可以随时被创建或删除。
121
+ 删除一个索引,使用 <command>DROP INDEX</command>命令。索引可以随时被创建或删除。
122
122
</para>
123
123
124
124
<!--==========================orignal english content==========================
@@ -148,7 +148,7 @@ ____________________________________________________________________________-->
148
148
</para>
149
149
____________________________________________________________________________-->
150
150
<para>
151
- 索引也会使带有搜索条件的 <command>UPDATE</command>和<command>DELETE</command>命令受益 。此外索引还可以在连接搜索中使用。因此,一个定义在连接条件列上的索引可以显著地提高连接查询的速度。
151
+ 索引也会对带有搜索条件的 <command>UPDATE</command>和<command>DELETE</command>命令有帮助 。此外索引还可以在连接搜索中使用。因此,一个定义在连接条件列上的索引可以显著地提高连接查询的速度。
152
152
</para>
153
153
154
154
<!--==========================orignal english content==========================
@@ -193,15 +193,24 @@ ____________________________________________________________________________-->
193
193
B-tree, Hash, GiST, SP-GiST, GIN and BRIN.
194
194
Each index type uses a different
195
195
algorithm that is best suited to different types of queries.
196
- By default, the <command>CREATE INDEX</command> command creates
196
+ By default, the <link linkend="sql-createindex"><command>CREATE
197
+ INDEX</command></link> command creates
197
198
B-tree indexes, which fit the most common situations.
199
+ The other index types are selected by writing the keyword
200
+ <literal>USING</literal> followed by the index type name.
201
+ For example, to create a Hash index:
198
202
</para>
199
203
____________________________________________________________________________-->
200
204
<para>
201
205
<productname>PostgreSQL</productname>提供了多种索引类型:
202
206
B-tree、Hash、GiST、SP-GiST 、GIN 和 BRIN。每一种索引类型使用了
203
207
一种不同的算法来适应不同类型的查询。默认情况下,
204
- <command>CREATE INDEX</command>命令创建适合于大部分情况的B-tree 索引。
208
+ <link linkend="sql-createindex"><command>CREATE
209
+ INDEX</command></link> 命令创建适合于大部分情况的B-tree 索引。
210
+ 在索引类型名后面加上关键字<literal>USING</literal> , 可以选择其他的索引类型,例如, 创建一个HASH索引:
211
+ <programlisting>
212
+ CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> USING HASH (<replaceable>column</replaceable>);
213
+ </programlisting>
205
214
</para>
206
215
207
216
<!--==========================orignal english content==========================
@@ -234,24 +243,21 @@ ____________________________________________________________________________-->
234
243
NULL</literal> condition on an index column can be used with a B-tree index.
235
244
</para>
236
245
____________________________________________________________________________-->
237
- <para>
246
+ <sect2 id="indexes-types-btree">
247
+ <title>B-Tree</title>
238
248
<indexterm>
239
249
<primary>index</primary>
240
- <secondary>B-tree </secondary>
250
+ <secondary>B-Tree </secondary>
241
251
</indexterm>
242
252
<indexterm>
243
- <primary>B-tree </primary>
253
+ <primary>B-Tree </primary>
244
254
<see>index</see>
245
255
</indexterm>
246
256
B-tree可以在可排序数据上的处理等值和范围查询。特别地,<productname>PostgreSQL</productname>的查询规划器会在任何一种涉及到以下操作符的已索引列上考虑使用B-tree索引:
247
257
248
- <simplelist>
249
- <member><literal><</literal></member>
250
- <member><literal><=</literal></member>
251
- <member><literal>=</literal></member>
252
- <member><literal>>=</literal></member>
253
- <member><literal>></literal></member>
254
- </simplelist>
258
+ <synopsis>
259
+ < <= = >= >
260
+ </synopsis>
255
261
256
262
将这些操作符组合起来,例如<literal>BETWEEN</literal>和<literal>IN</literal>,也可以用B-tree索引搜索实现。同样,在索引列上的<literal>IS NULL</literal>或<literal>IS NOT
257
263
NULL</literal>条件也可以在B-tree索引中使用。
@@ -289,6 +295,7 @@ ____________________________________________________________________________-->
289
295
<para>
290
296
B-tree索引也可以用于检索排序数据。这并不会总是比简单扫描和排序更快,但是总是有用的。
291
297
</para>
298
+ </sect2>
292
299
293
300
<!--==========================orignal english content==========================
294
301
<para>
@@ -310,7 +317,8 @@ CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable>
310
317
</synopsis>
311
318
</para>
312
319
____________________________________________________________________________-->
313
- <para>
320
+ <sect2 id="indexes-types-hash">
321
+ <title>Hash</title>
314
322
<indexterm>
315
323
<primary>index</primary>
316
324
<secondary>hash</secondary>
@@ -319,11 +327,12 @@ ____________________________________________________________________________-->
319
327
<primary>hash</primary>
320
328
<see>index</see>
321
329
</indexterm>
322
- Hash索引只能处理简单等值比较。不论何时当一个索引列涉及到一个使用了<literal>=</literal>操作符的比较时,查询规划器将考虑使用一个Hash索引。下面的命令将创建一个Hash索引:
330
+ HASH索引存储一个由索引列计算出的32位的hash code值。因此, Hash索引只能处理简单等值比较。每当索引列涉及到等值操作符的比较时,查询规划器将会使用Hash索引。
323
331
<synopsis>
324
- CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> USING HASH (<replaceable>column</replaceable>);
332
+ =
325
333
</synopsis>
326
334
</para>
335
+ </sect2>
327
336
328
337
<!--==========================orignal english content==========================
329
338
<para>
@@ -368,7 +377,8 @@ CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable>
368
377
projects. For more information see <xref linkend="gist"/>.
369
378
</para>
370
379
____________________________________________________________________________-->
371
- <para>
380
+ <sect2 id="indexes-type-gist">
381
+ <title>GiST</title>
372
382
<indexterm>
373
383
<primary>index</primary>
374
384
<secondary>GiST</secondary>
@@ -377,22 +387,12 @@ ____________________________________________________________________________-->
377
387
<primary>GiST</primary>
378
388
<see>index</see>
379
389
</indexterm>
390
+ <para>
380
391
GiST索引并不是一种单独的索引,而是可以用于实现很多不同索引策略的基础设施。相应地,可以使用一个GiST索引的特定操作符根据索引策略(<firstterm>操作符类</firstterm>)而变化。作为一个例子,<productname>PostgreSQL</productname>的标准捐献包中包括了用于多种二维几何数据类型的GiST操作符类,它用来支持使用下列操作符的索引化查询:
381
392
382
- <simplelist>
383
- <member><literal><<</literal></member>
384
- <member><literal>&<</literal></member>
385
- <member><literal>&></literal></member>
386
- <member><literal>>></literal></member>
387
- <member><literal><<|</literal></member>
388
- <member><literal>&<|</literal></member>
389
- <member><literal>|&></literal></member>
390
- <member><literal>|>></literal></member>
391
- <member><literal>@></literal></member>
392
- <member><literal><@</literal></member>
393
- <member><literal>~=</literal></member>
394
- <member><literal>&&</literal></member>
395
- </simplelist>
393
+ <synopsis>
394
+ << &< &> >> <<| &<| |&> |>> @> <@ ~= &&
395
+ </synopsis>
396
396
397
397
(这些操作符的含义见<xref linkend="functions-geometry"/>)<xref linkend="gist-builtin-opclasses-table"/>中给出了标准发布中所包括的 GiST 操作符类。<literal>contrib</literal>集合中还包括了很多其他GiST操作符类,可见<xref linkend="gist"/>。
398
398
</para>
@@ -420,6 +420,7 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
420
420
它将找到离给定目标点最近的10个位置。能够支持这种查询的能力同样取决于被使用的特定操作符类。
421
421
在<xref linkend="gist-builtin-opclasses-table"/>中,<quote>Ordering Operators</quote>列中列出了可以在这种方法中使用的操作符。
422
422
</para>
423
+ </sect2>
423
424
424
425
<!--==========================orignal english content==========================
425
426
<para>
@@ -455,7 +456,8 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
455
456
For more information see <xref linkend="spgist"/>.
456
457
</para>
457
458
____________________________________________________________________________-->
458
- <para>
459
+ <sect2 id="indexes-type-spgist">
460
+ <title>SP-GiST</title>
459
461
<indexterm>
460
462
<primary>index</primary>
461
463
<secondary>SP-GiST</secondary>
@@ -464,17 +466,13 @@ ____________________________________________________________________________-->
464
466
<primary>SP-GiST</primary>
465
467
<see>index</see>
466
468
</indexterm>
469
+ <para>
467
470
和GiST相似,SP-GiST索引为支持多种搜索提供了一种基础结构。SP-GiST 允许实现众多不同的非平衡的基于磁盘的数据结构,例如四叉树、k-d树和radix树。作为一个例
468
471
子,<productname>PostgreSQL</productname>的标准捐献包中包含了一个用于二维点的SP-GiST操作符类,它用于支持使用下列操作符的索引化查询:
469
472
470
- <simplelist>
471
- <member><literal><<</literal></member>
472
- <member><literal>>></literal></member>
473
- <member><literal>~=</literal></member>
474
- <member><literal><@</literal></member>
475
- <member><literal><^</literal></member>
476
- <member><literal>>^</literal></member>
477
- </simplelist>
473
+ <synopsis>
474
+ << >> ~= <@ <<| |>>
475
+ </synopsis>
478
476
479
477
(其含义见<xref linkend="functions-geometry"/>)<xref linkend="spgist-builtin-opclasses-table"/>中给出了标准发布中所包括的 SP-GiST 操作符类。更多信息参见<xref linkend="spgist"/>。
480
478
</para>
@@ -489,8 +487,9 @@ ____________________________________________________________________________-->
489
487
____________________________________________________________________________-->
490
488
<para>
491
489
就像 GiST, SP-GiST 支持 <quote>nearest-neighbor</quote> 搜索.
492
- 对于支持距离排序的 SP-GiST 运算符类别,相应的运算符被规定在 <xref linkend="spgist-builtin-opclasses-table"/>里面的<quote>Ordering Operators</quote>列中 。
490
+ 对于支持距离排序的 SP-GiST 运算符类别,相应的运算符被列在 <xref linkend="spgist-builtin-opclasses-table"/>里面的<quote>Ordering Operators</quote>中 。
493
491
</para>
492
+ </sect2>
494
493
495
494
<!--==========================orignal english content==========================
496
495
<para>
@@ -509,7 +508,8 @@ ____________________________________________________________________________-->
509
508
component values.
510
509
</para>
511
510
____________________________________________________________________________-->
512
- <para>
511
+ <sect2 id="indexes-types-gin">
512
+ <title>GIN</title>
513
513
<indexterm>
514
514
<primary>index</primary>
515
515
<secondary>GIN</secondary>
@@ -518,6 +518,7 @@ ____________________________________________________________________________-->
518
518
<primary>GIN</primary>
519
519
<see>index</see>
520
520
</indexterm>
521
+ <para>
521
522
GIN 索引是<quote>倒排索引</quote>,它适合于包含多个组成值的数据值,例如数组。倒排索引中为每一个组成值都包含一个单独的项,它可以高效地处理测试指定组成值是否存在的查询。
522
523
</para>
523
524
@@ -550,15 +551,13 @@ ____________________________________________________________________________-->
550
551
<para>
551
552
与 GiST 和 SP-GiST相似, GIN 可以支持多种不同的用户定义的索引策略,并且可以与一个 GIN 索引配合使用的特定操作符取决于索引策略。作为一个例子,<productname>PostgreSQL</productname>的标准贡献包中包含了用于数组的GIN操作符类,它用于支持使用下列操作符的索引化查询:
552
553
553
- <simplelist>
554
- <member><literal><@</literal></member>
555
- <member><literal>@></literal></member>
556
- <member><literal>=</literal></member>
557
- <member><literal>&&</literal></member>
558
- </simplelist>
554
+ <synopsis>
555
+ <@ @> = &&
556
+ </synopsis>
559
557
560
558
(这些操作符的含义见<xref linkend="functions-array"/>)<xref linkend="gin-builtin-opclasses-table"/>中给出了标准发布中所包括的 GIN 操作符类。在<literal>contrib</literal>集合中还有更多其他GIN操作符类,更多信息参见<xref linkend="gin"/>。
561
559
</para>
560
+ </sect2>
562
561
563
562
<!--==========================orignal english content==========================
564
563
<para>
@@ -594,7 +593,8 @@ ____________________________________________________________________________-->
594
593
For more information see <xref linkend="brin"/>.
595
594
</para>
596
595
____________________________________________________________________________-->
597
- <para>
596
+ <sect2 id="indexes-types-brin">
597
+ <title>BRIN</title>
598
598
<indexterm>
599
599
<primary>index</primary>
600
600
<secondary>BRIN</secondary>
@@ -603,18 +603,15 @@ ____________________________________________________________________________-->
603
603
<primary>BRIN</primary>
604
604
<see>index</see>
605
605
</indexterm>
606
- BRIN 索引(块范围索引的缩写)存储有关存放在一个表的连续物理块范围上的值摘要信息。与 GiST、SP-GiST 和 GIN 相似,BRIN 可以支持很多种不同的索引策略,并且可以与一个 BRIN 索引配合使用的特定操作符取决于索引策略。对于具有线性排序顺序的数据类型,被索引的数据对应于每个块范围的列中值的最小值和最大值,使用这些操作符来支持用到索引的查询:
606
+ BRIN 索引(块范围索引的缩写)存储有关存放在一个表的连续物理块范围上的值摘要信息。因此,那些值和table中物理行存放顺序相关性更好的列更高效。 与 GiST、SP-GiST 和 GIN 相似,BRIN 可以支持很多种不同的索引策略,并且可以与一个 BRIN 索引配合使用的特定操作符取决于索引策略。对于具有线性排序顺序的数据类型,被索引的数据对应于每个块范围的列中值的最小值和最大值,使用这些操作符来支持用到索引的查询:
607
607
608
- <simplelist>
609
- <member><literal><</literal></member>
610
- <member><literal><=</literal></member>
611
- <member><literal>=</literal></member>
612
- <member><literal>>=</literal></member>
613
- <member><literal>></literal></member>
614
- </simplelist>
608
+ <synopsis>
609
+ < <= = >= >
610
+ </synopsis>
615
611
616
- 包括在标准发布中的 BRIN 操作符类的文档在 <xref linkend="brin-builtin-opclasses-table"/>中 。更多信息请见<xref linkend="brin"/>。
612
+ 标准发行文档中有记录BRIN 操作符类 <xref linkend="brin-builtin-opclasses-table"/>。更多信息请见<xref linkend="brin"/>。
617
613
</para>
614
+ </sect2>
618
615
</sect1>
619
616
620
617
@@ -688,7 +685,7 @@ CREATE INDEX test2_mm_idx ON test2 (major, minor);
688
685
</para>
689
686
____________________________________________________________________________-->
690
687
<para>
691
- 目前,只有 B-tree、GiST、GIN 和 BRIN 索引类型支持多列索引,最多可以指定32个列 (该限制可以在源代码文件<filename>pg_config_manual.h</filename>中修改,但是修改后需要重新编译<productname>PostgreSQL</productname>)。
688
+ 目前,只有 B-tree、GiST、GIN 和 BRIN 索引类型支持多列索引。是否可以有多个关键列与<literal>INCLUDE</literal>列是否可以被添加到索引中无关。 索引最多可以有32列,包括<literal>INCLUDE</literal>列。 (该限制可以在源代码文件<filename>pg_config_manual.h</filename>中修改,但是修改后需要重新编译<productname>PostgreSQL</productname>)。
692
689
</para>
693
690
694
691
<!--==========================orignal english content==========================
@@ -1970,7 +1967,7 @@ CREATE UNIQUE INDEX tab_x_y ON tab(x) INCLUDE (y);
1970
1967
</para>
1971
1968
____________________________________________________________________________-->
1972
1969
<para>
1973
- 保守地将非键负载列添加到索引是明智的,尤其是宽列。 如果索引元组超过索引类型允许的最大大小,数据插入将失败。在任何情况下,非键列都将复制索引表中的数据并放大了索引的大小,从而有可能减慢搜索速度。请记住,除非一个表足够慢以至于仅索引扫描可能不必访问堆,否则没有什么理由在一个索引中包含负载列。无论如何,如果必须访问堆元组,从堆里获取列的值并不会带来更高的开销。其他限制是表达式不被作为包含的来支持。只有B树和GiST索引当前支持包含的列 。
1970
+ 保守地将非键负载列添加到索引是明智的,尤其是宽列。 如果索引元组超过索引类型允许的最大大小,数据插入将失败。在任何情况下,非键列都将复制索引表中的数据并放大了索引的大小,从而有可能减慢搜索速度。请记住,除非一个表足够慢以至于仅索引扫描可能不必访问堆,否则没有什么理由在一个索引中包含负载列。无论如何,如果必须访问堆元组,从堆里获取列的值并不会带来更高的开销。其他限制是表达式不被作为包含的来支持。只有B树,GiST和SP-GiST 索引当前支持包含的列 。
1974
1971
</para>
1975
1972
1976
1973
<!--==========================orignal english content==========================
0 commit comments