sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
btober@seaworthysys.com's Avatar

Is the COMMUTATOR clause required for self commutative operators?


Question posted by: btober@seaworthysys.com (Guest) on November 12th, 2005 01:03 AM
In the command

CREATE OPERATOR name (
PROCEDURE = func_name
[, LEFTARG = lefttype ] [, RIGHTARG = righttype ]
[, COMMUTATOR = com_op ] [, NEGATOR = neg_op ]
[, RESTRICT = res_proc ] [, JOIN = join_proc ]
[, HASHES ] [, MERGES ]
[, SORT1 = left_sort_op ] [, SORT2 = right_sort_op ]
[, LTCMP = less_than_op ] [, GTCMP = greater_than_op ]
)


Is omitting the COMMUTATOR option a problem at all in case of
self-commutative operators? That is, if I define

CREATE OPERATOR public.+(
PROCEDURE = numeric_add_null,
LEFTARG = numeric,
RIGHTARG = numeric,
COMMUTATOR = +)


(where numeric_add_null is a function that handles in NULLs in a
non-standard, but more useful way), since "+" is self commutative, is it
necessary to include it here? Any advantage or disadvantage to ommitting
or including it?

~Berend Tober




---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

2 Answers Posted
Peter Eisentraut's Avatar
Peter Eisentraut November 12th, 2005 01:03 AM
Guest - n/a Posts
#2: Re: Is the COMMUTATOR clause required for self commutative operators?

Join Bytes! wrote:[color=blue]
> In the command
>
> CREATE OPERATOR name (
> PROCEDURE = func_name
> [, LEFTARG = lefttype ] [, RIGHTARG = righttype ]
> [, COMMUTATOR = com_op ] [, NEGATOR = neg_op ]
> [, RESTRICT = res_proc ] [, JOIN = join_proc ]
> [, HASHES ] [, MERGES ]
> [, SORT1 = left_sort_op ] [, SORT2 = right_sort_op ]
> [, LTCMP = less_than_op ] [, GTCMP = greater_than_op ]
> )
>
>
> Is omitting the COMMUTATOR option a problem at all in case of
> self-commutative operators?[/color]

It's an optimization clause, so if you omit it then you prevent certain
optimizations. See
http://www.postgresql.org/docs/curr...n.html#AEN29826
for details.


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Tom Lane's Avatar
Guest - n/a Posts
#3: Re: Is the COMMUTATOR clause required for self commutative operators?

<btober@seaworthysys.com> writes:[color=blue]
> Is omitting the COMMUTATOR option a problem at all in case of
> self-commutative operators?[/color]

At the moment it only really matters for operators that are used in
top-level WHERE clauses --- which lets out anything that doesn't return
boolean. But I'd say that as a matter of style, if the operator is
self-commutative you should mark it so. Some day the system might
pay attention.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to Join Bytes! so that your
message can get through to the mailing list cleanly

 
Not the answer you were looking for? Post your question . . .
196,849 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,849 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors