SET_END in statcollect()
After all rows are processed, statcollect() must transfer the statistics data from its statistics-collection structure into the predefined opaque type, stat. It is stat data that the UPDATE STATISTICS statement stores in the encdat column of the sysdistrib system catalog table.
- An assign() support function, which is responsible
for determining whether or not the statistics data is to be stored
in a smart large object
If the data exceeds the predefined threshold, this assign() function creates the smart large object and increments its reference count. The database server calls this assign() function just before it inserts the mi_statret structure into the encdat column of the sysdistrib table.
- A destroy() support function, which is responsible
for deleting any smart large object that might exist to hold the statistics
data
The database server calls this destroy() function just before it deletes a row from the sysdistrib system catalog table in response to the DROP DISTRIBUTION clause of the UPDATE STATISTICS statement.
For UPDATE STATISTICS to be able to store the distribution data in the encdat column, the statcollect() function must copy its statistics-collection structure into the stat data type.
The internal structure of the stat opaque type is a C language structure named mi_statret. The stat support functions handle most of the interaction with the mi_statret structure; however, your statcollect() function must fill in the mi_statret multirepresentational fields.
- mi_stat_buf
- #define for the statdata.buffer field
- mi_stat_mr
- #define for the statdata.mr field
- MI_STATMAXLEN
- Constant for the size of the statdata.buffer field
- mi_stat_hdrsize
- Size of the information in the mi_statret structure that is not holding the statistics data (size of all fields except the statdata field)
The assign() and destroy() support functions of the stat opaque type determine whether to store the distribution data directly in the encdat column or in a smart large object. In the latter case, the encdat column stores the LO handle of the smart large object. Your statcollect() function can use the MI_STATMAXLEN constant to determine whether it needs to handle multirepresentational data.
- Copy the data from the statistics-collection structure directly into the statdata.buffer field.
- Set the statdata.szind field to MI_MULTIREP_SMALL to indicate that the multirepresentational data is not stored in a smart large object but is in the mi_statret structure.
The assign() and destroy() support functions of the stat opaque type take care of determining whether to store the distribution data directly in the encdat column or in a smart large object whose LO handle is stored in the encdat column.
- Create a new smart large object.
- Copy the data from the statistics-collection structure into the new smart large object.
- Copy the LO handle of this smart large object into the statdata.mr.mr_lo_struct.mr_s_lo field.
- Set the statdata.szind field to MI_MULTIREP_LARGE to indicate that the multirepresentational data is stored in a smart large object.