
2.7.3 DML Event中的标识
前文提到过,每个DML Event都包含columns_after_image/columns_before_image位图。但只是简单地说,对于FULL设置始终是0Xff。这里我们就知道了,如果本参数不设置为FULL,那么read_set和write_set最终会分别写入columns_before_image和columns_after_image。
这里以DELETE语句为例进行比较。
建表语句和数据如下。


执行如下语句。

使用mysqlbinlog解析,如下。

下面是语句生成的DELETE_EVENT。

关键部分解析。
ff:binlog_row_image为FULL,就是记录十六进制值ff。
f8:十六进制值f8转换为二进制值为11111000,参考2.5节。
01 00 00 00:实际数据的第一个字段为数字1。
0a 00 00 00:实际数据的第二个字段为数字10。
07 67 61 6f 70 65 6e 67:实际数据字符串gaopeng的ASCII码。
修改参数binlog_row_image为MINIMAL,执行语句如下。

使用mysqlbinlog解析如下。

下面是DELETE_EVENT:

关键部分解析。
02:十六进制值02,即二进制值00000010,这里是位图的表示方式。说明第二个字段是需要记录到Event的。
fe:十六进制值fe,即二进制值11111110,参考2.5节。
14 00 00 00:实际的数据,十六进制值14,即十进制值20。
我们清楚地看到before_image值记录非空唯一键的值。如果从库本表的结构和主库不同,不包含主键和非空唯一键,只有一个a列上的索引,那么由于主库参数binlog_row_image被设置为MINIMAL,这个索引是用不到的,将会引起全表扫描。这是因为a列的值根本就不会在Event中记录。但是如果参数binlog_row_image被设置为FULL,那么a列上的索引是可以使用的,这是因为Event中记录了全部字段的值。关于从库数据的查找将会在4.6节详细解释。