summaryrefslogtreecommitdiff
path: root/doc/src/sgml/xoper.sgml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/sgml/xoper.sgml')
-rw-r--r--doc/src/sgml/xoper.sgml19
1 files changed, 18 insertions, 1 deletions
diff --git a/doc/src/sgml/xoper.sgml b/doc/src/sgml/xoper.sgml
index ab5f38be751..80e6793397e 100644
--- a/doc/src/sgml/xoper.sgml
+++ b/doc/src/sgml/xoper.sgml
@@ -1,5 +1,5 @@
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/xoper.sgml,v 1.26 2003/08/31 17:32:21 petere Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/xoper.sgml,v 1.27 2003/10/21 22:51:14 tgl Exp $
-->
<sect1 id="xoper">
@@ -121,6 +121,23 @@ SELECT (a + b) AS c FROM test_complex;
</para>
<para>
+ It's critical to provide commutator information for operators that
+ will be used in indexes and join clauses, because this allows the
+ query optimizer to <quote>flip around</> such a clause to the forms
+ needed for different plan types. For example, consider a query with
+ a WHERE clause like <literal>tab1.x = tab2.y</>, where <literal>tab1.x</>
+ and <literal>tab2.y</> are of a user-defined type, and suppose that
+ <literal>tab2.y</> is indexed. The optimizer cannot generate an
+ indexscan unless it can determine how to flip the clause around to
+ <literal>tab2.y = tab1.x</>, because the indexscan machinery expects
+ to see the indexed column on the left of the operator it is given.
+ <ProductName>PostgreSQL</ProductName> will <emphasis>not</> simply
+ assume that this is a valid transformation --- the definer of the
+ <literal>=</> operator must specify that it is valid, by marking the
+ operator with commutator information.
+ </para>
+
+ <para>
When you are defining a self-commutative operator, you just do it.
When you are defining a pair of commutative operators, things are
a little trickier: how can the first one to be defined refer to the