A commutator function is a special UDR that is associated with a user-defined function. A UDR is commutator of another user-defined function if either of the following statements is true:
For example, the lessthan( ) and greaterthanorequal( ) functions are commutators of one another because the following two expressions yield the same result:
a < b
b >= a
In the following SELECT statement, the optimizer can choose whether it is more cost effective to execute lessthan(a, b) or greaterthanorequal(b, a) in the WHERE clause:
SELECT * FROM tab1 WHERE lessthan(a, b);
The optimizer can choose to invoke the function greaterthanorequal(b, a) if there is no index on lessthan( ) and there exists an index on greaterthanorequal( ).
Specify the name of the commutator function with the COMMUTATOR routine modifier in the CREATE FUNCTION statement that registers the user-defined function.
The following CREATE FUNCTION statements register the commute_func1( ) and func1( ) user-defined functions:
CREATE FUNCTION commute_func1(b CHAR(20), a INTEGER) RETURNS INTEGER EXTERNAL NAME '/usr/local/lib/udrs/udrs.so' LANGUAGE C; CREATE FUNCTION func1(a INTEGER, b CHAR(20)) RETURNS INTEGER WITH (COMMUTATOR = commute_func1) EXTERNAL NAME '/usr/local/lib/udrs/udrs.so' LANGUAGE C;
For more information about commutator functions, see the IBM Informix: User-Defined Routines and Data Types Developer's Guide. For information on how to determine if a user-defined function has a commutator function, see Checking for a Commutator Function.
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]