Home | Previous Page | Next Page   Using a User-Defined Routine > Tasks That You Can Perform with User-Defined Routines >

Supporting User-Defined Data Types

When you create UDTs, you also provide the following routines:

Cast Functions

A cast performs a conversion between two data types. The database server allows you to write your own cast functions to perform casts. The following sections summarize how you can extend a cast function for built-in and UDTs. For more information on how to extend casts, refer to Creating User-Defined Casts.

Tip:
If a DataBlade module defines a data type, it might also provide cast functions between this data type and other data types in the database. For more information on functions that a specific DataBlade module provides, refer to the user guide for that DataBlade module.
Casting Between Built-In Data Types

The database server provides built-in casts that perform automatic conversions between certain built-in data types. For more information on these built-in casts, refer to the IBM Informix: Guide to SQL Reference.

You cannot create user-defined casts to allow conversions between two built-in data types for which a built-in cast does not currently exist. For more information on when you might want to write new cast functions, refer to Creating a User-Defined Cast.

Casting Between Other Data Types

You can create user-defined casts to perform conversions between most data types, including opaque types, distinct types, row types, and built-in types. You can write cast functions in SPL or in external languages. For example, you can define casts for any of the following UDTs:

For more information on how to create and register casts on extended data types, refer to Creating User-Defined Casts.

End-User Routines

An end-user routine is an SQL-invoked function that the SQL user can include in an SQL statement. Such routines provide special functionality that application users often need. An end-user routine might be as simple as "increase the price of every item from XYZ Corporation by 5 percent" or something far more complicated.

This section summarizes how you can extend an end-user routine that operates on the following data types:

For more information about end-user routines, see Creating an End-User Routine.

Aggregate Functions

An aggregate function is an SQL-invoked function that takes values that depend on all the rows that the query selects and returns information about these rows. The database server supports aggregate functions that you write, called user-defined aggregates. You can write user-defined aggregates in SPL or in external languages.

You can extend an aggregate function for built-in and UDTs, as follows:

Tip:
If a DataBlade module defines a data type, it might also provide user-defined aggregate functions on this data type. For more information on functions that a specific DataBlade module provides, refer to the user guide for that DataBlade module.

For more information about aggregate functions, see Creating User-Defined Aggregates. Aggregate functions use the support functions to compute the aggregate result. For information on support functions, see Writing Support Functions.

Operator Functions

An operator function is an SQL-invoked function that has a corresponding operator symbol (such as '=' or '+'). These operator symbols are used within expressions in an SQL statement.

Operator binding is the implicit invocation of an operator function when an operator symbol is used in an SQL statement. The database server implicitly maps a built-in operator function name to a built-in operator. For example, you can compare two values for equality in either of the following ways.

Method of Comparison
Operator Used
Operator function
equal(value1, value2)
Operator symbol
value1 = value2

The following sections summarize how you can extend an operator on built-in and UDTs. For more information on how to extend operators, refer to Extending Operators and Built-In Functions.

Operators on Built-In Data Types

The database server provides operator functions that operate on most built-in data types. For a complete list of operator functions, see Extending Operators and Built-In Functions. You cannot extend an operator function that operates on a built-in data type.

Operators on User-Defined Data Types

You can extend an existing operator to operate on a UDT. When you define the appropriate operator function, operator binding enables SQL statements to use both the function name and its operator symbol on the UDT. You can write operator functions in SPL or an external language.

For example, suppose you create a data type, called Scottish, that represents Scottish names, and you want to order the data type in a different way than the U.S. English collating sequence. You might want the names McDonald and MacDonald to appear together on a phone list. The default relational operators (for example, =) for character strings do not achieve this ordering.

To cause Mc and Mac to appear together, you can create a compare() function that compares two Scottish-name values and treats Mc and Mac identically. The database server uses the compare (Scottish, Scottish) function when it compares two Scottish-name values. If you define a compare() function, you must also define the greaterthan(), lessthan(), equal() or other functions that use the compare function.

Note:
Routine overloading is the ability to use the same name for multiple functions to handle different data types.

For more information, refer to Overloading Routines.

Tip:
The relational operators (such as =) are the operator-class functions of the built-in secondary-access method, the generic B-tree. Therefore, if you redefine the relational operators to handle a UDT, you also enable that type to be used in a B-tree index. For more information, see Operator-Class Functions in the following section.

Operator-Class Functions

An operator class is the set of operators that the database server associates with a secondary-access method for query optimization and building the index. A secondary-access method (sometimes referred to as an index-access method) is a set of database server functions that build, access, and manipulate an index structure such as a B-tree, an R-tree, or an index structure that a DataBlade module provides.

The query optimizer uses an operator class to determine if an index can be considered in the cost analysis of query plans. The query optimizer can consider use of the index for the given query when the following conditions are true:

For more information on how to optimize queries with UDRs, refer to Optimizing a User-Defined Routine. For more information on how to extend operator classes, refer to Extending an Existing Operator Class.

Tip:
If a DataBlade module provides a secondary-access method, it might also provide operator classes with the strategy and support functions. For more information on functions that a specific DataBlade module provides, refer to the user guide for that DataBlade module.
Operator-Class Functions on Built-In Data Types

The database server provides the default operator class for the built-in secondary-access method, the generic B-tree. These operator-class functions handle the built-in data types. You can write new operator-class functions that operate on built-in data types if you want to do the following:

Operator Classes on User-Defined Data Types

When you create a opaque data type, you can write operator-class functions to do the following:

Optimization Functions

Optimization functions help the query optimizer determine the most efficient query plan for a particular SQL statement. These optimization functions are as follows.

Optimization Function
Description
Negator function
Specifies the function to use for a NOT condition that involves a Boolean UDR
Cost function
Specifies the cost factor for execution of a particular UDR
Selectivity function
Specifies the percentage of rows for which a Boolean UDR is expected to return true
Parallel UDR
A UDR that can be run in parallel and therefore can be run in parallel queries
Statistics function
Creates distribution statistics for a UDT

The database server provides optimization functions for the built-in data types. You can write an optimization function on any UDT that is registered in the database. You cannot extend existing optimization for built-in types through optimization functions.

For more information about optimization functions, see Improving UDR Performance.

Opaque Data Type Support Functions

When you define a new opaque data type, you provide support functions that enable the database server to operate on the data type. The database server requires some support functions, and others are optional. The following list shows the standard functions that you define to support opaque data types:

For more information on support functions for opaque data types, refer to Writing Support Functions.

Access-Method Purpose Functions

An access method is a set of functions that the database server uses to access and manipulate a table or an index. The two types of access methods are as follows:

DataBlade modules can provide other primary- and secondary-access methods. For more information, refer to the IBM Informix: Virtual-Table Interface Programmer's Guide and the IBM Informix: Virtual-Index Interface Programmer's Guide.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]