十一:参数binlog_row_image(笔记)

简介: 一、设置过程插入前先调用TABLE::mark_columns_per_binlog_row_image函数函数中有image的详细设置/* Mark columns according the binlog row image option.

一、设置过程

插入前先调用TABLE::mark_columns_per_binlog_row_image函数
函数中有image的详细设置

/*
  Mark columns according the binlog row image option.

  When logging in RBR, the user can select whether to
  log partial or full rows, depending on the table
  definition, and the value of binlog_row_image.

  Semantics of the binlog_row_image are the following 
  (PKE - primary key equivalent, ie, PK fields if PK 
  exists, all fields otherwise):

  binlog_row_image= MINIMAL
    - This marks the PKE fields in the read_set
    - This marks all fields where a value was specified
      in the write_set

  binlog_row_image= NOBLOB
    - This marks PKE + all non-blob fields in the read_set
    - This marks all fields where a value was specified
      and all non-blob fields in the write_set

  binlog_row_image= FULL
    - all columns in the read_set
    - all columns in the write_set
    
  This marking is done without resetting the original 
  bitmaps. This means that we will strip extra fields in
  the read_set at binlogging time (for those cases that 
  we only want to log a PK and we needed other fields for
  execution).
 */
void TABLE::mark_columns_per_binlog_row_image()
{
  DBUG_ENTER("mark_columns_per_binlog_row_image");
  DBUG_ASSERT(read_set->bitmap);
  DBUG_ASSERT(write_set->bitmap);

  /**
    If in RBR we may need to mark some extra columns,
    depending on the binlog-row-image command line argument.
   */
  if ((mysql_bin_log.is_open() && in_use &&
       in_use->is_current_stmt_binlog_format_row() &&
       !ha_check_storage_engine_flag(s->db_type(), HTON_NO_BINLOG_ROW_OPT)))
  {

    THD *thd= current_thd;

    /* if there is no PK, then mark all columns for the BI. */
    if (s->primary_key >= MAX_KEY)
      bitmap_set_all(read_set);

    switch (thd->variables.binlog_row_image)
    {
      case BINLOG_ROW_IMAGE_FULL:
        if (s->primary_key < MAX_KEY)
          bitmap_set_all(read_set); //记录全部字段
        bitmap_set_all(write_set); //记录全部字段,前面write_set应该只是记录了 修改了哪些字段   位图 初始化初始4字节
        break;
      case BINLOG_ROW_IMAGE_NOBLOB:
        /* for every field that is not set, mark it unless it is a blob */
        for (Field **ptr=field ; *ptr ; ptr++)
        {
          Field *my_field= *ptr;
          /* 
            bypass blob fields. These can be set or not set, we don't care.
            Later, at binlogging time, if we don't need them in the before 
            image, we will discard them.

            If set in the AI, then the blob is really needed, there is 
            nothing we can do about it.
           */
          if ((s->primary_key < MAX_KEY) && 
              ((my_field->flags & PRI_KEY_FLAG) || 
              (my_field->type() != MYSQL_TYPE_BLOB)))
            bitmap_set_bit(read_set, my_field->field_index);

          if (my_field->type() != MYSQL_TYPE_BLOB)
            bitmap_set_bit(write_set, my_field->field_index);
        }
        break;
      case BINLOG_ROW_IMAGE_MINIMAL:
        /* mark the primary key if available in the read_set */
        if (s->primary_key < MAX_KEY)
          mark_columns_used_by_index_no_reset(s->primary_key, read_set); //只记录主键或者非空唯一键的 字段
        break;

      default: 
        DBUG_ASSERT(FALSE);
    }
    file->column_bitmaps_signal();
  }

  DBUG_VOID_RETURN;
}

二、过滤过程

THD::binlog_prepare_row_images还会准备image

binlog_log_row 上层接口 记录 binlog
-> Write_rows_log_event::binlog_row_logging_function 
  -> THD::binlog_write_row(THD::binlog_delete_row)
     ->THD::binlog_prepare_row_images 准备前印象位图 如果没有主键/非空唯一键 则不考虑记录全字段
       pack_row 通过位图准备好行
       THD::binlog_prepare_pending_rows_event 
         -> 判断是否需要新建一个EVENT 大约8K左右,
            如果新建 新建后写event到 log buffer
         ->否则在当前event中写入   
       add_row_data(row_data, len); 将数据加入到EVENT
相关文章
|
8月前
|
数据挖掘 OLAP 定位技术
星形模式(Star Schema)
星形模式(Star Schema)是一种常用于数据仓库设计的数据模型。它以星形的结构命名,因为中心的事实表(Fact Table)被周围的维度表(Dimension Tables)所环绕,就像星星周围的射线一样。星形模式具有简单、直观和易于理解的特点,适用于大量数据的查询和分析。
603 1
|
NoSQL Redis 数据安全/隐私保护
Redis 6.0 新特性详解
艺术致敬! 一、众多新模块(modules)API   Redis 6中模块API开发进展非常大,因为Redis Labs为了开发复杂的功能,从一开始就用上Redis模块。Redis可以变成一个框架,利用Modules来构建不同系统,而不需要从头开始写然后还要BSD许可。
8309 0
|
存储 关系型数据库 MySQL
MySQL出现Data too long for column...(错误号1406)和 Data truncated for column...(错误号1265)
MySQL出现Data too long for column...(错误号1406)和 Data truncated for column...(错误号1265)
582 0
MySQL出现Data too long for column...(错误号1406)和 Data truncated for column...(错误号1265)
|
JSON NoSQL Redis
redis-full-check校验工具
redis-full-check是阿里云Redis&MongoDB团队开源的用于校验2个redis数据是否一致的工具,通常用于redis数据迁移后正确性的校验。
19900 0
开发指南—Sequence—显示用法—修改Sequence
本文主要介绍如何对Sequence的各种类型进行修改。
115 0
开发指南—Sequence—显示用法—删除Sequence
本文主要介绍如何删除已经创建的Sequence。
|
缓存 Linux 开发工具
CentOS 7- 配置阿里镜像源
阿里镜像官方地址http://mirrors.aliyun.com/ 1、点击官方提供的相应系统的帮助 :2、查看不同版本的系统操作: 下载源1、安装wget yum install -y wget2、下载CentOS 7的repo文件wget -O /etc/yum.
152231 0
|
缓存 关系型数据库 MySQL
MySQL参数优化之thread_cache_size
MySQL参数优化之thread_cache_size
1242 0
|
缓存 关系型数据库 MySQL
【MySQL】read_buffer_size=512kb,是干什么的?底层原理是什么?
【MySQL】read_buffer_size=512kb,是干什么的?底层原理是什么?
277 0
|
NoSQL Redis 监控
redis-shake数据同步&迁移&备份导入导出工具使用介绍
redis-shake是阿里云Redis&MongoDB团队开源的用于redis数据同步的工具。
65019 3
redis-shake数据同步&迁移&备份导入导出工具使用介绍

热门文章

最新文章