Strategy functions

Strategy functions are user-defined functions that can be used in queries to select data. Registering them as strategy functions with the CREATE OPCLASS statement lets the optimizer know that an associated R-tree index can be used to execute a query that contains one of those functions.

For example, assume there is an R-tree index on a column called boxes, and Overlap is defined as a strategy function. If a query contains the qualification WHERE Overlap (boxes, region), the query optimizer considers using the R-tree index to evaluate the query.

You can include up to 64 strategy functions when you create a new operator class for the R-tree access method. You must, however, include the following four strategy functions:
  • Overlap
  • Equal
  • Contains
  • Within

You must list these functions first, in the order shown, when you execute the CREATE OPCLASS statement to register the operator class with the database server. This SQL statement is described in Syntax for creating a new operator class.

The four required strategy functions are defined in detail in later topics, with an example of creating the Contains strategy function.
Tip: It is useful to name strategy functions in a way that describes what they do. For example, it makes sense to name a function that calculates whether one object overlaps another Overlap. For convenience, this guide uses the names Overlap, Equal, Contains, and Within when it describes the four required strategy functions. These are also the names that the default operator class rtree_ops uses for its strategy functions.