File: create_index.l.html

package info (click to toggle)
mpsql 2.0-2
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 2,912 kB
  • ctags: 5,665
  • sloc: ansic: 34,322; makefile: 3,525; sh: 17
file content (369 lines) | stat: -rw-r--r-- 12,873 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!-- manual page source format generated by PolyglotMan v3.0.4, -->
<!-- available via anonymous ftp from ftp.cs.berkeley.edu:/ucb/people/phelps/tcltk/rman.tar.Z -->

<HTML>
<HEAD>
<TITLE>"CREATE(INDEX") manual page</TITLE>
</HEAD>
<BODY>
<A HREF="sql.html">SQL Reference Contents</A>
 
<H2><A NAME="sect0" HREF="#toc0">NAME </A></H2>
create index - construct a secondary index  
<H2><A NAME="sect1" HREF="#toc1">SYNOPSIS </A></H2>
<B>create </B> [<B>unique 
</B>] <B>index </B> index-name <BR>
 <tt> </tt><tt> </tt><B>on </B> classname [<B>using </B> am-name] <BR>
 <tt> </tt><tt> </tt><B>( </B> attname [type_class], 
...<B> ) </B> <BR>
 <P>
 <B>create </B> [<B>unique </B>] <B>index </B> index-name <BR>
 <tt> </tt><tt> </tt><B>on </B> classname [<B>using </B> am-name] 
<BR>
 <tt> </tt><tt> </tt><B>( </B> funcname <B>( </B> attname-1 { , attname-i } <B>) </B> type_class <B>) </B> <BR>
  
<H2><A NAME="sect2" HREF="#toc2">DESCRIPTION 
</A></H2>
This command constructs an index called <I>index-name.</I> <P>
<I>Am-name</I> is the name of 
the access method which is used for the index. The default access method 
is btree. <P>
In the first syntax shown above, the key fields for the index 
are specified as attribute names.  It may also have an associated <I>operator 
class</I>. An operator class is used to specify the operators to be used for 
a particular index. For example, a btree index on four-byte integers would 
use the <I>int4_ops</I> class; this operator class includes comparison functions 
for four-byte integers. The default operator class is the appropriate operator 
class for that field type. <P>
<B>Note: </B> currently, only  <I>btree</I> access method 
supports multi-attribute indices. Up to 7 keys may be specified. <P>
In the second 
syntax shown above, an index can be defined on the result of a user-defined 
function <I>funcname</I> applied to one or more attributes of a single class. 
 These <I>functional indices</I> can be used to obtain fast access to data based 
on operators that would normally require some transformation to be applied 
to the base data.  For example, say you have an attribute in class `myclass' 
called `pt' that consists of a 2D point type.  Now, suppose that you would 
like to index this attribute but you only have index operator classes 
for 2D polygon types.  You can define an index on the point attribute using 
a function that you write (call it `point_to_polygon') and your existing 
polygon operator class; after that, queries using existing polygon operators 
that reference `point_to_polygon(myclass.pt)' on one side will use the precomputed 
polygons stored in the functional index instead of computing a polygon 
for each and every instance in `myclass' and then comparing it to the value 
on the other side of the operator. Obviously, the decision to build a functional 
index represents a tradeoff between space (for the index) and execution 
time. <P>
The <B>unique </B> keyword causes the system to check for duplicate values 
when the index is created (if data already exist) and each time data is 
added. Attempts to insert or update non-duplicate data will generate an 
error. <P>
Postgres provides btree, rtree and hash access methods for secondary 
indices.  The btree access method is an implementation of the Lehman-Yao 
high-concurrency btrees.  The rtree access method implements standard rtrees 
using Guttman's quadratic split algorithm. The hash access method is an 
implementation of Litwin's linear hashing.  We mention the algorithms used 
solely to indicate that all of these access methods are fully dynamic 
and do not have to be optimized periodically (as is the case with, for 
example, static hash access methods). <P>
This list was generated from the 
Postgres system catalogs with the query: <P>
 SELECT am.amname AS acc_name, 
<BR>
        opc.opcname AS ops_name, <BR>
        opr.oprname AS ops_comp <BR>
 FROM  
 pg_am am, pg_amop amop, pg_opclass opc, pg_operator opr <BR>
 WHERE  amop.amopid 
= am.oid AND <BR>
        amop.amopclaid = opc.oid AND <BR>
        amop.amopopr = opr.oid 
<BR>
 ORDER BY acc_name, ops_name, ops_comp; <BR>
 <P>
 acc_name|ops_name   |ops_comp 
<BR>
 --------+-----------+-------- <BR>
 btree   |abstime_ops|&lt;        <BR>
 btree   |abstime_ops|&lt;=       <BR>
 btree   |abstime_ops|= 
       <BR>
 btree   |abstime_ops|&gt;        <BR>
 btree   |abstime_ops|&gt;=       <BR>
 btree 
  |bpchar_ops |&lt;        <BR>
 btree   |bpchar_ops |&lt;=       <BR>
 btree   |bpchar_ops |= 
       <BR>
 btree   |bpchar_ops |&gt;        <BR>
 btree   |bpchar_ops |&gt;=       <BR>
 btree 
  |char16_ops |&lt;        <BR>
 btree   |char16_ops |&lt;=       <BR>
 btree   |char16_ops |= 
       <BR>
 btree   |char16_ops |&gt;        <BR>
 btree   |char16_ops |&gt;=       <BR>
 btree 
  |char2_ops  |&lt;        <BR>
 btree   |char2_ops  |&lt;=       <BR>
 btree   |char2_ops  |= 
       <BR>
 btree   |char2_ops  |&gt;        <BR>
 btree   |char2_ops  |&gt;=       <BR>
 btree 
  |char4_ops  |&lt;        <BR>
 btree   |char4_ops  |&lt;=       <BR>
 btree   |char4_ops  |= 
       <BR>
 btree   |char4_ops  |&gt;        <BR>
 btree   |char4_ops  |&gt;=       <BR>
 btree 
  |char8_ops  |&lt;        <BR>
 btree   |char8_ops  |&lt;=       <BR>
 btree   |char8_ops  |= 
       <BR>
 btree   |char8_ops  |&gt;        <BR>
 btree   |char8_ops  |&gt;=       <BR>
 btree 
  |char_ops   |&lt;        <BR>
 btree   |char_ops   |&lt;=       <BR>
 btree   |char_ops   |= 
       <BR>
 btree   |char_ops   |&gt;        <BR>
 btree   |char_ops   |&gt;=       <BR>
 btree 
  |date_ops   |&lt;        <BR>
 btree   |date_ops   |&lt;=       <BR>
 btree   |date_ops   |= 
       <BR>
 btree   |date_ops   |&gt;        <BR>
 btree   |date_ops   |&gt;=       <BR>
 btree 
  |float4_ops |&lt;        <BR>
 btree   |float4_ops |&lt;=       <BR>
 btree   |float4_ops |= 
       <BR>
 btree   |float4_ops |&gt;        <BR>
 btree   |float4_ops |&gt;=       <BR>
 btree 
  |float8_ops |&lt;        <BR>
 btree   |float8_ops |&lt;=       <BR>
 btree   |float8_ops |= 
       <BR>
 btree   |float8_ops |&gt;        <BR>
 btree   |float8_ops |&gt;=       <BR>
 btree 
  |int24_ops  |&lt;        <BR>
 btree   |int24_ops  |&lt;=       <BR>
 btree   |int24_ops  |= 
       <BR>
 btree   |int24_ops  |&gt;        <BR>
 btree   |int24_ops  |&gt;=       <BR>
 btree 
  |int2_ops   |&lt;        <BR>
 btree   |int2_ops   |&lt;=       <BR>
 btree   |int2_ops   |= 
       <BR>
 btree   |int2_ops   |&gt;        <BR>
 btree   |int2_ops   |&gt;=       <BR>
 btree 
  |int42_ops  |&lt;        <BR>
 btree   |int42_ops  |&lt;=       <BR>
 btree   |int42_ops  |= 
       <BR>
 btree   |int42_ops  |&gt;        <BR>
 btree   |int42_ops  |&gt;=       <BR>
 btree 
  |int4_ops   |&lt;        <BR>
 btree   |int4_ops   |&lt;=       <BR>
 btree   |int4_ops   |= 
       <BR>
 btree   |int4_ops   |&gt;        <BR>
 btree   |int4_ops   |&gt;=       <BR>
 btree 
  |name_ops   |&lt;        <BR>
 btree   |name_ops   |&lt;=       <BR>
 btree   |name_ops   |= 
       <BR>
 btree   |name_ops   |&gt;        <BR>
 btree   |name_ops   |&gt;=       <BR>
 btree 
  |oid_ops    |&lt;        <BR>
 btree   |oid_ops    |&lt;=       <BR>
 btree   |oid_ops    |= 
       <BR>
 btree   |oid_ops    |&gt;        <BR>
 btree   |oid_ops    |&gt;=       <BR>
 btree 
  |oidint2_ops|&lt;        <BR>
 btree   |oidint2_ops|&lt;=       <BR>
 btree   |oidint2_ops|= 
       <BR>
 btree   |oidint2_ops|&gt;        <BR>
 btree   |oidint2_ops|&gt;=       <BR>
 btree 
  |oidint4_ops|&lt;        <BR>
 btree   |oidint4_ops|&lt;=       <BR>
 btree   |oidint4_ops|= 
       <BR>
 btree   |oidint4_ops|&gt;        <BR>
 btree   |oidint4_ops|&gt;=       <BR>
 btree 
  |oidname_ops|&lt;        <BR>
 btree   |oidname_ops|&lt;=       <BR>
 btree   |oidname_ops|= 
       <BR>
 btree   |oidname_ops|&gt;        <BR>
 btree   |oidname_ops|&gt;=       <BR>
 btree 
  |text_ops   |&lt;        <BR>
 btree   |text_ops   |&lt;=       <BR>
 btree   |text_ops   |= 
       <BR>
 btree   |text_ops   |&gt;        <BR>
 btree   |text_ops   |&gt;=       <BR>
 btree 
  |time_ops   |&lt;        <BR>
 btree   |time_ops   |&lt;=       <BR>
 btree   |time_ops   |= 
       <BR>
 btree   |time_ops   |&gt;        <BR>
 btree   |time_ops   |&gt;=       <BR>
 btree 
  |varchar_ops|&lt;        <BR>
 btree   |varchar_ops|&lt;=       <BR>
 btree   |varchar_ops|= 
       <BR>
 btree   |varchar_ops|&gt;        <BR>
 btree   |varchar_ops|&gt;=       <BR>
 hash  
  |bpchar_ops |=        <BR>
 hash    |char16_ops |=        <BR>
 hash    |char2_ops 
 |=        <BR>
 hash    |char4_ops  |=        <BR>
 hash    |char8_ops  |=        <BR>
 hash 
   |char_ops   |=        <BR>
 hash    |date_ops   |=        <BR>
 hash    |float4_ops 
|=        <BR>
 hash    |float8_ops |=        <BR>
 hash    |int2_ops   |=        <BR>
 hash 
   |int4_ops   |=        <BR>
 hash    |name_ops   |=        <BR>
 hash    |oid_ops  
  |=        <BR>
 hash    |text_ops   |=        <BR>
 hash    |time_ops   |=        <BR>
 
hash    |varchar_ops|=        <BR>
 rtree   |bigbox_ops |&amp;&amp;       <BR>
 rtree   |bigbox_ops 
|&amp;&lt;       <BR>
 rtree   |bigbox_ops |&amp;&gt;       <BR>
 rtree   |bigbox_ops |&lt;&lt;       <BR>
 rtree   
|bigbox_ops |&gt;&gt;       <BR>
 rtree   |bigbox_ops |@        <BR>
 rtree   |bigbox_ops |~  
      <BR>
 rtree   |bigbox_ops |~=       <BR>
 rtree   |box_ops    |&amp;&amp;       <BR>
 rtree  
 |box_ops    |&amp;&lt;       <BR>
 rtree   |box_ops    |&amp;&gt;       <BR>
 rtree   |box_ops    |&lt;&lt;    
   <BR>
 rtree   |box_ops    |&gt;&gt;       <BR>
 rtree   |box_ops    |@        <BR>
 rtree   |box_ops 
   |~        <BR>
 rtree   |box_ops    |~=       <BR>
 rtree   |poly_ops   |&amp;&amp;       <BR>
 rtree 
  |poly_ops   |&amp;&lt;       <BR>
 rtree   |poly_ops   |&amp;&gt;       <BR>
 rtree   |poly_ops   |&lt;&lt;   
    <BR>
 rtree   |poly_ops   |&gt;&gt;       <BR>
 rtree   |poly_ops   |@        <BR>
 rtree   |poly_ops 
  |~        <BR>
 rtree   |poly_ops   |~=       <BR>
 <P>
 The <I>int24_ops</I> operator class 
is useful for constructing indices on int2 data, and doing comparisons 
against int4 data in query qualifications. Similarly, <I>int42_ops</I> support 
indices on int4 data that is to be compared against int2 data in queries. 
<P>
The operator classes <I>oidint2_ops</I>, <I>oidint4_ops</I>, and <I>oidchar16_ops</I> represent 
the use of  <I>functional indices</I> to simulate multi-key indices. These are 
no longer needed now that multi-key indexes are supported. <P>
The Postgres 
query optimizer will consider using btree indices in a scan whenever an 
indexed attribute is involved in a comparison using one of: <P>
 &lt;    &lt;=    
=    &gt;=    &gt; <BR>
 <P>
 Both box classes support indices on the `box' datatype in Postgres. 
 The difference between them is that <I>bigbox_ops</I> scales box coordinates 
down, to avoid floating point exceptions from doing multiplication, addition, 
and subtraction on very large floating-point coordinates.  If the field 
on which your rectangles lie is about 20,000 units square or larger, you 
should use <I>bigbox_ops</I>. The <I>poly_ops</I> operator class supports rtree indices 
on `polygon' data. <P>
The Postgres query optimizer will consider using an rtree 
index whenever an indexed attribute is involved in a comparison using 
one of: <P>
 &lt;&lt;    &amp;&lt;    &amp;&gt;    &gt;&gt;    @    ~=    &amp;&amp; <BR>
 <P>
 The Postgres query optimizer will 
consider using a hash index whenever an indexed attribute is involved 
in a comparison using the <B>= </B> operator.  
<H2><A NAME="sect3" HREF="#toc3">EXAMPLES </A></H2>
-- <BR>
 --Create a btree index 
on the emp class using the age attribute. <BR>
 -- <BR>
 create index empindex on emp 
using btree (age int4_ops) <BR>
 -- <BR>
 --Create a btree index on employee name. <BR>
 -- 
<BR>
 create index empname <BR>
 <tt> </tt><tt> </tt>on emp using btree (name char16_ops) <BR>
 -- <BR>
 --Create 
an rtree index on the bounding rectangle of cities. <BR>
 -- <BR>
 create index cityrect 
<BR>
 <tt> </tt><tt> </tt>on city using rtree (boundbox box_ops) <BR>
 -- <BR>
 --Create a rtree index on a point 
attribute such that we <BR>
 --can efficiently use box operators on the result 
of the  <BR>
 --conversion function.  Such a qualification might look  <BR>
 --like "where 
point2box(points.pointloc) = boxes.box". <BR>
 -- <BR>
 create index pointloc <BR>
 <tt> </tt><tt> </tt>on points 
using rtree (<A HREF="point2box.location.html">point2box(location)</A>
 box_ops) <BR>
 <P>

<HR><P>
<A NAME="toc"><B>Table of Contents</B></A><P>
<UL>
<LI><A NAME="toc0" HREF="#sect0">NAME</A></LI>
<LI><A NAME="toc1" HREF="#sect1">SYNOPSIS</A></LI>
<LI><A NAME="toc2" HREF="#sect2">DESCRIPTION</A></LI>
<LI><A NAME="toc3" HREF="#sect3">EXAMPLES</A></LI>
</UL>
</BODY></HTML>