目的
MySQL数据库源码中,MY_BITMAP数据结构及相关处理方法是位图相关的操作。尽管MySQL不支持位图索引,但是在binlog子系统、查询子系统、分区子系统以及table的定义中都有应用。
数据结构
BITMAP相关的数据结构定义在mysql源码的include/my_bitmap.h和mysys/my_bitmap.c文件中,具体定义如下所示:
typedefuint32 my_bitmap_map;
typedefstruct st_bitmap
{
my_bitmap_map *bitmap;
uint n_bits; /* number of bits occupied by the above */
my_bitmap_map last_word_mask;
my_bitmap_map *last_word_ptr;
/* mutex will be acquired for the duration of each bitmap operation if thread_safe flag in bitmap_init was set.Otherwise, we optimize by not acquiring the mutex */
mysql_mutex_t *mutex;
} MY_BITMAP;
MY_BITMAP数据结构定义比较简单,其中bitmap是实际存储位图信息的字段;n_bits表示位图表示的位数,即bitmap的有效位数;last_word_mask和last_word_ptr两个变量用于指定最后一个数的掩码值和指针地址,主要是安全访问的考虑;mutex是多线程并发操作时,提供现成安全的访问。
源码实现