11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.19 2001/05/17 21:50:18 petere Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.20 2001/07/16 05:06:57 tgl Exp $
33Postgres documentation
44-->
55
@@ -20,13 +20,15 @@ Postgres documentation
2020 </refnamediv>
2121 <refsynopsisdiv>
2222 <refsynopsisdivinfo>
23- <date>1999 -07-20 </date>
23+ <date>2001 -07-15 </date>
2424 </refsynopsisdivinfo>
2525 <synopsis>
2626CREATE [ 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_method</replaceable> ] ( <replaceable class="parameter">column</replaceable> [ <replaceable class="parameter">ops_name</replaceable> ] [, ...] )
28+ [ WHERE <replaceable class="parameter">predicate</replaceable> ]
2829CREATE [ 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">column</replaceable> [, ... ]) [ <replaceable class="parameter">ops_name</replaceable> ] )
30+ [ USING <replaceable class="parameter">acc_method</replaceable> ] ( <replaceable class="parameter">func_name</replaceable>( <replaceable class="parameter">column</replaceable> [, ... ]) [ <replaceable class="parameter">ops_name</replaceable> ] )
31+ [ WHERE <replaceable class="parameter">predicate</replaceable> ]
3032 </synopsis>
3133
3234 <refsect2 id="R2-SQL-CREATEINDEX-1">
@@ -71,12 +73,12 @@ CREATE [ UNIQUE ] INDEX <replaceable class="parameter">index_name</replaceable>
7173 </varlistentry>
7274
7375 <varlistentry>
74- <term><replaceable class="parameter">acc_name </replaceable></term>
76+ <term><replaceable class="parameter">acc_method </replaceable></term>
7577 <listitem>
7678 <para>
7779The name of the access method to be used for
7880the index. The default access method is BTREE.
79- Postgres providesthree access methods for indexes:
81+ Postgres providesfour access methods for indexes:
8082
8183<variablelist>
8284 <varlistentry>
@@ -106,6 +108,15 @@ CREATE [ UNIQUE ] INDEX <replaceable class="parameter">index_name</replaceable>
106108 </para>
107109 </listitem>
108110 </varlistentry>
111+
112+ <varlistentry>
113+ <term>GIST</term>
114+ <listitem>
115+ <para>
116+ Generalized Index Search Trees.
117+ </para>
118+ </listitem>
119+ </varlistentry>
109120</variablelist>
110121 </para>
111122 </listitem>
@@ -137,6 +148,15 @@ CREATE [ UNIQUE ] INDEX <replaceable class="parameter">index_name</replaceable>
137148 </para>
138149 </listitem>
139150 </varlistentry>
151+
152+ <varlistentry>
153+ <term><replaceable class="parameter">predicate</replaceable></term>
154+ <listitem>
155+ <para>
156+ Defines the constraint expression for a partial index.
157+ </para>
158+ </listitem>
159+ </varlistentry>
140160 </variablelist>
141161 </para>
142162 </refsect2>
@@ -216,7 +236,7 @@ ERROR: Cannot create index: 'index_name' already exists.
216236 </para>
217237
218238 <para>
219- Postgres provides btree, rtree andhash access methods for
239+ Postgres provides btree, rtree, hash, andGiST access methods for
220240 indexes. The btree access method is an implementation of
221241 Lehman-Yao high-concurrency btrees. The rtree access method
222242 implements standard rtrees using Guttman's quadratic split algorithm.
@@ -227,6 +247,32 @@ ERROR: Cannot create index: 'index_name' already exists.
227247 access methods).
228248 </para>
229249
250+ <para>
251+ When the <command>WHERE</command> clause is present, a
252+ <firstterm>partial index</firstterm> is created.
253+ A partial index is an index that contains entries for only a portion of
254+ a table, usually a portion that is somehow more interesting than the
255+ rest of the table. For example, if you have a table that contains both
256+ billed and unbilled orders where the unbilled orders take up a small
257+ fraction of the total table and yet that is an often used section, you
258+ can improve performance by creating an index on just that portion.
259+ </para>
260+
261+ <para>
262+ The expression used in the <command>WHERE</command> clause may refer
263+ only to columns of the underlying table (but it can use all columns,
264+ not only the one(s) being indexed). Currently, the
265+ <productname>PostgreSQL</productname> planner can only devise query
266+ plans that make use of a partial index when the predicate is built from
267+ <command>AND</command> and <command>OR</command> combinations of
268+ elements of the form
269+ <firstterm>column</firstterm>
270+ <firstterm>operator</firstterm>
271+ <firstterm>constant</firstterm>.
272+ However, more general predicates may still be useful in conjunction
273+ with UNIQUE indexes, to enforce uniqueness over a subset of a table.
274+ </para>
275+
230276 <para>
231277 Use <xref linkend="sql-dropindex" endterm="sql-dropindex-title">
232278 to remove an index.
@@ -278,9 +324,10 @@ ERROR: Cannot create index: 'index_name' already exists.
278324 </para>
279325
280326 <para>
281- Currently, only the btree accessmethod supports multi-column
327+ Currently, only the btreeand gist accessmethods support multi-column
282328 indexes. Up to 16 keys may be specified by default (this limit
283- can be altered when building Postgres).
329+ can be altered when building Postgres). Only btree currently supports
330+ unique indexes.
284331 </para>
285332
286333 <para>
@@ -307,9 +354,9 @@ ERROR: Cannot create index: 'index_name' already exists.
307354 The difference between them is that <literal>bigbox_ops</literal>
308355 scales box coordinates down, to avoid floating-point exceptions from
309356 doing multiplication, addition, and subtraction on very large
310- floating-point coordinates.If the field on which your rectangles lie
311- is about 20,000 units square or larger, you should use
312- <literal>bigbox_ops</literal>.
357+ floating-point coordinates.(Note: this was true some time ago,
358+ but currently the two operator classes both use floating point
359+ and are effectively identical.)
313360 </para>
314361 </listitem>
315362 </itemizedlist>
@@ -319,15 +366,15 @@ ERROR: Cannot create index: 'index_name' already exists.
319366 The following query shows all defined operator classes:
320367
321368 <programlisting>
322- SELECT am.amname ASacc_name ,
369+ SELECT am.amname ASacc_method ,
323370 opc.opcname AS ops_name,
324371 opr.oprname AS ops_comp
325372 FROM pg_am am, pg_amop amop,
326373 pg_opclass opc, pg_operator opr
327374 WHERE amop.amopid = am.oid AND
328375 amop.amopclaid = opc.oid AND
329376 amop.amopopr = opr.oid
330- ORDER BYacc_name , ops_name, ops_comp
377+ ORDER BYacc_method , ops_name, ops_comp
331378 </programlisting>
332379 </para>
333380 </refsect2>