十一:引數binlog_row_image(筆記)
歡迎關注我的《深入理解MySQL主從原理 32講 》,如下:
如果圖片不能顯示可檢視下面連結:
https://www.jianshu.com/p/d636215d767f
一、設定過程
插入前先呼叫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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7728585/viewspace-2649953/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Swift學習筆記(三十一)——引數的預設值Swift筆記
- Swift學習筆記(三十三)——常量引數,變數引數和inout引數Swift筆記變數
- ES6 筆記 Rest 引數和 預設引數筆記REST
- NOVA溫控器引數筆記(十四)筆記
- Bootstrap Table 學習筆記之列引數(一)boot筆記
- GoldenGate學習筆記(11)_常用引數Go筆記
- Pytest學習筆記8-引數化筆記
- Swift學習筆記(三十二)——可變引數Swift筆記
- 讀書筆記:深入解析oracle-第3章 引數及引數檔案筆記Oracle
- hive學習筆記之十一:UDTFHive筆記
- Vue學習筆記(十一):路由管理Vue筆記路由
- angular學習筆記(十一)-表示式Angular筆記
- Swift學習筆記(三十)——函式的內部引數名和外部引數名Swift筆記函式
- docker學習筆記-啟動映象輸入引數Docker筆記
- JVM引數調優八大技巧之筆記JVM筆記
- ES6筆記之引數預設值(譯)筆記
- Redis學習筆記(十一) 伺服器Redis筆記伺服器
- ReactNative學習筆記十一之FlatListReact筆記
- Nginxhttp模組(學習筆記二十一)NginxHTTP筆記
- angular學習筆記(三十一)-$location(1)Angular筆記
- angular學習筆記(三十一)-$location(2)Angular筆記
- Swift學習筆記(二十一)——字典Swift筆記
- 【轉】Oracle學習筆記:INITRANS和MAXTRANS引數的作用Oracle筆記
- 10G新特性筆記之COMPATIBLE引數筆記
- C#學習筆記-方法引數、擴充套件方法C#筆記套件
- oracle學習筆記(十一) 高階查詢Oracle筆記
- ES(2017)學習筆記(十一)【Async】筆記
- Linux 筆記分享十一:sudo 許可權Linux筆記
- Java學習筆記——第十一天Java筆記
- JavaWeb學習筆記——第十一天JavaWeb筆記
- 數學筆記筆記
- ESP32引腳筆記筆記
- Django筆記四十一之Django中使用esDjango筆記
- angular學習筆記(二十一)-$http.getAngular筆記HTTP
- PMBOK筆記-第十一章 專案風險管理筆記
- Reinforcement Learning 第十一週課程筆記筆記
- 效能測試學習筆記:Loadrunner如何進行引數化?筆記
- LTE-5G學習筆記8---PRACH引數規劃筆記