Strategy functions in a data type hierarchy

When you create the strategy functions, such as Overlaps, only one function needs to be created in SQL: Overlaps (MyShape, MyShape). The internal C code for this Overlaps function first checks to see what actual data type it is operating on (either MyPoint, MyBox, or MyCircle), and then calls the appropriate code for that data type. For example, if the function call in the query was actually Overlaps (MyCircle, MyCircle), the appropriate code for the overlap between two MyCircle data types is executed.

If a query contains the expression Overlaps (MyCircle, MyCircle), the query optimizer first looks for a function with the same signature. It will not find one, because none has been defined. It does, however, find a cast from MyCircle to MyShape, so it searches for an Overlaps function that applies to the MyShape data type. Because this function does exist, the query optimizer executes it after implicitly casting MyCircle to MyShape.

By taking advantage of type hierarchies and casting, you avoid having to explicitly create the various combinations of Overlaps functions within SQL, such as Overlaps(MyPoint, MyPoint), Overlaps(MyBox, MyCircle), and so on.

The preceding discussion about type hierarchies and strategy functions is true for all strategy functions, not just for the Overlaps function.