序列类型分析
结构定义
对数据库中类型为序列的字段进行操作的分析函数库使用在头文件 mcoseq.h
中定义的 mco_seq_iterator_t 结构,如下所示:
typedef struct mco_seq_iterator_t_
{
mco_seq_iterator_next_t next; /* method for obtaning next portion of values */
mco_seq_iterator_reset_t reset; /* start iteration from beginning */
mco_seq_iterator_prepare_t prepare; /* prepare iterator (used to start parallel processing) */
mco_seq_iterator_merge_t merge; /* merge two iterators (used to merge results of parallel processing) */
uint2 elem_size; /* size of element */
uint2 tile_size; /* number of tile items */
uint2 tile_offs; /* offset to first not handled tile item */
uint1 rle_offs; /* index within same RLE value */
uint1 prepared; /* flag set by prepare function */
mco_seq_no_t first_seq_no; /* first sequence number (inclusive) */
mco_seq_no_t next_seq_no; /* sequence number of element returned by sudsequent invocation of next() function */
mco_seq_no_t last_seq_no; /* last sequence number (inclusive) */
struct mco_seq_iterator_t_* opd[3]; /*operands of sequence operator */
void* buf; /* memory buffer used by operators requiring temporary memory (reverse, order_by) */
mco_size_t buf_size; /* size of buffer */
uint1 elem_type; /* result element type MCO_DD_... */
uint1 bounded; /* iterator is used in expression */
uint1 createdBySql; /* iterator was created by SQL */
uint8 context[MCO_SEQ_ITERATOR_CTX_SIZE/8]; /* operator specific context */
mco_seq_tile_t tile; /* tile of values */
} mco_seq_iterator_t, *mco_seq_iterator_h;
诸如生成的函数 classname_fieldname_search()
这样的函数使用 mco_seq_boundary_kind_t 结构来指定边界类型:
typedef enum mco_seq_boundary_kind_t_
{
MCO_SEQ_BOUNDARY_OPEN,
MCO_SEQ_BOUNDARY_INCLUSIVE,
MCO_SEQ_BOUNDARY_EXCLUSIVE
} mco_seq_boundary_kind_t;
为了优化内存中序列的访问,序列函数在连续内存块中的序列值数组上运行。
用于此内部优化的 mco_seq_iterator_t 结构的最后一个元素层定义如下:
typedef union mco_seq_tile_t_
{
mco_seq_bool arr_mco_seq_bool[MCO_SEQ_TILE_SIZE_BYTES/sizeof(mco_seq_bool)];
char arr_char[MCO_SEQ_TILE_SIZE_BYTES];
int1 arr_int1[MCO_SEQ_TILE_SIZE_BYTES];
int2 arr_int2[MCO_SEQ_TILE_SIZE_BYTES/sizeof(int2)];
int4 arr_int4[MCO_SEQ_TILE_SIZE_BYTES/sizeof(int4)];
mco_int8 arr_int8[MCO_SEQ_TILE_SIZE_BYTES/sizeof(mco_int8)];
uint1 arr_uint1[MCO_SEQ_TILE_SIZE_BYTES/sizeof(uint1)];
uint2 arr_uint2[MCO_SEQ_TILE_SIZE_BYTES/sizeof(uint2)];
uint4 arr_uint4[MCO_SEQ_TILE_SIZE_BYTES/sizeof(uint4)];
uint8 arr_uint8[MCO_SEQ_TILE_SIZE_BYTES/sizeof(uint8)];
mco_time arr_mco_time[MCO_SEQ_TILE_SIZE_BYTES/sizeof(mco_time)];
mco_date arr_mco_date[MCO_SEQ_TILE_SIZE_BYTES/sizeof(mco_date)];
mco_datetime arr_datetime[MCO_SEQ_TILE_SIZE_BYTES/sizeof(mco_datetime)];
float arr_float[MCO_SEQ_TILE_SIZE_BYTES/sizeof(float)];
double arr_double[MCO_SEQ_TILE_SIZE_BYTES/sizeof(double)];
} mco_seq_tile_t MCO_ALIGN_16;