1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.11 2000/04/11 05:39:15 thomas Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.12 2000/04/23 02:08:33 tgl Exp $
3
3
Postgres documentation
4
4
-->
5
5
@@ -24,9 +24,9 @@ Postgres documentation
24
24
</refsynopsisdivinfo>
25
25
<synopsis>
26
26
CREATE [ UNIQUE ] INDEX <replaceable class="parameter">index_name</replaceable> ON <replaceable class="parameter">table</replaceable>
27
- [ USING <replaceable class="parameter">acc_name</replaceable> ] ( <replaceable class="parameter">column</replaceable> [ <replaceable class="parameter">ops_name</replaceable>] [, ...] )
27
+ [ USING <replaceable class="parameter">acc_name</replaceable> ] ( <replaceable class="parameter">column</replaceable> [ <replaceable class="parameter">ops_name</replaceable> ] [, ...] )
28
28
CREATE [ UNIQUE ] INDEX <replaceable class="parameter">index_name</replaceable> ON <replaceable class="parameter">table</replaceable>
29
- [ USING <replaceable class="parameter">acc_name</replaceable> ] ( <replaceable class="parameter">func_name</replaceable>( <replaceable class="parameter">col </replaceable> [, ... ]) <replaceable class="parameter">ops_name</replaceable> )
29
+ [ USING <replaceable class="parameter">acc_name</replaceable> ] ( <replaceable class="parameter">func_name</replaceable>( <replaceable class="parameter">column </replaceable> [, ... ]) [ <replaceable class="parameter">ops_name</replaceable> ] )
30
30
</synopsis>
31
31
32
32
<refsect2 id="R2-SQL-CREATEINDEX-1">
@@ -74,16 +74,16 @@ CREATE [ UNIQUE ] INDEX <replaceable class="parameter">index_name</replaceable>
74
74
<term><replaceable class="parameter">acc_name</replaceable></term>
75
75
<listitem>
76
76
<para>
77
- the name of the access method which is to be used for
77
+ The name of the access method to be used for
78
78
the index. The default access method is BTREE.
79
- Postgres provides three access methods for secondary indexes:
79
+ Postgres provides three access methods for indexes:
80
80
81
81
<variablelist>
82
82
<varlistentry>
83
83
<term>BTREE</term>
84
84
<listitem>
85
85
<para>
86
- an implementation of the Lehman-Yao
86
+ an implementation of Lehman-Yao
87
87
high-concurrency btrees.
88
88
</para>
89
89
</listitem>
@@ -133,8 +133,7 @@ CREATE [ UNIQUE ] INDEX <replaceable class="parameter">index_name</replaceable>
133
133
<term><replaceable class="parameter">func_name</replaceable></term>
134
134
<listitem>
135
135
<para>
136
- A user-defined function, which returns a value that can
137
- be indexed.
136
+ A function, which returns a value that can be indexed.
138
137
</para>
139
138
</listitem>
140
139
</varlistentry>
@@ -199,21 +198,15 @@ ERROR: Cannot create index: 'index_name' already exists.
199
198
</para>
200
199
201
200
<para>
202
- In the first syntax shown above, the key fields for the
203
- index are specified as column names; a column may also have
204
- an associated operator class. An operator class is used
205
- to specify the operators to be used for a particular
206
- index. For example, a btree index on four-byte integers
207
- would use the <literal>int4_ops</literal> class;
208
- this operator class includes
209
- comparison functions for four-byte integers. The default
210
- operator class is the appropriate operator class for that
211
- field type.
201
+ In the first syntax shown above, the key field(s) for the
202
+ index are specified as column names.
203
+ Multiple fields can be specified if the index access method supports
204
+ multi-column indexes.
212
205
</para>
213
206
214
207
<para>
215
208
In the second syntax shown above, an index is defined
216
- on the result of a user-defined function
209
+ on the result of a user-specified function
217
210
<replaceable class="parameter">func_name</replaceable> applied
218
211
to one or more attributes of a single class.
219
212
These <firstterm>functional indices</firstterm>
@@ -224,8 +217,8 @@ ERROR: Cannot create index: 'index_name' already exists.
224
217
225
218
<para>
226
219
Postgres provides btree, rtree and hash access methods for
227
- secondary indices. The btree access method is an implementation of
228
- the Lehman-Yao high-concurrency btrees. The rtree access method
220
+ indices. The btree access method is an implementation of
221
+ Lehman-Yao high-concurrency btrees. The rtree access method
229
222
implements standard rtrees using Guttman's quadratic split algorithm.
230
223
The hash access method is an implementation of Litwin's linear
231
224
hashing. We mention the algorithms used solely to indicate that all
@@ -243,8 +236,9 @@ ERROR: Cannot create index: 'index_name' already exists.
243
236
</title>
244
237
245
238
<para>
246
- The Postgres query optimizer will consider using btree indices in a scan
247
- whenever an indexed attribute is involved in a comparison using one of:
239
+ The <productname>Postgres</productname>
240
+ query optimizer will consider using a btree index whenever
241
+ an indexed attribute is involved in a comparison using one of:
248
242
249
243
<simplelist type="inline">
250
244
<member><</member>
@@ -255,19 +249,6 @@ ERROR: Cannot create index: 'index_name' already exists.
255
249
</simplelist>
256
250
</para>
257
251
258
- <para>
259
- Both box classes support indices on the <literal>box</literal> data
260
- type in <productname>Postgres</productname>.
261
- The difference between them is that <literal>bigbox_ops</literal>
262
- scales box coordinates down, to avoid floating point exceptions from
263
- doing multiplication, addition, and subtraction on very large
264
- floating-point coordinates. If the field on which your rectangles lie
265
- is about 20,000 units square or larger, you should use
266
- <literal>bigbox_ops</literal>.
267
- The <literal>poly_ops</literal> operator class supports rtree
268
- indices on <literal>polygon</literal> data.
269
- </para>
270
-
271
252
<para>
272
253
The <productname>Postgres</productname>
273
254
query optimizer will consider using an rtree index whenever
@@ -292,26 +273,56 @@ ERROR: Cannot create index: 'index_name' already exists.
292
273
</para>
293
274
294
275
<para>
295
- Currently, only the BTREE access method supports multi-column
296
- indexes. Up to 7 keys may be specified.
297
- </para>
298
-
299
- <para>
300
- Use <xref linkend="sql-dropindex-title" endterm="sql-dropindex-title">
301
- to remove an index.
276
+ Currently, only the btree access method supports multi-column
277
+ indexes. Up to 16 keys may be specified by default (this limit
278
+ can be altered when building Postgres).
302
279
</para>
303
280
304
- <para>
305
- The <literal>int24_ops</literal>
306
- operator class is useful for constructing indices on int2 data, and
307
- doing comparisons against int4 data in query qualifications.
308
- Similarly, <literal>int42_ops</literal>
309
- support indices on int4 data that is to be compared against int2 data
310
- in queries.
311
- </para>
281
+ <para>
282
+ An <firstterm>operator class</firstterm> can be specified for each
283
+ column of an index. The operator class identifies the operators to
284
+ be used by the index for that column. For example, a btree index on
285
+ four-byte integers would use the <literal>int4_ops</literal> class;
286
+ this operator class includes comparison functions for four-byte
287
+ integers. In practice the default operator class for the field's
288
+ datatype is usually sufficient. The main point of having operator classes
289
+ is that for some datatypes, there could be more than one meaningful
290
+ ordering. For example, we might want to sort a complex-number datatype
291
+ either by absolute value or by real part. We could do this by defining
292
+ two operator classes for the datatype and then selecting the proper
293
+ class when making an index. There are also some operator classes with
294
+ special purposes:
295
+
296
+ <itemizedlist>
297
+ <listitem>
298
+ <para>
299
+ The operator classes <literal>box_ops</literal> and
300
+ <literal>bigbox_ops</literal> both support rtree indices on the
301
+ <literal>box</literal> datatype.
302
+ The difference between them is that <literal>bigbox_ops</literal>
303
+ scales box coordinates down, to avoid floating point exceptions from
304
+ doing multiplication, addition, and subtraction on very large
305
+ floating-point coordinates. If the field on which your rectangles lie
306
+ is about 20,000 units square or larger, you should use
307
+ <literal>bigbox_ops</literal>.
308
+ </para>
309
+ </listitem>
310
+
311
+ <listitem>
312
+ <para>
313
+ The <literal>int24_ops</literal>
314
+ operator class is useful for constructing indices on int2 data, and
315
+ doing comparisons against int4 data in query qualifications.
316
+ Similarly, <literal>int42_ops</literal>
317
+ support indices on int4 data that is to be compared against int2 data
318
+ in queries.
319
+ </para>
320
+ </listitem>
321
+ </itemizedlist>
322
+ </para>
312
323
313
324
<para>
314
- The following select list returns all ops_names :
325
+ The following query shows all defined operator classes :
315
326
316
327
<programlisting>
317
328
SELECT am.amname AS acc_name,
@@ -328,6 +339,11 @@ SELECT am.amname AS acc_name,
328
339
</refsect2>
329
340
</refsect1>
330
341
342
+ <para>
343
+ Use <xref linkend="sql-dropindex-title" endterm="sql-dropindex-title">
344
+ to remove an index.
345
+ </para>
346
+
331
347
<refsect1 id="R1-SQL-CREATEINDEX-2">
332
348
<title>
333
349
Usage
0 commit comments