Create an absolute-value operator class
-1, 2, -3, -4
- Write and register external functions for the new strategy functions: abs_lessthan(), abs_lessthanorequal(), abs_equal(), abs_greaterthan(),
and abs_greaterthanorequal().
For more information, refer to Develop a user-defined routine.
- Register the five new strategy functions with the CREATE FUNCTION statement.
- Write the C function for the new support function: abs_compare().
Compile this function and store it in the absbtree.so shared-object file.
- Register the new support function with the CREATE FUNCTION statement.
- Create the new abs_btree_ops operator class for the B-tree secondary-access method.
CREATE TABLE cust_tab
(
cust_name varchar(20),
cust_num integer
...
);
CREATE INDEX c_num1_ix
ON cust_tab (cust_num abs_btree_ops);
SELECT * FROM cust_tab WHERE abs_lt(cust_num, 7)
In addition, because the abs_lt() function is part of an operator class, the query optimizer can use the c_num1_ix index when it looks for all cust_tab rows with cust_num values between -7 and 7. A cust_num value of -8 does not satisfy this query.
CREATE INDEX c_num2_ix ON cust_tab (cust_num);
SELECT * FROM cust_tab WHERE lessthan(cust_num, 7)
The query optimizer can use the c_num2_ix index when it looks for all cust_tab rows with cust_num values less than 7. A cust_num value of -8 does satisfy this query.