MySQL  8.0.22
Source Code Documentation
rows_event.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2020, Oracle and/or its affiliates.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 /**
24  @addtogroup Replication
25  @{
26 
27  @file rows_event.h
28 
29  @brief Contains the classes representing events which are used for row based
30  replication. In row-based replication, the master writes events to the binary
31  log that indicate how individual table rows are changed.
32 */
33 
34 #ifndef ROWS_EVENT_INCLUDED
35 #define ROWS_EVENT_INCLUDED
36 
37 #include <vector>
38 #include "control_events.h"
39 #include "table_id.h"
40 
41 /**
42  1 byte length, 1 byte format
43  Length is total length in bytes, including 2 byte header
44  Length values 0 and 1 are currently invalid and reserved.
45 */
46 #define EXTRA_ROW_INFO_LEN_OFFSET 0
47 #define EXTRA_ROW_INFO_FORMAT_OFFSET 1
48 #define EXTRA_ROW_INFO_HEADER_LENGTH 2
49 #define EXTRA_ROW_INFO_MAX_PAYLOAD (255 - EXTRA_ROW_INFO_HEADER_LENGTH)
50 
51 #define ROWS_MAPID_OFFSET 0
52 #define ROWS_FLAGS_OFFSET 6
53 #define ROWS_VHLEN_OFFSET 8
54 #define EXTRA_ROW_INFO_TYPECODE_LENGTH 1
55 #define EXTRA_ROW_PART_INFO_VALUE_LENGTH 2
56 
57 /**
58  This is the typecode defined for the different elements present in
59  the container Extra_row_info, this is different from the format information
60  stored inside extra_row_ndb_info at EXTRA_ROW_INFO_FORMAT_OFFSET.
61 */
62 enum class enum_extra_row_info_typecode { NDB = 0, PART = 1 };
63 
64 namespace binary_log {
65 /**
66  @class Table_map_event
67 
68  In row-based mode, every row operation event is preceded by a
69  Table_map_event which maps a table definition to a number. The
70  table definition consists of database name, table name, and column
71  definitions.
72 
73  @section Table_map_event_binary_format Binary Format
74 
75  The Post-Header has the following components:
76 
77  <table>
78  <caption>Post-Header for Table_map_event</caption>
79 
80  <tr>
81  <th>Name</th>
82  <th>Format</th>
83  <th>Description</th>
84  </tr>
85 
86  <tr>
87  <td>table_id</td>
88  <td>6 bytes unsigned integer</td>
89  <td>The number that identifies the table.</td>
90  </tr>
91 
92  <tr>
93  <td>flags</td>
94  <td>2 byte bitfield</td>
95  <td>Reserved for future use; currently always 0.</td>
96  </tr>
97 
98  </table>
99 
100  The Body has the following components:
101 
102  <table>
103  <caption>Body for Table_map_event</caption>
104 
105  <tr>
106  <th>Name</th>
107  <th>Format</th>
108  <th>Description</th>
109  </tr>
110 
111  <tr>
112  <td>database_name</td>
113  <td>one byte string length, followed by null-terminated string</td>
114  <td>The name of the database in which the table resides. The name
115  is represented as a one byte unsigned integer representing the
116  number of bytes in the name, followed by length bytes containing
117  the database name, followed by a terminating 0 byte. (Note the
118  redundancy in the representation of the length.) </td>
119  </tr>
120 
121  <tr>
122  <td>table_name</td>
123  <td>one byte string length, followed by null-terminated string</td>
124  <td>The name of the table, encoded the same way as the database
125  name above.</td>
126  </tr>
127 
128  <tr>
129  <td>column_count</td>
130  <td>@ref packed_integer "Packed Integer"</td>
131  <td>The number of columns in the table, represented as a packed
132  variable-length integer.</td>
133  </tr>
134 
135  <tr>
136  <td>column_type</td>
137  <td>List of column_count 1 byte enumeration values</td>
138  <td>The type of each column in the table, listed from left to
139  right. Each byte is mapped to a column type according to the
140  enumeration type enum_field_types defined in mysql_com.h. The
141  mapping of types to numbers is listed in the table @ref
142  Table_table_map_event_column_types "below" (along with
143  description of the associated metadata field). </td>
144  </tr>
145 
146  <tr>
147  <td>metadata_length</td>
148  <td>@ref packed_integer "Packed Integer"</td>
149  <td>The length of the following metadata block</td>
150  </tr>
151 
152  <tr>
153  <td>metadata</td>
154  <td>list of metadata for each column</td>
155  <td>For each column from left to right, a chunk of data who's
156  length and semantics depends on the type of the column. The
157  length and semantics for the metadata for each column are listed
158  in the table @ref Table_table_map_event_column_types
159  "below".</td>
160  </tr>
161 
162  <tr>
163  <td>null_bits</td>
164  <td>column_count bits, rounded up to nearest byte</td>
165  <td>For each column, a bit indicating whether data in the column
166  can be NULL or not. The number of bytes needed for this is
167  int((column_count + 7) / 8). The flag for the first column from the
168  left is in the least-significant bit of the first byte, the second
169  is in the second least significant bit of the first byte, the
170  ninth is in the least significant bit of the second byte, and so
171  on. </td>
172  </tr>
173 
174  <tr>
175  <td>optional metadata fields</td>
176  <td>optional metadata fields are stored in Type, Length, Value(TLV) format.
177  Type takes 1 byte. Length is a packed integer value. Values takes
178  Length bytes.
179  </td>
180  <td>There are some optional metadata defined. They are listed in the table
181  @ref Table_table_map_event_optional_metadata. Optional metadata fields
182  follow null_bits. Whether binlogging an optional metadata is decided by the
183  server. The order is not defined, so they can be binlogged in any order.
184  </td>
185  </tr>
186  </table>
187 
188  The table below lists all column types, along with the numerical
189  identifier for it and the size and interpretation of meta-data used
190  to describe the type.
191 
192  @anchor Table_table_map_event_column_types
193  <table>
194  <caption>Table_map_event column types: numerical identifier and
195  metadata</caption>
196  <tr>
197  <th>Name</th>
198  <th>Identifier</th>
199  <th>Size of metadata in bytes</th>
200  <th>Description of metadata</th>
201  </tr>
202 
203  <tr>
204  <td>MYSQL_TYPE_DECIMAL</td><td>0</td>
205  <td>0</td>
206  <td>No column metadata.</td>
207  </tr>
208 
209  <tr>
210  <td>MYSQL_TYPE_TINY</td><td>1</td>
211  <td>0</td>
212  <td>No column metadata.</td>
213  </tr>
214 
215  <tr>
216  <td>MYSQL_TYPE_SHORT</td><td>2</td>
217  <td>0</td>
218  <td>No column metadata.</td>
219  </tr>
220 
221  <tr>
222  <td>MYSQL_TYPE_LONG</td><td>3</td>
223  <td>0</td>
224  <td>No column metadata.</td>
225  </tr>
226 
227  <tr>
228  <td>MYSQL_TYPE_FLOAT</td><td>4</td>
229  <td>1 byte</td>
230  <td>1 byte unsigned integer, representing the "pack_length", which
231  is equal to sizeof(float) on the server from which the event
232  originates.</td>
233  </tr>
234 
235  <tr>
236  <td>MYSQL_TYPE_DOUBLE</td><td>5</td>
237  <td>1 byte</td>
238  <td>1 byte unsigned integer, representing the "pack_length", which
239  is equal to sizeof(double) on the server from which the event
240  originates.</td>
241  </tr>
242 
243  <tr>
244  <td>MYSQL_TYPE_NULL</td><td>6</td>
245  <td>0</td>
246  <td>No column metadata.</td>
247  </tr>
248 
249  <tr>
250  <td>MYSQL_TYPE_TIMESTAMP</td><td>7</td>
251  <td>0</td>
252  <td>No column metadata.</td>
253  </tr>
254 
255  <tr>
256  <td>MYSQL_TYPE_LONGLONG</td><td>8</td>
257  <td>0</td>
258  <td>No column metadata.</td>
259  </tr>
260 
261  <tr>
262  <td>MYSQL_TYPE_INT24</td><td>9</td>
263  <td>0</td>
264  <td>No column metadata.</td>
265  </tr>
266 
267  <tr>
268  <td>MYSQL_TYPE_DATE</td><td>10</td>
269  <td>0</td>
270  <td>No column metadata.</td>
271  </tr>
272 
273  <tr>
274  <td>MYSQL_TYPE_TIME</td><td>11</td>
275  <td>0</td>
276  <td>No column metadata.</td>
277  </tr>
278 
279  <tr>
280  <td>MYSQL_TYPE_DATETIME</td><td>12</td>
281  <td>0</td>
282  <td>No column metadata.</td>
283  </tr>
284 
285  <tr>
286  <td>MYSQL_TYPE_YEAR</td><td>13</td>
287  <td>0</td>
288  <td>No column metadata.</td>
289  </tr>
290 
291  <tr>
292  <td><i>MYSQL_TYPE_NEWDATE</i></td><td><i>14</i></td>
293  <td>&ndash;</td>
294  <td><i>This enumeration value is only used internally and cannot
295  exist in a binlog.</i></td>
296  </tr>
297 
298  <tr>
299  <td>MYSQL_TYPE_VARCHAR</td><td>15</td>
300  <td>2 bytes</td>
301  <td>2 byte unsigned integer representing the maximum length of
302  the string.</td>
303  </tr>
304 
305  <tr>
306  <td>MYSQL_TYPE_BIT</td><td>16</td>
307  <td>2 bytes</td>
308  <td>A 1 byte unsigned int representing the length in bits of the
309  bitfield (0 to 64), followed by a 1 byte unsigned int
310  representing the number of bytes occupied by the bitfield. The
311  number of bytes is either int((length + 7) / 8) or int(length / 8).
312  </td>
313  </tr>
314 
315  <tr>
316  <td>MYSQL_TYPE_NEWDECIMAL</td><td>246</td>
317  <td>2 bytes</td>
318  <td>A 1 byte unsigned int representing the precision, followed
319  by a 1 byte unsigned int representing the number of decimals.</td>
320  </tr>
321 
322  <tr>
323  <td><i>MYSQL_TYPE_ENUM</i></td><td><i>247</i></td>
324  <td>&ndash;</td>
325  <td><i>This enumeration value is only used internally and cannot
326  exist in a binlog.</i></td>
327  </tr>
328 
329  <tr>
330  <td><i>MYSQL_TYPE_SET</i></td><td><i>248</i></td>
331  <td>&ndash;</td>
332  <td><i>This enumeration value is only used internally and cannot
333  exist in a binlog.</i></td>
334  </tr>
335 
336  <tr>
337  <td>MYSQL_TYPE_TINY_BLOB</td><td>249</td>
338  <td>&ndash;</td>
339  <td><i>This enumeration value is only used internally and cannot
340  exist in a binlog.</i></td>
341  </tr>
342 
343  <tr>
344  <td><i>MYSQL_TYPE_MEDIUM_BLOB</i></td><td><i>250</i></td>
345  <td>&ndash;</td>
346  <td><i>This enumeration value is only used internally and cannot
347  exist in a binlog.</i></td>
348  </tr>
349 
350  <tr>
351  <td><i>MYSQL_TYPE_LONG_BLOB</i></td><td><i>251</i></td>
352  <td>&ndash;</td>
353  <td><i>This enumeration value is only used internally and cannot
354  exist in a binlog.</i></td>
355  </tr>
356 
357  <tr>
358  <td>MYSQL_TYPE_BLOB</td><td>252</td>
359  <td>1 byte</td>
360  <td>The pack length, i.e., the number of bytes needed to represent
361  the length of the blob: 1, 2, 3, or 4.</td>
362  </tr>
363 
364  <tr>
365  <td>MYSQL_TYPE_VAR_STRING</td><td>253</td>
366  <td>2 bytes</td>
367  <td>This is used to store both strings and enumeration values.
368  The first byte is a enumeration value storing the <i>real
369  type</i>, which may be either MYSQL_TYPE_VAR_STRING or
370  MYSQL_TYPE_ENUM. The second byte is a 1 byte unsigned integer
371  representing the field size, i.e., the number of bytes needed to
372  store the length of the string.</td>
373  </tr>
374 
375  <tr>
376  <td>MYSQL_TYPE_STRING</td><td>254</td>
377  <td>2 bytes</td>
378  <td>The first byte is always MYSQL_TYPE_VAR_STRING (i.e., 253).
379  The second byte is the field size, i.e., the number of bytes in
380  the representation of size of the string: 3 or 4.</td>
381  </tr>
382 
383  <tr>
384  <td>MYSQL_TYPE_GEOMETRY</td><td>255</td>
385  <td>1 byte</td>
386  <td>The pack length, i.e., the number of bytes needed to represent
387  the length of the geometry: 1, 2, 3, or 4.</td>
388  </tr>
389 
390  <tr>
391  <td>MYSQL_TYPE_TYPED_ARRAY</td><td>15</td>
392  <td>up to 4 bytes</td>
393  <td>
394  - The first byte holds the MySQL type for the elements.
395  - The following 0, 1, 2, or 3 bytes holds the metadata for the MySQL
396  type for the elements. The contents of these bytes depends on the
397  element type, as described in the other rows of this table.
398  </td>
399  </tr>
400 
401  </table>
402 
403  The table below lists all optional metadata types, along with the numerical
404  identifier for it and the size and interpretation of meta-data used
405  to describe the type.
406 
407  @anchor Table_table_map_event_optional_metadata
408  <table>
409  <caption>Table_map_event optional metadata types: numerical identifier and
410  metadata. Optional metadata fields are stored in TLV fields.
411  Format of values are described in this table. </caption>
412  <tr>
413  <th>Type</th>
414  <th>Description</th>
415  <th>Format</th>
416  </tr>
417  <tr>
418  <td>SIGNEDNESS</td>
419  <td>signedness of numeric colums. This is included for all values of
420  binlog_row_metadata.</td>
421  <td>For each numeric column, a bit indicates whether the numeric
422  colunm has unsigned flag. 1 means it is unsigned. The number of
423  bytes needed for this is int((column_count + 7) / 8). The order is
424  the same as the order of column_type field.</td>
425  </tr>
426  <tr>
427  <td>DEFAULT_CHARSET</td>
428  <td>Charsets of character columns. It has a default charset for
429  the case that most of character columns have same charset and the
430  most used charset is binlogged as default charset.Collation
431  numbers are binlogged for identifying charsets. They are stored in
432  packed length format. Either DEFAULT_CHARSET or COLUMN_CHARSET is
433  included for all values of binlog_row_metadata.</td>
434  <td>Default charset's collation is logged first. The charsets which are not
435  same to default charset are logged following default charset. They are
436  logged as column index and charset collation number pair sequence. The
437  column index is counted only in all character columns. The order is same to
438  the order of column_type
439  field. </td>
440  </tr>
441  <tr>
442  <td>COLUMN_CHARSET</td>
443  <td>Charsets of character columns. For the case that most of columns have
444  different charsets, this field is logged. It is never logged with
445  DEFAULT_CHARSET together. Either DEFAULT_CHARSET or COLUMN_CHARSET is
446  included for all values of binlog_row_metadata.</td>
447  <td>It is a collation number sequence for all character columns.</td>
448  </tr>
449  <tr>
450  <td>COLUMN_NAME</td>
451  <td>Names of columns. This is only included if
452  binlog_row_metadata=FULL.</td>
453  <td>A sequence of column names. For each column name, 1 byte for
454  the string length in bytes is followed by a string without null
455  terminator.</td>
456  </tr>
457  <tr>
458  <td>SET_STR_VALUE</td>
459  <td>The string values of SET columns. This is only included if
460  binlog_row_metadata=FULL.</td>
461  <td>For each SET column, a pack_length representing the value
462  count is followed by a sequence of length and string pairs. length
463  is the byte count in pack_length format. The string has no null
464  terminator.</td>
465  </tr>
466  <tr>
467  <td>ENUM_STR_VALUE</td>
468  <td>The string values is ENUM columns. This is only included
469  if binlog_row_metadata=FULL.</td>
470  <td>The format is the same as SET_STR_VALUE.</td>
471  </tr>
472  <tr>
473  <td>GEOMETRY_TYPE</td>
474  <td>The real type of geometry columns. This is only included
475  if binlog_row_metadata=FULL.</td>
476  <td>A sequence of real type of geometry columns are stored in pack_length
477  format. </td>
478  </tr>
479  <tr>
480  <td>SIMPLE_PRIMARY_KEY</td>
481  <td>The primary key without any prefix. This is only included
482  if binlog_row_metadata=FULL and there is a primary key where every
483  key part covers an entire column.</td>
484  <td>A sequence of column indexes. The indexes are stored in pack_length
485  format.</td>
486  </tr>
487  <tr>
488  <td>PRIMARY_KEY_WITH_PREFIX</td>
489  <td>The primary key with some prefix. It doesn't appear together with
490  SIMPLE_PRIMARY_KEY. This is only included if
491  binlog_row_metadata=FULL and there is a primary key where some key
492  part covers a prefix of the column.</td>
493  <td>A sequence of column index and prefix length pairs. Both
494  column index and prefix length are in pack_length format. Prefix length
495  0 means that the whole column value is used.</td>
496  </tr>
497  <tr>
498  <td>ENUM_AND_SET_DEFAULT_CHARSET</td>
499  <td>Charsets of ENUM and SET columns. It has the same layout as
500  DEFAULT_CHARSET. If there are SET or ENUM columns and
501  binlog_row_metadata=FULL, exactly one of
502  ENUM_AND_SET_DEFAULT_CHARSET and ENUM_AND_SET_COLUMN_CHARSET
503  appears (the encoder chooses the representation that uses the
504  least amount of space). Otherwise, none of them appears.</td>
505  <td>The same format as for DEFAULT_CHARSET, except it counts ENUM
506  and SET columns rather than character columns.</td>
507  </tr>
508  <tr>
509  <td>ENUM_AND_SET_COLUMN_CHARSET</td>
510  <td>Charsets of ENUM and SET columns. It has the same layout as
511  COLUMN_CHARSET. If there are SET or ENUM columns and
512  binlog_row_metadata=FULL, exactly one of
513  ENUM_AND_SET_DEFAULT_CHARSET and ENUM_AND_SET_COLUMN_CHARSET
514  appears (the encoder chooses the representation that uses the
515  least amount of space). Otherwise, none of them appears.</td>
516  <td>The same format as for COLUMN_CHARSET, except it counts ENUM
517  and SET columns rather than character columns.</td>
518  </tr>
519  </table>
520 */
522  public:
523  /** Constants representing offsets */
525  /** TM = "Table Map" */
526  TM_MAPID_OFFSET = 0,
527  TM_FLAGS_OFFSET = 6
528  };
529 
530  typedef uint16_t flag_set;
531 
532  /**
533  DEFAULT_CHARSET and COLUMN_CHARSET don't appear together, and
534  ENUM_AND_SET_DEFAULT_CHARSET and ENUM_AND_SET_COLUMN_CHARSET don't
535  appear together. They are just alternative ways to pack character
536  set information. When binlogging, it logs character sets in the
537  way that occupies least storage.
538 
539  SIMPLE_PRIMARY_KEY and PRIMARY_KEY_WITH_PREFIX don't appear together.
540  SIMPLE_PRIMARY_KEY is for the primary keys which only use whole values of
541  pk columns. PRIMARY_KEY_WITH_PREFIX is
542  for the primary keys which just use part value of pk columns.
543  */
545  SIGNEDNESS = 1, // UNSIGNED flag of numeric columns
546  DEFAULT_CHARSET, /* Character set of string columns, optimized to
547  minimize space when many columns have the
548  same charset. */
549  COLUMN_CHARSET, /* Character set of string columns, optimized to
550  minimize space when columns have many
551  different charsets. */
553  SET_STR_VALUE, // String value of SET columns
554  ENUM_STR_VALUE, // String value of ENUM columns
555  GEOMETRY_TYPE, // Real type of geometry columns
556  SIMPLE_PRIMARY_KEY, // Primary key without prefix
557  PRIMARY_KEY_WITH_PREFIX, // Primary key with prefix
558  ENUM_AND_SET_DEFAULT_CHARSET, /* Character set of enum and set
559  columns, optimized to minimize
560  space when many columns have the
561  same charset. */
562  ENUM_AND_SET_COLUMN_CHARSET, /* Character set of enum and set
563  columns, optimized to minimize
564  space when many columns have the
565  same charset. */
566  };
567 
568  /**
569  Metadata_fields organizes m_optional_metadata into a structured format which
570  is easy to access.
571  */
573  typedef std::pair<unsigned int, unsigned int> uint_pair;
574  typedef std::vector<std::string> str_vector;
575 
578  bool empty() const { return default_charset == 0; }
579 
580  // Default charset for the columns which are not in charset_pairs.
581  unsigned int default_charset;
582 
583  /* The uint_pair means <column index, column charset number>. */
584  std::vector<uint_pair> charset_pairs;
585  };
586 
587  // Contents of DEFAULT_CHARSET field are converted into Default_charset.
589  // Contents of ENUM_AND_SET_DEFAULT_CHARSET are converted into
590  // Default_charset.
592  std::vector<bool> m_signedness;
593  // Character set number of every string column
594  std::vector<unsigned int> m_column_charset;
595  // Character set number of every ENUM or SET column.
596  std::vector<unsigned int> m_enum_and_set_column_charset;
597  std::vector<std::string> m_column_name;
598  // each str_vector stores values of one enum/set column
599  std::vector<str_vector> m_enum_str_value;
600  std::vector<str_vector> m_set_str_value;
601  std::vector<unsigned int> m_geometry_type;
602  /*
603  The uint_pair means <column index, prefix length>. Prefix length is 0 if
604  whole column value is used.
605  */
606  std::vector<uint_pair> m_primary_key;
607 
608  /*
609  It parses m_optional_metadata and populates into above variables.
610 
611  @param[in] optional_metadata points to the begin of optional metadata
612  fields in table_map_event.
613  @param[in] optional_metadata_len length of optional_metadata field.
614  */
615  Optional_metadata_fields(unsigned char *optional_metadata,
616  unsigned int optional_metadata_len);
617  // It is used to specify the validity of the deserialized structure
618  bool is_valid;
619  };
620 
621  /**
622  <pre>
623  The buffer layout for fixed data part is as follows:
624  +-----------------------------------+
625  | table_id | Reserved for future use|
626  +-----------------------------------+
627  </pre>
628 
629  <pre>
630  The buffer layout for variable data part is as follows:
631  +--------------------------------------------------------------------------+
632  | db len| db name | table len| table name | no of cols | array of col types|
633  +--------------------------------------------------------------------------+
634  +---------------------------------------------+
635  | metadata len | metadata block | m_null_bits |
636  +---------------------------------------------+
637  </pre>
638 
639  @param buf Contains the serialized event.
640  @param fde An FDE event (see Rotate_event constructor for more info).
641  */
642  Table_map_event(const char *buf, const Format_description_event *fde);
643 
644  Table_map_event(const Table_id &tid, unsigned long colcnt, const char *dbnam,
645  size_t dblen, const char *tblnam, size_t tbllen)
647  m_table_id(tid),
648  m_data_size(0),
649  m_dbnam(""),
650  m_dblen(dblen),
651  m_tblnam(""),
652  m_tbllen(tbllen),
653  m_colcnt(colcnt),
654  m_field_metadata_size(0),
655  m_field_metadata(nullptr),
656  m_null_bits(nullptr),
657  m_optional_metadata_len(0),
658  m_optional_metadata(nullptr) {
659  if (dbnam) m_dbnam = std::string(dbnam, m_dblen);
660  if (tblnam) m_tblnam = std::string(tblnam, m_tbllen);
661  }
662 
663  ~Table_map_event() override;
664 
665  /** Event post header contents */
667  flag_set m_flags;
668 
669  size_t m_data_size; /** event data size */
670 
671  /** Event body contents */
672  std::string m_dbnam;
673  size_t m_dblen;
674  std::string m_tblnam;
675  size_t m_tbllen;
676  unsigned long m_colcnt;
677  unsigned char *m_coltype;
678 
679  /**
680  The size of field metadata buffer set by calling save_field_metadata()
681  */
682  unsigned long m_field_metadata_size;
683  unsigned char *m_field_metadata; /** field metadata */
684  unsigned char *m_null_bits;
686  unsigned char *m_optional_metadata;
687 
690  m_coltype(nullptr),
691  m_field_metadata_size(0),
692  m_field_metadata(nullptr),
693  m_null_bits(nullptr),
694  m_optional_metadata_len(0),
695  m_optional_metadata(nullptr) {}
696 
697  unsigned long long get_table_id() { return m_table_id.id(); }
698  std::string get_table_name() { return m_tblnam; }
699  std::string get_db_name() { return m_dbnam; }
700 
701 #ifndef HAVE_MYSYS
702  void print_event_info(std::ostream &info) override;
703  void print_long_info(std::ostream &info) override;
704 #endif
705 };
706 
707 /**
708  @class Rows_event
709 
710  Common base class for all row-containing binary log events.
711 
712  RESPONSIBILITIES
713 
714  - Provide an interface for adding an individual row to the event.
715 
716  @section Rows_event_binary_format Binary Format
717 
718  The Post-Header has the following components:
719 
720  <table>
721  <caption>Post-Header for Rows_event</caption>
722 
723  <tr>
724  <th>Name</th>
725  <th>Format</th>
726  <th>Description</th>
727  </tr>
728 
729  <tr>
730  <td>table_id</td>
731  <td>6 bytes unsigned integer</td>
732  <td>The number that identifies the table</td>
733  </tr>
734 
735  <tr>
736  <td>flags</td>
737  <td>2 byte bitfield</td>
738  <td>Reserved for future use; currently always 0.</td>
739  </tr>
740 
741  </table>
742 
743  The Body has the following components:
744 
745  <table>
746  <caption>Body for Rows_event</caption>
747 
748  <tr>
749  <th>Name</th>
750  <th>Format</th>
751  <th>Description</th>
752  </tr>
753 
754 
755  <tr>
756  <td>width</td>
757  <td>packed integer</td>
758  <td>Represents the number of columns in the table</td>
759  </tr>
760 
761  <tr>
762  <td>cols</td>
763  <td>Bitfield, variable sized</td>
764  <td>Indicates whether each column is used, one bit per column.
765  For this field, the amount of storage required is
766  INT((width + 7) / 8) bytes. </td>
767  </tr>
768 
769  <tr>
770  <td>extra_row_info</td>
771  <td>An object of class Extra_row_info</td>
772  <td>The class Extra_row_info will be storing the information related
773  to m_extra_row_ndb_info and partition info (partition_id and
774  source_partition_id). At any given time a Rows_event can have both, one
775  or none of ndb_info and partition_info present as part of Rows_event.
776  In case both ndb_info and partition_info are present then below will
777  be the order in which they will be stored.
778 
779  @verbatim
780  +----------+--------------------------------------+
781  |type_code | extra_row_ndb_info |
782  +--- ------+--------------------------------------+
783  | NDB |Len of ndb_info |Format |ndb_data |
784  | 1 byte |1 byte |1 byte |len - 2 byte |
785  +----------+----------------+-------+-------------+
786 
787  In case of INSERT/DELETE
788  +-----------+----------------+
789  | type_code | partition_info |
790  +-----------+----------------+
791  | PART | partition_id |
792  | (1 byte) | 2 byte |
793  +-----------+----------------+
794 
795  In case of UPDATE
796  +-----------+------------------------------------+
797  | type_code | partition_info |
798  +-----------+--------------+---------------------+
799  | PART | partition_id | source_partition_id |
800  | (1 byte) | 2 byte | 2 byte |
801  +-----------+--------------+---------------------+
802 
803  source_partition_id is used only in the case of Update_event
804  to log the partition_id of the source partition.
805 
806  @endverbatim
807  This is the format for any information stored as extra_row_info.
808  type_code is not a part of the class Extra_row_info as it is a constant
809  values used at the time of serializing and decoding the event.
810  </td>
811  </tr>
812 
813  <tr>
814  <td>columns_before_image</td>
815  <td>vector of elements of type uint8_t</td>
816  <td>For DELETE and UPDATE only.
817  Bit-field indicating whether each column is used
818  one bit per column. For this field, the amount of storage
819  required for N columns is INT((N + 7) / 8) bytes.</td>
820  </tr>
821 
822  <tr>
823  <td>columns_after_image</td>
824  <td>vector of elements of type uint8_t</td>
825  <td>For WRITE and UPDATE only.
826  Bit-field indicating whether each column is used in the
827  UPDATE_ROWS_EVENT and WRITE_ROWS_EVENT after-image; one bit per column.
828  For this field, the amount of storage required for N columns
829  is INT((N + 7) / 8) bytes.
830 
831  @verbatim
832  +-------------------------------------------------------+
833  | Event Type | Cols_before_image | Cols_after_image |
834  +-------------------------------------------------------+
835  | DELETE | Deleted row | NULL |
836  | INSERT | NULL | Inserted row |
837  | UPDATE | Old row | Updated row |
838  +-------------------------------------------------------+
839  @endverbatim
840  </td>
841  </tr>
842 
843  <tr>
844  <td>row</td>
845  <td>vector of elements of type uint8_t</td>
846  <td> A sequence of zero or more rows. The end is determined by the size
847  of the event. Each row has the following format:
848  - A Bit-field indicating whether each field in the row is NULL.
849  Only columns that are "used" according to the second field in
850  the variable data part are listed here. If the second field in
851  the variable data part has N one-bits, the amount of storage
852  required for this field is INT((N + 7) / 8) bytes.
853  - The row-image, containing values of all table fields. This only
854  lists table fields that are used (according to the second field
855  of the variable data part) and non-NULL (according to the
856  previous field). In other words, the number of values listed here
857  is equal to the number of zero bits in the previous field.
858  (not counting padding bits in the last byte).
859  @verbatim
860  For example, if a INSERT statement inserts into 4 columns of a
861  table, N= 4 (in the formula above).
862  length of bitmask= (4 + 7) / 8 = 1
863  Number of fields in the row= 4.
864 
865  +------------------------------------------------+
866  |Null_bit_mask(4)|field-1|field-2|field-3|field 4|
867  +------------------------------------------------+
868  @endverbatim
869  </td>
870  </tr>
871  </table>
872 */
873 class Rows_event : public Binary_log_event {
874  public:
875  /**
876  These definitions allow to combine the flags into an
877  appropriate flag set using the normal bitwise operators. The
878  implicit conversion from an enum-constant to an integer is
879  accepted by the compiler, which is then used to set the real set
880  of flags.
881  */
882  enum enum_flag {
883  /** Last event of a statement */
884  STMT_END_F = (1U << 0),
885  /** Value of the OPTION_NO_FOREIGN_KEY_CHECKS flag in thd->options */
886  NO_FOREIGN_KEY_CHECKS_F = (1U << 1),
887  /** Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in thd->options */
888  RELAXED_UNIQUE_CHECKS_F = (1U << 2),
889  /**
890  Indicates that rows in this event are complete, that is contain
891  values for all columns of the table.
892  */
893  COMPLETE_ROWS_F = (1U << 3)
894  };
895 
896  /**
897  Constructs an event directly. The members are assigned default values.
898 
899  @param type_arg Type of ROW_EVENT. Expected types are:
900  - WRITE_ROWS_EVENT, WRITE_ROWS_EVENT_V1
901  - UPDATE_ROWS_EVENT, UPDATE_ROWS_EVENT_V1,
902  PARTIAL_UPDATE_ROWS_EVENT
903  - DELETE_ROWS_EVENT, DELETE_ROWS_EVENT_V1
904  */
905  explicit Rows_event(Log_event_type type_arg)
906  : Binary_log_event(type_arg),
907  m_table_id(0),
908  m_width(0),
909  columns_before_image(0),
910  columns_after_image(0),
911  row(0) {}
912  /**
913  The constructor is responsible for decoding the event contained in
914  the buffer.
915 
916  <pre>
917  The buffer layout for fixed data part is as follows
918  +------------------------------------+
919  | table_id | reserved for future use |
920  +------------------------------------+
921  </pre>
922 
923  <pre>
924  The buffer layout for variable data part is as follows
925  +------------------------------------------------------------------+
926  | var_header_len | column_before_image | columns_after_image | row |
927  +------------------------------------------------------------------+
928  </pre>
929 
930  @param buf Contains the serialized event.
931  @param fde An FDE event (see Rotate_event constructor for more info).
932  */
933  Rows_event(const char *buf, const Format_description_event *fde);
934 
935  ~Rows_event() override;
936 
937  protected:
938  Log_event_type m_type; /** Actual event type */
939 
940  /** Post header content */
942  uint16_t m_flags; /** Flags for row-level events */
943 
944  /* Body of the event */
945  unsigned long m_width; /** The width of the columns bitmap */
946  uint32_t n_bits_len; /** value determined by (m_width + 7) / 8 */
947  uint16_t var_header_len;
948 
949  std::vector<uint8_t> columns_before_image;
950  std::vector<uint8_t> columns_after_image;
951  std::vector<uint8_t> row;
952 
953  public:
955  private:
956  /** partition_id for a row in a partitioned table */
958  /**
959  It is the partition_id of the source partition in case
960  of Update_event, the target's partition_id is m_partition_id.
961  This variable is used only in case of Update_event.
962  */
964  /** The extra row info provided by NDB */
965  unsigned char *m_extra_row_ndb_info;
966 
967  public:
969  : m_partition_id(UNDEFINED),
970  m_source_partition_id(UNDEFINED),
971  m_extra_row_ndb_info(nullptr) {}
972 
973  Extra_row_info(const Extra_row_info &) = delete;
974 
975  int get_partition_id() const { return m_partition_id; }
976  void set_partition_id(int partition_id) {
977  BAPI_ASSERT(partition_id <= 65535);
978  m_partition_id = partition_id;
979  }
980 
981  int get_source_partition_id() const { return m_source_partition_id; }
982  void set_source_partition_id(int source_partition_id) {
983  BAPI_ASSERT(source_partition_id <= 65535);
984  m_source_partition_id = source_partition_id;
985  }
986 
987  unsigned char *get_ndb_info() const { return m_extra_row_ndb_info; }
988  void set_ndb_info(const unsigned char *ndb_info, size_t len) {
989  BAPI_ASSERT(!have_ndb_info());
990  m_extra_row_ndb_info =
991  static_cast<unsigned char *>(bapi_malloc(len, 16 /* flags */));
992  std::copy(ndb_info, ndb_info + len, m_extra_row_ndb_info);
993  }
994  /**
995  Compares the extra_row_info in a Row event, it checks three things
996  1. The m_extra_row_ndb_info pointers. It compares their significant bytes.
997  2. Partition_id
998  3. source_partition_id
999 
1000  @return
1001  true all the above variables are same in the event and the one passed
1002  in parameter.
1003  false Any of the above variable has a different value.
1004  */
1005  bool compare_extra_row_info(const unsigned char *ndb_info_arg,
1006  int part_id_arg, int source_part_id);
1007 
1008  bool have_part() const { return m_partition_id != UNDEFINED; }
1009 
1010  bool have_ndb_info() const { return m_extra_row_ndb_info != nullptr; }
1011  size_t get_ndb_length();
1012  size_t get_part_length();
1013  ~Extra_row_info();
1014 
1015  static const int UNDEFINED{INT_MAX};
1016  };
1018 
1019  unsigned long long get_table_id() const { return m_table_id.id(); }
1020 
1021  enum_flag get_flags() const { return static_cast<enum_flag>(m_flags); }
1022 
1023  uint32_t get_null_bits_len() const { return n_bits_len; }
1024 
1025  unsigned long get_width() const { return m_width; }
1026 
1027  static std::string get_flag_string(enum_flag flag) {
1028  std::string str = "";
1029  if (flag & STMT_END_F) str.append(" Last event of the statement");
1030  if (flag & NO_FOREIGN_KEY_CHECKS_F) str.append(" No foreign Key checks");
1031  if (flag & RELAXED_UNIQUE_CHECKS_F) str.append(" No unique key checks");
1032  if (flag & COMPLETE_ROWS_F) str.append(" Complete Rows");
1033  if (flag & ~(STMT_END_F | NO_FOREIGN_KEY_CHECKS_F |
1034  RELAXED_UNIQUE_CHECKS_F | COMPLETE_ROWS_F))
1035  str.append("Unknown Flag");
1036  return str;
1037  }
1038 #ifndef HAVE_MYSYS
1039  void print_event_info(std::ostream &info) override;
1040  void print_long_info(std::ostream &info) override;
1041 #endif
1042 
1043  template <class Iterator_value_type>
1044  friend class Row_event_iterator;
1045 };
1046 
1047 /**
1048  @class Write_rows_event
1049 
1050  Log row insertions. The event contain several insert/update rows
1051  for a table. Note that each event contains only rows for one table.
1052 
1053  @section Write_rows_event_binary_format Binary Format
1054 */
1055 class Write_rows_event : public virtual Rows_event {
1056  public:
1057  Write_rows_event(const char *buf, const Format_description_event *fde);
1059 };
1060 
1061 /**
1062  @class Update_rows_event
1063 
1064  Log row updates with a before image. The event contain several
1065  update rows for a table. Note that each event contains only rows for
1066  one table.
1067 
1068  Also note that the row data consists of pairs of row data: one row
1069  for the old data and one row for the new data.
1070 
1071  @section Update_rows_event_binary_format Binary Format
1072 */
1073 class Update_rows_event : public virtual Rows_event {
1074  public:
1075  Update_rows_event(const char *buf, const Format_description_event *fde);
1077 };
1078 
1079 /**
1080  @class Delete_rows_event
1081 
1082  Log row deletions. The event contain several delete rows for a
1083  table. Note that each event contains only rows for one table.
1084 
1085  RESPONSIBILITIES
1086 
1087  - Act as a container for rows that has been deleted on the master
1088  and should be deleted on the slave.
1089 
1090  @section Delete_rows_event_binary_format Binary Format
1091 */
1092 class Delete_rows_event : public virtual Rows_event {
1093  public:
1094  Delete_rows_event(const char *buf, const Format_description_event *fde);
1096 };
1097 
1098 /**
1099  @class Rows_query_event
1100 
1101  Rows query event type, which is a subclass
1102  of the Ignorable_event, to record the original query for the rows
1103  events in RBR. This event can be used to display the original query as
1104  comments by SHOW BINLOG EVENTS query, or mysqlbinlog client when the
1105  --verbose option is given twice
1106 
1107  @section Rows_query_var_event_binary_format Binary Format
1108 
1109  The Post-Header for this event type is empty. The Body has one
1110  component:
1111 
1112  <table>
1113  <caption>Body for Rows_query_event</caption>
1114 
1115  <tr>
1116  <th>Name</th>
1117  <th>Format</th>
1118  <th>Description</th>
1119  </tr>
1120 
1121  <tr>
1122  <td>m_rows_query</td>
1123  <td>char array</td>
1124  <td>Records the original query executed in RBR </td>
1125  </tr>
1126  </table>
1127 */
1128 class Rows_query_event : public virtual Ignorable_event {
1129  public:
1130  /**
1131  It is used to write the original query in the binlog file in case of RBR
1132  when the session flag binlog_rows_query_log_events is set.
1133 
1134  <pre>
1135  The buffer layout is as follows:
1136  +------------------------------------+
1137  | The original query executed in RBR |
1138  +------------------------------------+
1139  </pre>
1140 
1141  @param buf Contains the serialized event.
1142  @param fde An FDE event (see Rotate_event constructor for more info).
1143  */
1144 
1145  Rows_query_event(const char *buf, const Format_description_event *fde);
1146  /**
1147  It is the minimal constructor, and all it will do is set the type_code as
1148  ROWS_QUERY_LOG_EVENT in the header object in Binary_log_event.
1149  */
1151  : Ignorable_event(ROWS_QUERY_LOG_EVENT), m_rows_query(nullptr) {}
1152 
1153  ~Rows_query_event() override;
1154 
1155  protected:
1157 };
1158 } // namespace binary_log
1159 
1160 /**
1161  @} (end of group Replication)
1162 */
1163 #endif /* ROWS_EVENT_INCLUDED */
std::vector< bool > m_signedness
Definition: rows_event.h:592
unsigned char * m_coltype
Definition: rows_event.h:677
Base class for ignorable log events.
Definition: control_events.h:651
int get_source_partition_id() const
Definition: rows_event.h:981
Write_rows_event()
Definition: rows_event.h:1058
Default_charset m_enum_and_set_default_charset
Definition: rows_event.h:591
Default_charset m_default_charset
Definition: rows_event.h:588
Update_rows_event(Log_event_type event_type)
Definition: rows_event.h:1076
unsigned char * m_field_metadata
Definition: rows_event.h:683
size_t m_tbllen
Definition: rows_event.h:675
unsigned long get_width() const
Definition: rows_event.h:1025
uint32_t get_null_bits_len() const
Definition: rows_event.h:1023
uint16_t var_header_len
value determined by (m_width + 7) / 8
Definition: rows_event.h:947
std::vector< std::string > str_vector
Definition: rows_event.h:574
enum_flag
These definitions allow to combine the flags into an appropriate flag set using the normal bitwise op...
Definition: rows_event.h:882
unsigned long long id() const
Definition: table_id.h:49
std::string get_db_name()
Definition: rows_event.h:699
MySQL chooses which algorithm to use.
Definition: mysqlx_crud.proto:334
This is the abstract base class for binary log events.
Definition: binlog_event.h:797
std::vector< uint8_t > row
Definition: rows_event.h:951
unsigned char * m_extra_row_ndb_info
The extra row info provided by NDB.
Definition: rows_event.h:965
Log row deletions.
Definition: rows_event.h:1092
Version 2 of the Row events.
Definition: binlog_event.h:326
std::vector< unsigned int > m_enum_and_set_column_charset
Definition: rows_event.h:596
Contains the class Table_id, mainly used for row based replication.
std::vector< str_vector > m_enum_str_value
Definition: rows_event.h:599
Log row updates with a before image.
Definition: rows_event.h:1073
Definition: buf0block_hint.cc:29
std::vector< uint8_t > columns_before_image
Definition: rows_event.h:949
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:265
uint16_t flag_set
Definition: rows_event.h:530
const char * default_charset
Definition: mysqladmin.cc:60
Extra_row_info()
Definition: rows_event.h:968
flag_set m_flags
Definition: rows_event.h:667
unsigned long m_width
Flags for row-level events.
Definition: rows_event.h:945
Common base class for all row-containing binary log events.
Definition: rows_event.h:873
Metadata_fields organizes m_optional_metadata into a structured format which is easy to access...
Definition: rows_event.h:572
std::string get_table_name()
Definition: rows_event.h:698
std::vector< unsigned int > m_geometry_type
Definition: rows_event.h:601
static std::string get_flag_string(enum_flag flag)
Definition: rows_event.h:1027
int m_source_partition_id
It is the partition_id of the source partition in case of Update_event, the target&#39;s partition_id is ...
Definition: rows_event.h:963
uint16_t m_flags
Definition: rows_event.h:942
std::vector< uint8_t > columns_after_image
Definition: rows_event.h:950
std::vector< uint_pair > charset_pairs
Definition: rows_event.h:584
Rows query event type, which is a subclass of the Ignorable_event, to record the original query for t...
Definition: rows_event.h:1128
size_t m_dblen
Definition: rows_event.h:673
Definition: rows_event.h:555
enum_flag get_flags() const
Definition: rows_event.h:1021
Definition: rows_event.h:954
Rows_event(Log_event_type type_arg)
Constructs an event directly.
Definition: rows_event.h:905
std::vector< unsigned int > m_column_charset
Definition: rows_event.h:594
std::vector< str_vector > m_set_str_value
Definition: rows_event.h:600
Extra_row_info m_extra_row_info
Definition: rows_event.h:1017
char * m_rows_query
Definition: rows_event.h:1156
Table_id m_table_id
Actual event type.
Definition: rows_event.h:941
unsigned long m_field_metadata_size
The size of field metadata buffer set by calling save_field_metadata()
Definition: rows_event.h:682
std::string m_tblnam
Definition: rows_event.h:674
unsigned long long get_table_id()
Definition: rows_event.h:697
bool have_ndb_info() const
Definition: rows_event.h:1010
Table_map_event()
Definition: rows_event.h:688
In row-based mode, every row operation event is preceded by a Table_map_event which maps a table defi...
Definition: rows_event.h:521
enum_extra_row_info_typecode
This is the typecode defined for the different elements present in the container Extra_row_info, this is different from the format information stored inside extra_row_ndb_info at EXTRA_ROW_INFO_FORMAT_OFFSET.
Definition: rows_event.h:62
#define BAPI_ASSERT(x)
Definition: wrapper_functions.h:61
std::pair< unsigned int, unsigned int > uint_pair
Definition: rows_event.h:573
Optional_metadata_field_type
DEFAULT_CHARSET and COLUMN_CHARSET don&#39;t appear together, and ENUM_AND_SET_DEFAULT_CHARSET and ENUM_A...
Definition: rows_event.h:544
void * bapi_malloc(size_t size, int flags)
This is a wrapper function in order to allocate memory from the heap in the binlogevent library...
Definition: wrapper_functions.h:169
void set_source_partition_id(int source_partition_id)
Definition: rows_event.h:982
For binlog version 4.
Definition: control_events.h:230
Delete_rows_event()
Definition: rows_event.h:1095
Each table share has a table id, it is mainly used for row based replication.
Definition: table_id.h:39
Definition: rows_event.h:552
unsigned long long get_table_id() const
Definition: rows_event.h:1019
unsigned long m_colcnt
Definition: rows_event.h:676
static int flag
Definition: hp_test1.cc:39
Table_map_event(const Table_id &tid, unsigned long colcnt, const char *dbnam, size_t dblen, const char *tblnam, size_t tbllen)
Definition: rows_event.h:644
int get_partition_id() const
Definition: rows_event.h:975
size_t m_data_size
Definition: rows_event.h:669
void set_partition_id(int partition_id)
Definition: rows_event.h:976
unsigned char * get_ndb_info() const
Definition: rows_event.h:987
Rows_query_event()
It is the minimal constructor, and all it will do is set the type_code as ROWS_QUERY_LOG_EVENT in the...
Definition: rows_event.h:1150
bool have_part() const
Definition: rows_event.h:1008
unsigned int m_optional_metadata_len
Definition: rows_event.h:685
int m_partition_id
partition_id for a row in a partitioned table
Definition: rows_event.h:957
unsigned char * m_optional_metadata
Definition: rows_event.h:686
The namespace contains classes representing events that can occur in a replication stream...
std::vector< uint_pair > m_primary_key
Definition: rows_event.h:606
uint32_t n_bits_len
The width of the columns bitmap.
Definition: rows_event.h:946
Log info(cout, "NOTE")
Table_id m_table_id
Event post header contents.
Definition: rows_event.h:666
event_type
Definition: test_pfs_resource_group.cc:70
Log_event_type m_type
Definition: rows_event.h:938
Definition: binlog_event.h:328
Table_map_event_offset
Constants representing offsets.
Definition: rows_event.h:524
Contains the classes representing events operating in the replication stream properties.
void set_ndb_info(const unsigned char *ndb_info, size_t len)
Definition: rows_event.h:988
std::string m_dbnam
event data size
Definition: rows_event.h:672
std::vector< std::string > m_column_name
Definition: rows_event.h:597
Log row insertions.
Definition: rows_event.h:1055
Definition: dtoa.cc:601
unsigned char * m_null_bits
field metadata
Definition: rows_event.h:684
Definition: rows_event.h:553
Definition: binlog_event.h:296
Dialog Client Authentication nullptr
Definition: dialog.cc:353
Definition: binlog_event.h:323