Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85b4ba7

Browse files
committed
Doc: minor improvements for section 11.2 "Index Types".
Break the per-index-type discussions into <sect2>'s so as to makethem more visually separate and easier to find. Improve the markup,and make a couple of small wording adjustments.This also fixes one stray reference to the now-deprecated pointoperators <^ and >^.Dagfinn Ilmari Mannsåker, reviewed by David Johnston and Jürgen PurtzDiscussion:https://postgr.es/m/877dukhvzg.fsf@wibble.ilmari.org
1 parent2432b1a commit85b4ba7

File tree

1 file changed

+70
-56
lines changed

1 file changed

+70
-56
lines changed

‎doc/src/sgml/indices.sgml

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -118,32 +118,39 @@ CREATE INDEX test1_id_index ON test1 (id);
118118
B-tree, Hash, GiST, SP-GiST, GIN and BRIN.
119119
Each index type uses a different
120120
algorithm that is best suited to different types of queries.
121-
By default, the <command>CREATE INDEX</command> command creates
121+
By default, the <link linkend="sql-createindex"><command>CREATE
122+
INDEX</command></link> command creates
122123
B-tree indexes, which fit the most common situations.
124+
The other index types are selected by writing the keyword
125+
<literal>USING</literal> followed by the index type name.
126+
For example, to create a Hash index:
127+
<programlisting>
128+
CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> USING HASH (<replaceable>column</replaceable>);
129+
</programlisting>
123130
</para>
124131

125-
<para>
132+
<sect2 id="indexes-types-btree">
133+
<title>B-Tree</title>
134+
126135
<indexterm>
127136
<primary>index</primary>
128-
<secondary>B-tree</secondary>
137+
<secondary>B-Tree</secondary>
129138
</indexterm>
130139
<indexterm>
131-
<primary>B-tree</primary>
140+
<primary>B-Tree</primary>
132141
<see>index</see>
133142
</indexterm>
143+
144+
<para>
134145
B-trees can handle equality and range queries on data that can be sorted
135146
into some ordering.
136147
In particular, the <productname>PostgreSQL</productname> query planner
137148
will consider using a B-tree index whenever an indexed column is
138149
involved in a comparison using one of these operators:
139150

140-
<simplelist>
141-
<member><literal>&lt;</literal></member>
142-
<member><literal>&lt;=</literal></member>
143-
<member><literal>=</literal></member>
144-
<member><literal>&gt;=</literal></member>
145-
<member><literal>&gt;</literal></member>
146-
</simplelist>
151+
<synopsis>
152+
&lt; &nbsp; &lt;= &nbsp; = &nbsp; &gt;= &nbsp; &gt;
153+
</synopsis>
147154

148155
Constructs equivalent to combinations of these operators, such as
149156
<literal>BETWEEN</literal> and <literal>IN</literal>, can also be implemented with
@@ -172,8 +179,11 @@ CREATE INDEX test1_id_index ON test1 (id);
172179
This is not always faster than a simple scan and sort, but it is
173180
often helpful.
174181
</para>
182+
</sect2>
183+
184+
<sect2 id="indexes-types-hash">
185+
<title>Hash</title>
175186

176-
<para>
177187
<indexterm>
178188
<primary>index</primary>
179189
<secondary>hash</secondary>
@@ -182,17 +192,24 @@ CREATE INDEX test1_id_index ON test1 (id);
182192
<primary>hash</primary>
183193
<see>index</see>
184194
</indexterm>
185-
Hash indexes can only handle simple equality comparisons.
195+
196+
<para>
197+
Hash indexes store a 32-bit hash code derived from the
198+
value of the indexed column. Hence,
199+
such indexes can only handle simple equality comparisons.
186200
The query planner will consider using a hash index whenever an
187201
indexed column is involved in a comparison using the
188-
<literal>=</literal> operator.
189-
The following command is used to create a hash index:
202+
equal operator:
203+
190204
<synopsis>
191-
CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> USING HASH (<replaceable>column</replaceable>);
205+
=
192206
</synopsis>
193207
</para>
208+
</sect2>
209+
210+
<sect2 id="indexes-type-gist">
211+
<title>GiST</title>
194212

195-
<para>
196213
<indexterm>
197214
<primary>index</primary>
198215
<secondary>GiST</secondary>
@@ -201,6 +218,8 @@ CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable>
201218
<primary>GiST</primary>
202219
<see>index</see>
203220
</indexterm>
221+
222+
<para>
204223
GiST indexes are not a single kind of index, but rather an infrastructure
205224
within which many different indexing strategies can be implemented.
206225
Accordingly, the particular operators with which a GiST index can be
@@ -210,20 +229,9 @@ CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable>
210229
for several two-dimensional geometric data types, which support indexed
211230
queries using these operators:
212231

213-
<simplelist>
214-
<member><literal>&lt;&lt;</literal></member>
215-
<member><literal>&amp;&lt;</literal></member>
216-
<member><literal>&amp;&gt;</literal></member>
217-
<member><literal>&gt;&gt;</literal></member>
218-
<member><literal>&lt;&lt;|</literal></member>
219-
<member><literal>&amp;&lt;|</literal></member>
220-
<member><literal>|&amp;&gt;</literal></member>
221-
<member><literal>|&gt;&gt;</literal></member>
222-
<member><literal>@&gt;</literal></member>
223-
<member><literal>&lt;@</literal></member>
224-
<member><literal>~=</literal></member>
225-
<member><literal>&amp;&amp;</literal></member>
226-
</simplelist>
232+
<synopsis>
233+
&lt;&lt; &nbsp; &amp;&lt; &nbsp; &amp;&gt; &nbsp; &gt;&gt; &nbsp; &lt;&lt;| &nbsp; &amp;&lt;| &nbsp; |&amp;&gt; &nbsp; |&gt;&gt; &nbsp; @&gt; &nbsp; &lt;@ &nbsp; ~= &nbsp; &amp;&amp;
234+
</synopsis>
227235

228236
(See <xref linkend="functions-geometry"/> for the meaning of
229237
these operators.)
@@ -246,8 +254,11 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
246254
In <xref linkend="gist-builtin-opclasses-table"/>, operators that can be
247255
used in this way are listed in the column <quote>Ordering Operators</quote>.
248256
</para>
257+
</sect2>
258+
259+
<sect2 id="indexes-type-spgist">
260+
<title>SP-GiST</title>
249261

250-
<para>
251262
<indexterm>
252263
<primary>index</primary>
253264
<secondary>SP-GiST</secondary>
@@ -256,6 +267,8 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
256267
<primary>SP-GiST</primary>
257268
<see>index</see>
258269
</indexterm>
270+
271+
<para>
259272
SP-GiST indexes, like GiST indexes, offer an infrastructure that supports
260273
various kinds of searches. SP-GiST permits implementation of a wide range
261274
of different non-balanced disk-based data structures, such as quadtrees,
@@ -264,14 +277,9 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
264277
for two-dimensional points, which support indexed
265278
queries using these operators:
266279

267-
<simplelist>
268-
<member><literal>&lt;&lt;</literal></member>
269-
<member><literal>&gt;&gt;</literal></member>
270-
<member><literal>~=</literal></member>
271-
<member><literal>&lt;@</literal></member>
272-
<member><literal>&lt;^</literal></member>
273-
<member><literal>&gt;^</literal></member>
274-
</simplelist>
280+
<synopsis>
281+
&lt;&lt; &nbsp; &gt;&gt; &nbsp; ~= &nbsp; &lt;@ &nbsp; &lt;&lt;| &nbsp; |&gt;&gt;
282+
</synopsis>
275283

276284
(See <xref linkend="functions-geometry"/> for the meaning of
277285
these operators.)
@@ -283,11 +291,14 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
283291
<para>
284292
Like GiST, SP-GiST supports <quote>nearest-neighbor</quote> searches.
285293
For SP-GiST operator classes that support distance ordering, the
286-
corresponding operator isspecified in the <quote>Ordering Operators</quote>
294+
corresponding operator islisted in the <quote>Ordering Operators</quote>
287295
column in <xref linkend="spgist-builtin-opclasses-table"/>.
288296
</para>
297+
</sect2>
298+
299+
<sect2 id="indexes-types-gin">
300+
<title>GIN</title>
289301

290-
<para>
291302
<indexterm>
292303
<primary>index</primary>
293304
<secondary>GIN</secondary>
@@ -296,6 +307,8 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
296307
<primary>GIN</primary>
297308
<see>index</see>
298309
</indexterm>
310+
311+
<para>
299312
GIN indexes are <quote>inverted indexes</quote> which are appropriate for
300313
data values that contain multiple component values, such as arrays. An
301314
inverted index contains a separate entry for each component value, and
@@ -312,12 +325,9 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
312325
<productname>PostgreSQL</productname> includes a GIN operator class
313326
for arrays, which supports indexed queries using these operators:
314327

315-
<simplelist>
316-
<member><literal>&lt;@</literal></member>
317-
<member><literal>@&gt;</literal></member>
318-
<member><literal>=</literal></member>
319-
<member><literal>&amp;&amp;</literal></member>
320-
</simplelist>
328+
<synopsis>
329+
&lt;@ &nbsp; @&gt; &nbsp; = &nbsp; &amp;&amp;
330+
</synopsis>
321331

322332
(See <xref linkend="functions-array"/> for the meaning of
323333
these operators.)
@@ -327,8 +337,11 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
327337
classes are available in the <literal>contrib</literal> collection or as separate
328338
projects. For more information see <xref linkend="gin"/>.
329339
</para>
340+
</sect2>
341+
342+
<sect2 id="indexes-types-brin">
343+
<title>BRIN</title>
330344

331-
<para>
332345
<indexterm>
333346
<primary>index</primary>
334347
<secondary>BRIN</secondary>
@@ -337,8 +350,12 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
337350
<primary>BRIN</primary>
338351
<see>index</see>
339352
</indexterm>
353+
354+
<para>
340355
BRIN indexes (a shorthand for Block Range INdexes) store summaries about
341356
the values stored in consecutive physical block ranges of a table.
357+
Thus, they are most effective for columns whose values are well-correlated
358+
with the physical order of the table rows.
342359
Like GiST, SP-GiST and GIN,
343360
BRIN can support many different indexing strategies,
344361
and the particular operators with which a BRIN index can be used
@@ -348,18 +365,15 @@ SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
348365
values in the column for each block range. This supports indexed queries
349366
using these operators:
350367

351-
<simplelist>
352-
<member><literal>&lt;</literal></member>
353-
<member><literal>&lt;=</literal></member>
354-
<member><literal>=</literal></member>
355-
<member><literal>&gt;=</literal></member>
356-
<member><literal>&gt;</literal></member>
357-
</simplelist>
368+
<synopsis>
369+
&lt; &nbsp; &lt;= &nbsp; = &nbsp; &gt;= &nbsp; &gt;
370+
</synopsis>
358371

359372
The BRIN operator classes included in the standard distribution are
360373
documented in <xref linkend="brin-builtin-opclasses-table"/>.
361374
For more information see <xref linkend="brin"/>.
362375
</para>
376+
</sect2>
363377
</sect1>
364378

365379

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp