11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_operator.sgml,v 1.25 2002/03/22 19:20:39 petere Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_operator.sgml,v 1.26 2002/04/16 23:08:10 tgl Exp $
33PostgreSQL documentation
44-->
55
@@ -28,7 +28,9 @@ CREATE OPERATOR <replaceable>name</replaceable> ( PROCEDURE = <replaceable class
2828 ] [, RIGHTARG = <replaceable class="parameter">righttype</replaceable> ]
2929 [, COMMUTATOR = <replaceable class="parameter">com_op</replaceable> ] [, NEGATOR = <replaceable class="parameter">neg_op</replaceable> ]
3030 [, RESTRICT = <replaceable class="parameter">res_proc</replaceable> ] [, JOIN = <replaceable class="parameter">join_proc</replaceable> ]
31- [, HASHES ] [, SORT1 = <replaceable class="parameter">left_sort_op</replaceable> ] [, SORT2 = <replaceable class="parameter">right_sort_op</replaceable> ] )
31+ [, HASHES ] [, MERGES ]
32+ [, SORT1 = <replaceable class="parameter">left_sort_op</replaceable> ] [, SORT2 = <replaceable class="parameter">right_sort_op</replaceable> ]
33+ [, LTCMP = <replaceable class="parameter">less_than_op</replaceable> ] [, GTCMP = <replaceable class="parameter">greater_than_op</replaceable> ] )
3234 </synopsis>
3335
3436 <refsect2 id="R2-SQL-CREATEOPERATOR-1">
@@ -115,11 +117,19 @@ CREATE OPERATOR <replaceable>name</replaceable> ( PROCEDURE = <replaceable class
115117 </para>
116118 </listitem>
117119 </varlistentry>
120+ <varlistentry>
121+ <term>MERGES</term>
122+ <listitem>
123+ <para>
124+ Indicates this operator can support a merge join.
125+ </para>
126+ </listitem>
127+ </varlistentry>
118128 <varlistentry>
119129 <term><replaceable class="parameter">left_sort_op</replaceable></term>
120130 <listitem>
121131 <para>
122- If this operator can support a merge join, the
132+ If this operator can support a merge join, the less-than
123133operator that sorts the left-hand data type of this operator.
124134 </para>
125135 </listitem>
@@ -128,11 +138,29 @@ CREATE OPERATOR <replaceable>name</replaceable> ( PROCEDURE = <replaceable class
128138 <term><replaceable class="parameter">right_sort_op</replaceable></term>
129139 <listitem>
130140 <para>
131- If this operator can support a merge join, the
141+ If this operator can support a merge join, the less-than
132142operator that sorts the right-hand data type of this operator.
133143 </para>
134144 </listitem>
135145 </varlistentry>
146+ <varlistentry>
147+ <term><replaceable class="parameter">less_than_op</replaceable></term>
148+ <listitem>
149+ <para>
150+ If this operator can support a merge join, the less-than
151+ operator that compares the input data types of this operator.
152+ </para>
153+ </listitem>
154+ </varlistentry>
155+ <varlistentry>
156+ <term><replaceable class="parameter">greater_than_op</replaceable></term>
157+ <listitem>
158+ <para>
159+ If this operator can support a merge join, the greater-than
160+ operator that compares the input data types of this operator.
161+ </para>
162+ </listitem>
163+ </varlistentry>
136164 </variablelist>
137165 </para>
138166 </refsect2>
@@ -295,30 +323,39 @@ MYBOXES.description !== box '((0,0), (1,1))'
295323 it also works to just have both operators refer to each other.)
296324 </para>
297325 <para>
298- The HASHES, SORT1, and SORT2 options are present to support the
299- query optimizer in performing joins.
300- <productname>PostgreSQL</productname> can always
301- evaluate a join (i.e., processing a clause with two tuple
302- variables separated by an operator that returns a <type>boolean</type>)
303- by iterative substitution [WONG76].
304- In addition, <productname>PostgreSQL</productname>
305- can use a hash-join algorithm along
306- the lines of [SHAP86]; however, it must know whether this
307- strategy is applicable. The current hash-join algorithm
308- is only correct for operators that represent equality tests;
309- furthermore, equality of the data type must mean bitwise equality
310- of the representation of the type. (For example, a data type that
311- contains unused bits that don't matter for equality tests could
312- not be hash-joined.)
313- The HASHES flag indicates to the query optimizer that a hash join
314- may safely be used with this operator.</para>
326+ The HASHES, MERGES, SORT1, SORT2, LTCMP, and GTCMP options are present to
327+ support the query optimizer in performing joins.
328+ <productname>PostgreSQL</productname> can always evaluate a join (i.e.,
329+ processing a clause with two tuple variables separated by an operator that
330+ returns a <type>boolean</type>) by iterative substitution [WONG76]. In
331+ addition, <productname>PostgreSQL</productname> can use a hash-join
332+ algorithm along the lines of [SHAP86]; however, it must know whether this
333+ strategy is applicable. The current hash-join algorithm is only correct
334+ for operators that represent equality tests; furthermore, equality of the
335+ data type must mean bitwise equality of the representation of the type.
336+ (For example, a data type that contains unused bits that don't matter for
337+ equality tests could not be hash-joined.) The HASHES flag indicates to the
338+ query optimizer that a hash join may safely be used with this
339+ operator.
340+ </para>
315341 <para>
316- Similarly, the two sort operators indicate to the query
317- optimizer whether merge-sort is a usable join strategy and
318- which operators should be used to sort the two operand
319- classes. Sort operators should only be provided for an equality
320- operator, and they should refer to less-than operators for the
321- left and right side data types respectively.
342+ Similarly, the MERGES flag indicates whether merge-sort is a usable join
343+ strategy for this operator. A merge join requires that the two input
344+ datatypes have consistent orderings, and that the mergejoin operator
345+ behave like equality with respect to that ordering. For example, it is
346+ possible to merge-join equality between an integer and a float variable by
347+ sorting both inputs in ordinary
348+ numeric order. Execution of a merge join requires that the system be
349+ able to identify four operators related to the mergejoin equality operator:
350+ less-than comparison for the left input datatype,
351+ less-than comparison for the right input datatype,
352+ less-than comparison between the two datatypes, and
353+ greater-than comparison between the two datatypes. It is possible to
354+ specify these by name, as the SORT1, SORT2, LTCMP, and GTCMP options
355+ respectively. The system will fill in the default names <literal><</>,
356+ <literal><</>, <literal><</>, <literal>></> respectively if
357+ any of these are omitted when MERGES is specified. Also, MERGES will
358+ be assumed to be implied if any of these four operator options appear.
322359 </para>
323360 <para>
324361 If other join strategies are found to be practical,
@@ -408,8 +445,10 @@ CREATE OPERATOR === (
408445 RESTRICT = area_restriction_procedure,
409446 JOIN = area_join_procedure,
410447 HASHES,
411- SORT1 = <<<,
412- SORT2 = <<<
448+ SORT1 = <<<,
449+ SORT2 = <<<
450+ -- Since sort operators were given, MERGES is implied.
451+ -- LTCMP and GTCMP are assumed to be < and > respectively
413452);
414453 </programlisting>
415454 </refsect1>