Extensions of the btree_ops operator class
About this task
After you determine how you want to implement the relational operators for a UDT, you can extend the btree_ops operator class so that the query optimizer can consider use of a B-tree index for a query that contains a relational operator.
To extend the default operator class for a generic B-tree index:
Procedure
- Write functions for the B-tree strategy functions that
accept the UDT in their parameter list.
The relational-operator functions serve as the strategy functions for the btree_ops operator class. If you have already defined these relational-operator functions for the UDT, the generic B-tree index uses them as its strategy functions. For example, you might have defined the relational-operator functions when you extended an aggregate for the user-defined type. (See Example of extending a built-in aggregate.)
- Register the strategy functions in the database with the
CREATE FUNCTION statement.
If you already registered the relational-operator functions, you do not need to reregister them as strategy functions.
- Write a function in C or Java™ for
the B-tree support function, compare(), that accepts
the UDT in its parameter list.(The compare() function cannot be in SPL.)
The compare() function also provides support for a UDT in comparison operations in a SELECT statement (such as the ORDER BY clause or the BETWEEN operator). If you have already defined this comparison function for the UDT, the generic B-tree index uses it as its support function.
When you define a compare() function, you must also define the greaterthan(), lessthan(), equal() or other functions that use the compare function.
- Register the support functions in the database with the
CREATE FUNCTION statement.
For opaque data types, you might have already defined this function to provide support for the comparison operations in a SELECT statement (such as the ORDER BY clause or the BETWEEN operator) on your opaque data type.
What to do next
For more information about strategy functions, see B-tree strategy functions. For information about relational operators for an opaque data type, see Conditional operators for opaque data types.
After you register the support function, use the CREATE INDEX statement to create a B-tree index on the column of the table that contains the UDT. The CREATE INDEX statement does not need the USING clause because you have extended the default operating class for the default index type, a generic B-tree index, to support your UDT.
The query optimizer can now consider use of this generic B-tree index to execute queries efficiently. For more information about the performance aspects of column indexes, see the Informix® Performance Guide.
The previous steps extend the default operator class of the generic B-tree index. You could also define a new operator class to provide another order sequence. For more information, see Creating a new B-tree operator class.