![]() |
|
If you selected statistics support routines when creating an opaque data type (see Statistics Support), BladeSmith generates code for the following statistics support routines for your opaque data type in the statistics.c source code file:
To implement user-defined statistics, you must also create selectivity routines to calculate the selectivity of routines that compare your opaque data type. Selectivity routines call the statistics support functions. For a description of user-defined statistics, see User-Defined Statistics.
Important: To avoid merging conflicts when you regenerate your code, add code only in areas marked by TO DO: comments or after the generated code. If you do modify code outside the designated areas, after you regenerate you might have two copies of the routine: the one you modified and the one BladeSmith generated. Although your changes remain, you must resolve the conflicts in the two pieces of code.
The Statistics Collection Function
The OpaqueStatCollect() function collects statistics (minimum value, maximum value, and distribution information) for the Opaque opaque data type when a user executes the UPDATE STATISTICS statement in medium or high mode. For more information on the UPDATE STATISTICS statement, see the Informix Guide to SQL: Syntax.
The OpaqueStatCollect() function calls the Opaque_SetMinValue(), Opaque_SetMaxValue(), and Opaque_SetHistogram() functions.
BladeSmith generates complete code for the OpaqueStatCollect() function. The OpaqueStatCollect() function is an iterator that processes each row in a table. It compiles statistical information by calling the Opaque_SetMinValue(), Opaque_SetMaxValue(), and Opaque_SetHistogram() functions. The OpaqueStatCollect() function stores statistical information in a multirepresentational type.
You must understand your data and how users will query it to create meaningful statistics. BladeSmith generates statistics code under the assumption that the minimum, maximum, and distribution of values are appropriate for your opaque data type; however, they might not be. In that case, you must rewrite the OpaqueStatCollect() function to call other functions that you provide.
The OpaqueStatPrint() function prints formatted statistics for the Opaque opaque data type. You can view statistics information with the dbschema utility.
BladeSmith generates complete code for the OpaqueStatPrint() function; however, you can alter it to customize the information it prints.
The Opaque_SetMinValue() function computes the minimum value of the Opaque opaque data type.
The Opaque_SetMaxValue() function computes the maximum value of the Opaque opaque data type.
The Opaque_SetHistogram() function computes the distribution of the values of the Opaque opaque data type.
BladeSmith generates only function stubs for the Opaque_SetMinValue(), Opaque_SetMaxValue(), and Opaque_SetHistogram() functions.
To complete the code for the statistics support functions, you must add code to compute the minimum, maximum, and distribution of the values of your opaque data type.
When the database server computes the minimum, maximum, and distribution of values for built-in data types, it uses the standard ASCII sequence to order the values. However, opaque data types can be much more complicated. For example, suppose you have a box opaque data type that contains values for its height and its width. You might decide that area of the box is an appropriate measure for determining the minimum and maximum values. The distribution, however, can be more complicated. If the area of the boxes varies, then area might be the appropriate way to assign boxes to bins. If the areas of your boxes are all very similar, but the heights and widths vary, then height or width might be the best distribution criteria.
The Box DataBlade module has an example of statistics support routines.