summaryrefslogtreecommitdiff
path: root/doc/src/sgml/ref/alter_opfamily.sgml
blob: 55b912611d94eada68880ed8fc4d2a0a783fdf6c (plain)
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
<!--
doc/src/sgml/ref/alter_opfamily.sgml
PostgreSQL documentation
-->

<refentry id="SQL-ALTEROPFAMILY">
 <indexterm zone="sql-alteropfamily">
  <primary>ALTER OPERATOR FAMILY</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>ALTER OPERATOR FAMILY</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>ALTER OPERATOR FAMILY</refname>
  <refpurpose>change the definition of an operator family</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> ADD
  {  OPERATOR <replaceable class="parameter">strategy_number</replaceable> <replaceable class="parameter">operator_name</replaceable> ( <replaceable class="parameter">op_type</replaceable>, <replaceable class="parameter">op_type</replaceable> ) [ FOR SEARCH | FOR ORDER BY <replaceable class="parameter">sort_family_name</replaceable> ]
   | FUNCTION <replaceable class="parameter">support_number</replaceable> [ ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) ] <replaceable class="parameter">function_name</replaceable> ( <replaceable class="parameter">argument_type</replaceable> [, ...] )
  } [, ... ]
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> DROP
  {  OPERATOR <replaceable class="parameter">strategy_number</replaceable> ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] )
   | FUNCTION <replaceable class="parameter">support_number</replaceable> ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] )
  } [, ... ]
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> OWNER TO <replaceable>new_owner</replaceable>
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> SET SCHEMA <replaceable>new_schema</replaceable>
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>ALTER OPERATOR FAMILY</command> changes the definition of
   an operator family.  You can add operators and support functions
   to the family, remove them from the family,
   or change the family's name or owner.
  </para>

  <para>
   When operators and support functions are added to a family with
   <command>ALTER OPERATOR FAMILY</command>, they are not part of any
   specific operator class within the family, but are just <quote>loose</>
   within the family.  This indicates that these operators and functions
   are compatible with the family's semantics, but are not required for
   correct functioning of any specific index.  (Operators and functions
   that are so required should be declared as part of an operator class,
   instead; see <xref linkend="sql-createopclass">.)
   <productname>PostgreSQL</productname> will allow loose members of a
   family to be dropped from the family at any time, but members of an
   operator class cannot be dropped without dropping the whole class and
   any indexes that depend on it.
   Typically, single-data-type operators
   and functions are part of operator classes because they are needed to
   support an index on that specific data type, while cross-data-type
   operators and functions are made loose members of the family.
  </para>

  <para>
   You must be a superuser to use <command>ALTER OPERATOR FAMILY</>.
   (This restriction is made because an erroneous operator family definition
   could confuse or even crash the server.)
  </para>

  <para>
   <command>ALTER OPERATOR FAMILY</command> does not presently check
   whether the operator family definition includes all the operators and
   functions required by the index method, nor whether the operators and
   functions form a self-consistent set.  It is the user's
   responsibility to define a valid operator family.
  </para>

  <para>
   Refer to <xref linkend="xindex"> for further information.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry>
    <term><replaceable class="parameter">name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of an existing operator
      family.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">index_method</replaceable></term>
    <listitem>
     <para>
      The name of the index method this operator family is for.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">strategy_number</replaceable></term>
    <listitem>
     <para>
      The index method's strategy number for an operator
      associated with the operator family.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">operator_name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of an operator associated
      with the operator family.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">op_type</replaceable></term>
    <listitem>
     <para>
      In an <literal>OPERATOR</> clause,
      the operand data type(s) of the operator, or <literal>NONE</> to
      signify a left-unary or right-unary operator.  Unlike the comparable
      syntax in <command>CREATE OPERATOR CLASS</>, the operand data types
      must always be specified.
     </para>

     <para>
      In an <literal>ADD FUNCTION</> clause, the operand data type(s) the
      function is intended to support, if different from
      the input data type(s) of the function.  For B-tree comparison functions
      and hash functions it is not necessary to specify <replaceable
      class="parameter">op_type</replaceable> since the function's input
      data type(s) are always the correct ones to use.  For B-tree sort
      support functions and all functions in GiST, SP-GiST and GIN operator
      classes, it is necessary to specify the operand data type(s) the function
      is to be used with.
     </para>

     <para>
      In a <literal>DROP FUNCTION</> clause, the operand data type(s) the
      function is intended to support must be specified.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">sort_family_name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of an existing <literal>btree</literal> operator
      family that describes the sort ordering associated with an ordering
      operator.
     </para>

     <para>
      If neither <literal>FOR SEARCH</> nor <literal>FOR ORDER BY</> is
      specified, <literal>FOR SEARCH</> is the default.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">support_number</replaceable></term>
    <listitem>
     <para>
      The index method's support procedure number for a
      function associated with the operator family.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">function_name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of a function that is an
      index method support procedure for the operator family.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">argument_type</replaceable></term>
    <listitem>
     <para>
      The parameter data type(s) of the function.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">new_name</replaceable></term>
    <listitem>
     <para>
      The new name of the operator family.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">new_owner</replaceable></term>
    <listitem>
     <para>
      The new owner of the operator family.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">new_schema</replaceable></term>
    <listitem>
     <para>
      The new schema for the operator family.
     </para>
    </listitem>
   </varlistentry>
 </variablelist>

  <para>
   The <literal>OPERATOR</> and <literal>FUNCTION</>
   clauses can appear in any order.
  </para>

 </refsect1>

 <refsect1>
  <title>Notes</title>

  <para>
   Notice that the <literal>DROP</> syntax only specifies the <quote>slot</>
   in the operator family, by strategy or support number and input data
   type(s).  The name of the operator or function occupying the slot is not
   mentioned.  Also, for <literal>DROP FUNCTION</> the type(s) to specify
   are the input data type(s) the function is intended to support; for
   GiST, SP-GiST and GIN indexes this might have nothing to do with the actual
   input argument types of the function.
  </para>

  <para>
   Because the index machinery does not check access permissions on functions
   before using them, including a function or operator in an operator family
   is tantamount to granting public execute permission on it.  This is usually
   not an issue for the sorts of functions that are useful in an operator
   family.
  </para>

  <para>
   The operators should not be defined by SQL functions.  A SQL function
   is likely to be inlined into the calling query, which will prevent
   the optimizer from recognizing that the query matches an index.
  </para>

  <para>
   Before <productname>PostgreSQL</productname> 8.4, the <literal>OPERATOR</>
   clause could include a <literal>RECHECK</> option.  This is no longer
   supported because whether an index operator is <quote>lossy</> is now
   determined on-the-fly at run time.  This allows efficient handling of
   cases where an operator might or might not be lossy.
  </para>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   The following example command adds cross-data-type operators and
   support functions to an operator family that already contains B-tree
   operator classes for data types <type>int4</> and <type>int2</>.
  </para>

<programlisting>
ALTER OPERATOR FAMILY integer_ops USING btree ADD

  -- int4 vs int2
  OPERATOR 1 &lt; (int4, int2) ,
  OPERATOR 2 &lt;= (int4, int2) ,
  OPERATOR 3 = (int4, int2) ,
  OPERATOR 4 &gt;= (int4, int2) ,
  OPERATOR 5 &gt; (int4, int2) ,
  FUNCTION 1 btint42cmp(int4, int2) ,

  -- int2 vs int4
  OPERATOR 1 &lt; (int2, int4) ,
  OPERATOR 2 &lt;= (int2, int4) ,
  OPERATOR 3 = (int2, int4) ,
  OPERATOR 4 &gt;= (int2, int4) ,
  OPERATOR 5 &gt; (int2, int4) ,
  FUNCTION 1 btint24cmp(int2, int4) ;
</programlisting>

  <para>
   To remove these entries again:
  </para>

<programlisting>
ALTER OPERATOR FAMILY integer_ops USING btree DROP

  -- int4 vs int2
  OPERATOR 1 (int4, int2) ,
  OPERATOR 2 (int4, int2) ,
  OPERATOR 3 (int4, int2) ,
  OPERATOR 4 (int4, int2) ,
  OPERATOR 5 (int4, int2) ,
  FUNCTION 1 (int4, int2) ,

  -- int2 vs int4
  OPERATOR 1 (int2, int4) ,
  OPERATOR 2 (int2, int4) ,
  OPERATOR 3 (int2, int4) ,
  OPERATOR 4 (int2, int4) ,
  OPERATOR 5 (int2, int4) ,
  FUNCTION 1 (int2, int4) ;
</programlisting>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   There is no <command>ALTER OPERATOR FAMILY</command> statement in
   the SQL standard.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-createopfamily"></member>
   <member><xref linkend="sql-dropopfamily"></member>
   <member><xref linkend="sql-createopclass"></member>
   <member><xref linkend="sql-alteropclass"></member>
   <member><xref linkend="sql-dropopclass"></member>
  </simplelist>
 </refsect1>
</refentry>