head 1.10; access; symbols; locks; strict; comment @# @; 1.10 date 92.07.14.05.54.17; author ptong; state Exp; branches; next 1.9; 1.9 date 92.07.13.03.45.59; author ptong; state Exp; branches; next 1.8; 1.8 date 91.12.02.04.02.08; author kemnitz; state Exp; branches; next 1.7; 1.7 date 91.08.23.13.21.08; author kemnitz; state Exp; branches; next 1.6; 1.6 date 91.02.25.15.17.32; author mike; state Exp; branches; next 1.5; 1.5 date 91.01.28.23.04.58; author mao; state Exp; branches; next 1.4; 1.4 date 90.08.02.16.16.33; author choi; state Exp; branches; next 1.3; 1.3 date 90.07.21.18.17.23; author kemnitz; state Exp; branches; next 1.2; 1.2 date 90.07.21.18.14.18; author kemnitz; state Exp; branches; next 1.1; 1.1 date 90.07.18.16.22.03; author mao; state Exp; branches; next ; desc @man page for the defineoperator postquel command @ 1.10 log @reformated @ text @.\" XXX standard disclaimer belongs here.... .\" $Header: /home/postgres/mer/refs/postquel/RCS/defineoperator,v 1.9 1992/07/13 03:45:59 ptong Exp ptong $ .SP "DEFINE OPERATOR" COMMANDS 6/14/90 .XA 2 "Define Operator" .uh NAME .lp define operator \*- define a new user operator .uh SYNOPSIS .lp .(l \fBdefine operator\fR operator_name \fB(\fR \fBarg1\fR \fB=\fR type-1 [ \fB,\fR \fBarg2\fR \fB=\fR type-2 ] , \fBprocedure =\fR func_name [\fB, precedence =\fR number ] [\fB, associativity =\fR \fB(left | right | none | any)\fR ] [\fB, commutator =\fR com_op ] [\fB, negator =\fR neg_op ] [\fB, restrict =\fR res_proc ] [\fB, hashes\fR] [\fB, join =\fR join_proc ] [\fB, sort =\fR sor_op1 {\fB,\fR sor_op2 } ] \fB)\fR .\" \fB"arg is (" .\" type [ .\" \fB, .\" type ] .\" \fB) .)l .uh DESCRIPTION .lp This command defines a new user operator, .i "operator_name" . The user who defines an operator becomes its owner. .lp The name of the operator, .i operator_name , can be composed of symbols only. Also, the .i func_name procedure must have been previously defined using .b "define function" and must have one or two arguments. The types of the arguments for the operator and the type of the answer are as defined by the function. .b Precedence refers to the order that multiple instances of the same operator are evaluated. .\" what does this number mean and what is its range? The next several fields are primarily for the use of the query optimizer. .lp The .b associativity value is used to indicate how an expression containing this operator should be evaluated when precedence and explicit grouping are insufficient to produce a complete order of evaluation. .b Left and .b right indicate that expressions containing the operator are to be evaluated from left to right or from right to left, respectively. .b None means that it is an error for this operator to be used without explicit grouping when there is ambiguity. And .b any , the default, indicates that the optimizer may choose to evaluate an expression which contains this operator arbitrarily. .lp .\" that multiple instances of the .\" operator must be be evaluated .\" For example, consider the area-intersection operator, .\" .q A, .\" and the following expression: .\" .(l .\" MYBOXES2.description A \*(lq0,0,1,1\*(rq A MYBOXES.description .\" .)l .\" .in .5i .\" The associativity flag indicates that .\" .(l .\" (MYBOXES2.description A \*(lq0,0,1,1\*(rq) A MYBOXES.description .\" .)l .\" .in .5i .\" is the same as .\" .(l .\" MYBOXES2.description A (\*(lq0,0,1,1\*(rq A MYBOXES.description). .\" .)l The commutator operator is present so that \*(PP can reverse the order of the operands if it wishes. For example, the operator area-less-than, >>>, would have a commutator operator, area-greater-than, <<<. Suppose that an operator, area-equal, ===, exists, as well as an area not equal, !==. Hence, the query optimizer could freely convert: .(l .ft C "0,0,1,1"::box >>> MYBOXES.description .ft .)l .in .5i to .(l .ft C MYBOXES.description <<< "0,0,1,1"::box .ft .)l .in .5i This allows the execution code to always use the latter representation and simplifies the query optimizer somewhat. .sp The negator operator allows the query optimizer to convert .(l .ft C not MYBOXES.description === "0,0,1,1"::box .ft .)l .in .5i to .(l .ft C MYBOXES.description !== "0,0,1,1"::box .ft .)l .in .5i .sp If a commutator operator name is supplied, \*(PP searches for it in the catalog. If it is found and it does not yet have a commutator itself, then the commutator's entry is updated to have the current (new) operator as its commutator. This applies to the negator, as well. .sp This is to allow the definition of two operators that are the commutators or the negators of each other. The first operator should be defined without a commutator or negator (as appropriate). When the second operator is defined, name the first as the commutator or negator. The first will be updated as a side effect. .sp The next two specifications are present to support the query optimizer in performing joins. \*(PP can always evaluate a join (i.e., processing a clause with two tuple variables separated by an operator that returns a boolean) by iterative substitution [WONG76]. In addition, \*(PP is planning on implementing a hash-join algorithm along the lines of [SHAP86]; however, it must know whether this strategy is applicable. For example, a hash-join algorithm is usable for a clause of the form: .(l .ft C MYBOXES.description === MYBOXES2.description .ft .)l .in .5i but not for a clause of the form: .(l .ft C MYBOXES.description <<< MYBOXES2.description. .ft .)l .in .5i The .i hashes flag gives the needed information to the query optimizer concerning whether a hash join strategy is usable for the operator in question. .sp Similarly, the two sort operators indicate to the query optimizer whether merge-sort is a usable join strategy and what operators should be used to sort the two operand classes. For the === clause above, the optimizer must sort both relations using the operator, <<<. On the other hand, merge-sort is not usable with the clause: .(l .ft C MYBOXES.description <<< MYBOXES2.description .ft .)l If other join strategies are found to be practical, \*(PP will change the optimizer and run-time system to use them and will require additional specification when an operator is defined. Fortunately, the research community invents new join strategies infrequently, and the added generality of user-defined join strategies was not felt to be worth the complexity involved. .lp The last two pieces of the specification are present so the query optimizer can estimate result sizes. If a clause of the form: .(l .ft C MYBOXES.description <<< "0,0,1,1"::box .ft .)l .in .5i is present in the qualification, then \*(PP may have to estimate the fraction of the instances in MYBOXES that satisfy the clause. The function res_proc must be a registered function (meaning it is already defined using .b "define function" ) which accepts one argument of the correct data type and returns a floating point number. The query optimizer simply calls this function, passing the parameter .ft C "0,0,1,1" .ft and multiplies the result by the relation size to get the desired expected number of instances. .sp Similarly, when the operands of the operator both contain instance variables, the query optimizer must estimate the size of the resulting join. The function join_proc will return another floating point number which will be multiplied by the cardinalities of the two classes involved to compute the desired expected result size. .sp The difference between the function .(l .ft C my_procedure_1 (MYBOXES.description, "0,0,1,1"::box) .ft .)l .in .5i and the operator .(l .ft C MYBOXES.description === "0,0,1,1"::box .ft .)l .in .5i is that \*(PP attempts to optimize operators and can decide to use an index to restrict the search space when operators are involved. However, there is no attempt to optimize functions, and they are performed by brute force. Moreover, functions can have any number of arguments while operators are restricted to one or two. .sp .(b .uh EXAMPLE .lp .nf .ft C /* The following command defines a new operator, */ /* area-equality, for the BOX data type. */ define operator === ( arg1 = box, arg2 = box, procedure = area_equal_procedure, precedence = 30, associativity = left, commutator = ===, negator = !==, restrict = area_restriction_procedure, hashes, join = area-join-procedure, sort = <<<, <<<) .\" arg is (box, box) .ft .)b .uh "SEE ALSO" .lp remove operator(commands), define function(commands). .uh BUGS .lp Operator names cannot be composed of alphabetic characters in Version \*(PV. .lp Operator precedence and associativity are not implemented in Version \*(PV. @ 1.9 log @Fixed up formating @ text @d2 1 a2 1 .\" $Header: /home/postgres/mer/refs/postquel/RCS/defineoperator,v 1.8 1991/12/02 04:02:08 kemnitz Exp ptong $ d254 2 a255 2 /* The following command defines a new operator, area-equality, for the BOX data type. */ @ 1.8 log @*** empty log message *** @ text @d2 1 a2 1 .\" $Header: RCS/defineoperator,v 1.7 91/08/23 13:21:08 kemnitz Exp Locker: kemnitz $ d10 15 a24 37 .b "define operator" operator_name .b "( arg1 =" type-1 .b "[, arg2 =" type-2 ] .b " procedure =" func_name [ .b ", precedence =" number ] [ .b ", associativity =" ( .b left | .b right | .b none | .b any ) ] [ .b ", commutator =" com_op ] [ .b ", negator =" neg_op ] [ .b ", restrict =" res_proc ] [ .b ", hashes" ] [ .b ", join =" join_proc ] [ .b ", sort =" sor_op1 { .b , sor_op2 } ] .b ) .\" .b "arg is (" d26 1 a26 1 .\" .b , d28 2 a29 1 .\" .b ) d102 3 a104 1 \*(lq0,0,1,1\*(rq::box >>> MYBOXES.description d109 3 a111 1 MYBOXES.description <<< \*(lq0,0,1,1\*(rq::box d119 3 a121 1 not MYBOXES.description === \*(lq0,0,1,1\*(rq::box d126 3 a128 1 MYBOXES.description !== \*(lq0,0,1,1\*(rq::box d133 1 a133 1 POSTGRES searches for it in the catalog. d159 1 d161 1 d166 1 d168 1 d186 1 d188 1 d202 3 a204 1 MYBOXES.description <<< \*(lq0,0,1,1\*(rq::box d216 6 a221 3 simply calls this function, passing the parameter \*(lq0,0,1,1\*(rq and multiplies the result by the relation size to get the desired expected number of instances. d231 3 a233 1 my_procedure_1 (MYBOXES.description, \*(lq0,0,1,1\*(rq::box) d238 3 a240 1 MYBOXES.description === \*(lq0,0,1,1\*(rq::box d253 1 d270 1 d274 2 a275 2 remove operator(commands) define function(commands) d278 3 a280 3 Operator names cannot be composed of alphabetic characters in Version 3.0. Operator precedence and associativity are not implemented in Version 3.0. @ 1.7 log @2.1 -> 3.0 @ text @d2 1 a2 1 .\" $Header: RCS/defineoperator,v 1.6 91/02/25 15:17:32 mike Exp Locker: kemnitz $ d64 1 a64 1 .b "define C function" d217 1 a217 1 .b "define C function" d271 1 a271 1 define C function(commands) @ 1.6 log @objectified @ text @d2 1 a2 1 .\" $Header: RCS/defineoperator,v 1.5 91/01/28 23:04:58 mao Exp Locker: mike $ d275 2 a276 2 characters in Version 2.1. Operator precedence and associativity are not implemented in Version 2.1. @ 1.5 log @document handling of operators that refer to one another as commutators or negators. @ text @d2 1 a2 1 .\" $Header: RCS/defineoperator,v 1.4 90/08/02 16:16:33 choi Exp Locker: mao $ d62 1 a62 1 function d190 1 a190 1 sort the two operand relations. d214 1 a214 1 estimate the fraction of the tuples in MYBOXES d223 1 a223 1 of tuples. d225 1 a225 1 Similarly, when the operands of the operator both contain tuple variables, d229 1 a229 1 relations involved to compute the desired expected result size. d275 2 a276 2 characters in Version 2. Operator precedence and associativity are not implemented in Version 2. @ 1.4 log @define operator takes "arg1 = type-1, [arg2 = type-2]" as arguments @ text @d2 1 a2 1 .\" $Header: RCS/defineoperator,v 1.3 90/07/21 18:17:23 kemnitz Exp Locker: choi $ d144 16 @ 1.3 log @Fixed some junk. @ text @d2 1 a2 1 .\" $Header: RCS/defineoperator,v 1.2 90/07/21 18:14:18 kemnitz Exp Locker: kemnitz $ d12 5 a16 1 .b "( procedure =" d239 2 @ 1.2 log @Changed syntax around somewhat to agree with implementation. @ text @d2 1 a2 1 .\" $Header: RCS/defineoperator,v 1.1 90/07/18 16:22:03 mao Exp Locker: kemnitz $ d60 1 a60 1 .b define C function d197 1 a197 1 .b define C function d248 2 a249 1 remove operator(commands). @ 1.1 log @Initial revision @ text @d2 1 a2 1 .\" $Header: defineoperator,v 1.9 89/03/30 10:07:36 wensel Exp $ d13 1 a13 1 proc_name d55 1 a55 8 can be composed of alphabetic characters or symbols, but not a combination of the two (i.e., .b A is valid, but .b ^A^ is not). d57 5 a61 3 .i proc_name procedure must have been previously defined and must have one d65 1 a65 1 answer are as defined by the procedure. d114 4 a117 3 For example, the operator area-less-than, ALT, would have a commutator operator, area-greater-than, AGT. Hence, the query optimizer could freely convert: d119 1 a119 1 \*(lq0,0,1,1\*(rq::box ALT MYBOXES.description d124 1 a124 1 MYBOXES.description AGT \*(lq0,0,1,1\*(rq::box d132 1 a132 1 not MYBOXES.description AE \*(lq0,0,1,1\*(rq::box d137 1 a137 1 MYBOXES.description NAE \*(lq0,0,1,1\*(rq::box d152 1 a152 1 MYBOXES.description AE MYBOXES2.description d157 1 a157 1 MYBOXES.description ALT MYBOXES2.description. d171 2 a172 2 For the AE clause above, the optimizer must sort both relations using the operator, ALT. d175 1 a175 1 MYBOXES.description ALT MYBOXES2.description d189 1 a189 1 MYBOXES.description ALT \*(lq0,0,1,1\*(rq::box d196 4 a199 1 be a registered function which accepts one argument of the correct d213 1 a213 1 my-procedure-1 (MYBOXES.description, \*(lq0,0,1,1\*(rq::box) d218 1 a218 1 MYBOXES.description AE \*(lq0,0,1,1\*(rq::box d234 2 a235 2 define operator AE ( procedure = area-equal-procedure, d238 3 a240 3 commutator = AE, negator = ANE, restrict = area-restriction-procedure, d243 1 a243 1 sort = ALT, ALT) @