Create an operator class

For most indexing, the operators in the default operator class of a secondary-access method provide adequate support. However, when you want to order the data in a different sequence than the default operator class provides, you can define a new operator class for the secondary-access method.

The CREATE OPCLASS statement creates an operator class. It provides the following information about the operator class to the database server:
  • The name of the operator class
  • The name of the secondary-access method with which to associate the functions of the operator class
  • The names and, optionally, the parameters of the strategy functions
  • The names of the support functions

The database server stores this information in the sysopclasses system catalog table. You must have the Resource privilege for the database or be the DBA to create an operator class.

The database server provides the default operator class, btree_ops, for the generic B-tree access method. The following CREATE OPCLASS statement creates a new operator class for the generic B-tree access method. You must list the strategy functions in the order shown:
CREATE OPCLASS new_btree_ops FOR btree
   STRATEGIES (lessthan, lessthanorequal, equal,
      greaterthanorequal, greaterthan)
   SUPPORT(compare);

For more information, see Generic B-tree index.

You might want to create a new operator class for:
  • The generic B-tree secondary-access method

    A new operator class can provide an additional sort order for all data types that the B-tree index can handle.

  • Any user-defined secondary-access methods

    A new operator class can provide additional functionality to the strategy functions of the operator class.