1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.41 2007/02/01 19:10:24 momjian Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.42 2007/02/06 04:38:31 tgl Exp $ -->
2
2
3
3
<sect1 id="xoper">
4
4
<title>User-Defined Operators</title>
@@ -85,7 +85,7 @@ SELECT (a + b) AS c FROM test_complex;
85
85
appropriate, because they can make for considerable speedups in execution
86
86
of queries that use the operator. But if you provide them, you must be
87
87
sure that they are right! Incorrect use of an optimization clause can
88
- result in server process crashes , subtly wrong output, or other Bad Things.
88
+ result in slow queries , subtly wrong output, or other Bad Things.
89
89
You can always leave out an optimization clause if you are not sure
90
90
about it; the only consequence is that queries might run slower than
91
91
they need to.
@@ -326,8 +326,8 @@ table1.column1 OP table2.column2
326
326
The <literal>HASHES</literal> clause, if present, tells the system that
327
327
it is permissible to use the hash join method for a join based on this
328
328
operator. <literal>HASHES</> only makes sense for a binary operator that
329
- returns <literal>boolean</>, and in practice the operator had better be
330
- equality for some data type.
329
+ returns <literal>boolean</>, and in practice the operator must represent
330
+ equality for some data type or pair of data types .
331
331
</para>
332
332
333
333
<para>
@@ -337,7 +337,13 @@ table1.column1 OP table2.column2
337
337
join will never compare them at all, implicitly assuming that the
338
338
result of the join operator must be false. So it never makes sense
339
339
to specify <literal>HASHES</literal> for operators that do not represent
340
- some form of equality.
340
+ some form of equality. In most cases it is only practical to support
341
+ hashing for operators that take the same data type on both sides.
342
+ However, sometimes it is possible to design compatible hash functions
343
+ for two or more datatypes; that is, functions that will generate the
344
+ same hash codes for <quote>equal</> values, even though the values
345
+ have different representations. For example, it's fairly simple
346
+ to arrange this property when hashing integers of different widths.
341
347
</para>
342
348
343
349
<para>
@@ -346,9 +352,9 @@ table1.column1 OP table2.column2
346
352
the operator, since of course the referencing operator family couldn't
347
353
exist yet. But attempts to use the operator in hash joins will fail
348
354
at run time if no such operator family exists. The system needs the
349
- operator family to find the data-type-specific hash function for the
350
- operator's input data type. Of course, you must also create a suitable
351
- hash function before you can create the operator family.
355
+ operator family to find the data-type-specific hash function(s) for the
356
+ operator's input data type(s) . Of course, you must also create suitable
357
+ hash functions before you can create the operator family.
352
358
</para>
353
359
354
360
<para>
@@ -366,6 +372,17 @@ table1.column1 OP table2.column2
366
372
to ensure it generates the same hash value as positive zero.
367
373
</para>
368
374
375
+ <para>
376
+ A hash-joinable operator must have a commutator (itself if the two
377
+ operand data types are the same, or a related equality operator
378
+ if they are different) that appears in the same operator family.
379
+ If this is not the case, planner errors might occur when the operator
380
+ is used. Also, it is a good idea (but not strictly required) for
381
+ a hash operator family that supports multiple datatypes to provide
382
+ equality operators for every combination of the datatypes; this
383
+ allows better optimization.
384
+ </para>
385
+
369
386
<note>
370
387
<para>
371
388
The function underlying a hash-joinable operator must be marked
0 commit comments