MySQL 8.0.40
Source Code Documentation
|
In row-based mode, every row operation event is preceded by a Table_map_event which maps a table definition to a number. More...
#include <rows_event.h>
Classes | |
struct | Optional_metadata_fields |
Metadata_fields organizes m_optional_metadata into a structured format which is easy to access. More... | |
Public Member Functions | |
Table_map_event (const char *buf, const Format_description_event *fde) | |
Table_map_event (const Table_id &tid, unsigned long colcnt, const char *dbnam, size_t dblen, const char *tblnam, size_t tbllen) | |
~Table_map_event () override | |
Table_map_event () | |
unsigned long long | get_table_id () |
std::string | get_table_name () |
std::string | get_db_name () |
Public Member Functions inherited from binary_log::Binary_log_event | |
virtual | ~Binary_log_event ()=0 |
Binary_log_event (const Binary_log_event &)=default | |
Binary_log_event (Binary_log_event &&)=default | |
Binary_log_event & | operator= (const Binary_log_event &)=default |
Binary_log_event & | operator= (Binary_log_event &&)=default |
enum Log_event_type | get_event_type () const |
Helper method. More... | |
const Log_event_header * | header () const |
Return a const pointer to the header of the log event. More... | |
Log_event_header * | header () |
Return a non-const pointer to the header of the log event. More... | |
const Log_event_footer * | footer () const |
Return a const pointer to the footer of the log event. More... | |
Log_event_footer * | footer () |
Return a non-const pointer to the footer of the log event. More... | |
Event_reader & | reader () |
Returns a reference to the event Event_reader object. More... | |
Public Attributes | |
Table_id | m_table_id |
Event post header contents. More... | |
flag_set | m_flags |
size_t | m_data_size |
std::string | m_dbnam |
event data size More... | |
unsigned long long int | m_dblen |
std::string | m_tblnam |
unsigned long long int | m_tbllen |
unsigned long | m_colcnt |
unsigned char * | m_coltype |
unsigned long | m_field_metadata_size |
The size of field metadata buffer set by calling save_field_metadata() More... | |
unsigned char * | m_field_metadata |
unsigned char * | m_null_bits |
field metadata More... | |
unsigned int | m_optional_metadata_len |
unsigned char * | m_optional_metadata |
Additional Inherited Members | |
Static Public Attributes inherited from binary_log::Binary_log_event | |
static const int | LOG_EVENT_TYPES = (ENUM_END_EVENT - 1) |
Protected Member Functions inherited from binary_log::Binary_log_event | |
Binary_log_event (Log_event_type type_code) | |
This constructor is used to initialize the type_code of header object m_header. More... | |
Binary_log_event (const char **buf, const Format_description_event *fde) | |
This constructor will create a new object of Log_event_header and initialize the variable m_header, which in turn will be used to initialize Log_event's member common_header. More... | |
In row-based mode, every row operation event is preceded by a Table_map_event which maps a table definition to a number.
The table definition consists of database name, table name, and column definitions.
The Post-Header has the following components:
Name | Format | Description |
---|---|---|
table_id | 6 bytes unsigned integer | The number that identifies the table. |
flags | 2 byte bitfield | Reserved for future use; currently always 0. |
The Body has the following components:
Name | Format | Description |
---|---|---|
database_name | one byte string length, followed by null-terminated string | The name of the database in which the table resides. The name is represented as a packed variable-length integer representing the number of bytes in the name, followed by length bytes containing the database name, followed by a terminating 0 byte. (Note the redundancy in the representation of the length.) |
table_name | The table name is represented as a packed variable-length integer representing the number of bytes in the name, followed by null-terminated string | The name of the table, encoded the same way as the database name above. |
column_count | Packed Integer | The number of columns in the table, represented as a packed variable-length integer. |
column_type | List of column_count 1 byte enumeration values | The type of each column in the table, listed from left to right. Each byte is mapped to a column type according to the enumeration type enum_field_types defined in mysql_com.h. The mapping of types to numbers is listed in the table below (along with description of the associated metadata field). |
metadata_length | Packed Integer | The length of the following metadata block |
metadata | list of metadata for each column | For each column from left to right, a chunk of data who's length and semantics depends on the type of the column. The length and semantics for the metadata for each column are listed in the table below. |
null_bits | column_count bits, rounded up to nearest byte | For each column, a bit indicating whether data in the column can be NULL or not. The number of bytes needed for this is int((column_count + 7) / 8). The flag for the first column from the left is in the least-significant bit of the first byte, the second is in the second least significant bit of the first byte, the ninth is in the least significant bit of the second byte, and so on. |
optional metadata fields | optional metadata fields are stored in Type, Length, Value(TLV) format. Type takes 1 byte. Length is a packed integer value. Values takes Length bytes. | There are some optional metadata defined. They are listed in the table Table_table_map_event_optional_metadata. Optional metadata fields follow null_bits. Whether binlogging an optional metadata is decided by the server. The order is not defined, so they can be binlogged in any order. |
The table below lists all column types, along with the numerical identifier for it and the size and interpretation of meta-data used to describe the type.
Name | Identifier | Size of metadata in bytes | Description of metadata |
---|---|---|---|
MYSQL_TYPE_DECIMAL | 0 | 0 | No column metadata. |
MYSQL_TYPE_TINY | 1 | 0 | No column metadata. |
MYSQL_TYPE_SHORT | 2 | 0 | No column metadata. |
MYSQL_TYPE_LONG | 3 | 0 | No column metadata. |
MYSQL_TYPE_FLOAT | 4 | 1 byte | 1 byte unsigned integer, representing the "pack_length", which is equal to sizeof(float) on the server from which the event originates. |
MYSQL_TYPE_DOUBLE | 5 | 1 byte | 1 byte unsigned integer, representing the "pack_length", which is equal to sizeof(double) on the server from which the event originates. |
MYSQL_TYPE_NULL | 6 | 0 | No column metadata. |
MYSQL_TYPE_TIMESTAMP | 7 | 0 | No column metadata. |
MYSQL_TYPE_LONGLONG | 8 | 0 | No column metadata. |
MYSQL_TYPE_INT24 | 9 | 0 | No column metadata. |
MYSQL_TYPE_DATE | 10 | 0 | No column metadata. |
MYSQL_TYPE_TIME | 11 | 0 | No column metadata. |
MYSQL_TYPE_DATETIME | 12 | 0 | No column metadata. |
MYSQL_TYPE_YEAR | 13 | 0 | No column metadata. |
MYSQL_TYPE_NEWDATE | 14 | – | This enumeration value is only used internally and cannot exist in a binlog. |
MYSQL_TYPE_VARCHAR | 15 | 2 bytes | 2 byte unsigned integer representing the maximum length of the string. |
MYSQL_TYPE_BIT | 16 | 2 bytes | A 1 byte unsigned int representing the length in bits of the bitfield (0 to 64), followed by a 1 byte unsigned int representing the number of bytes occupied by the bitfield. The number of bytes is either int((length + 7) / 8) or int(length / 8). |
MYSQL_TYPE_NEWDECIMAL | 246 | 2 bytes | A 1 byte unsigned int representing the precision, followed by a 1 byte unsigned int representing the number of decimals. |
MYSQL_TYPE_ENUM | 247 | – | This enumeration value is only used internally and cannot exist in a binlog. |
MYSQL_TYPE_SET | 248 | – | This enumeration value is only used internally and cannot exist in a binlog. |
MYSQL_TYPE_TINY_BLOB | 249 | – | This enumeration value is only used internally and cannot exist in a binlog. |
MYSQL_TYPE_MEDIUM_BLOB | 250 | – | This enumeration value is only used internally and cannot exist in a binlog. |
MYSQL_TYPE_LONG_BLOB | 251 | – | This enumeration value is only used internally and cannot exist in a binlog. |
MYSQL_TYPE_BLOB | 252 | 1 byte | The pack length, i.e., the number of bytes needed to represent the length of the blob: 1, 2, 3, or 4. |
MYSQL_TYPE_VAR_STRING | 253 | 2 bytes | This is used to store both strings and enumeration values. The first byte is a enumeration value storing the real type, which may be either MYSQL_TYPE_VAR_STRING or MYSQL_TYPE_ENUM. The second byte is a 1 byte unsigned integer representing the field size, i.e., the number of bytes needed to store the length of the string. |
MYSQL_TYPE_STRING | 254 | 2 bytes | The first byte is always MYSQL_TYPE_VAR_STRING (i.e., 253). The second byte is the field size, i.e., the number of bytes in the representation of size of the string: 3 or 4. |
MYSQL_TYPE_GEOMETRY | 255 | 1 byte | The pack length, i.e., the number of bytes needed to represent the length of the geometry: 1, 2, 3, or 4. |
MYSQL_TYPE_TYPED_ARRAY | 15 | up to 4 bytes |
|
The table below lists all optional metadata types, along with the numerical identifier for it and the size and interpretation of meta-data used to describe the type.
Type | Description | Format |
---|---|---|
SIGNEDNESS | signedness of numeric columns. This is included for all values of binlog_row_metadata. | For each numeric column, a bit indicates whether the numeric colunm has unsigned flag. 1 means it is unsigned. The number of bytes needed for this is int((column_count + 7) / 8). The order is the same as the order of column_type field. |
DEFAULT_CHARSET | Charsets of character columns. It has a default charset for the case that most of character columns have same charset and the most used charset is binlogged as default charset.Collation numbers are binlogged for identifying charsets. They are stored in packed length format. Either DEFAULT_CHARSET or COLUMN_CHARSET is included for all values of binlog_row_metadata. | Default charset's collation is logged first. The charsets which are not same to default charset are logged following default charset. They are logged as column index and charset collation number pair sequence. The column index is counted only in all character columns. The order is same to the order of column_type field. |
COLUMN_CHARSET | Charsets of character columns. For the case that most of columns have different charsets, this field is logged. It is never logged with DEFAULT_CHARSET together. Either DEFAULT_CHARSET or COLUMN_CHARSET is included for all values of binlog_row_metadata. | It is a collation number sequence for all character columns. |
COLUMN_NAME | Names of columns. This is only included if binlog_row_metadata=FULL. | A sequence of column names. For each column name, 1 byte for the string length in bytes is followed by a string without null terminator. |
SET_STR_VALUE | The string values of SET columns. This is only included if binlog_row_metadata=FULL. | For each SET column, a pack_length representing the value count is followed by a sequence of length and string pairs. length is the byte count in pack_length format. The string has no null terminator. |
ENUM_STR_VALUE | The string values is ENUM columns. This is only included if binlog_row_metadata=FULL. | The format is the same as SET_STR_VALUE. |
GEOMETRY_TYPE | The real type of geometry columns. This is only included if binlog_row_metadata=FULL. | A sequence of real type of geometry columns are stored in pack_length format. |
SIMPLE_PRIMARY_KEY | The primary key without any prefix. This is only included if binlog_row_metadata=FULL and there is a primary key where every key part covers an entire column. | A sequence of column indexes. The indexes are stored in pack_length format. |
PRIMARY_KEY_WITH_PREFIX | The primary key with some prefix. It doesn't appear together with SIMPLE_PRIMARY_KEY. This is only included if binlog_row_metadata=FULL and there is a primary key where some key part covers a prefix of the column. | A sequence of column index and prefix length pairs. Both column index and prefix length are in pack_length format. Prefix length 0 means that the whole column value is used. |
ENUM_AND_SET_DEFAULT_CHARSET | Charsets of ENUM and SET columns. It has the same layout as DEFAULT_CHARSET. If there are SET or ENUM columns and binlog_row_metadata=FULL, exactly one of ENUM_AND_SET_DEFAULT_CHARSET and ENUM_AND_SET_COLUMN_CHARSET appears (the encoder chooses the representation that uses the least amount of space). Otherwise, none of them appears. | The same format as for DEFAULT_CHARSET, except it counts ENUM and SET columns rather than character columns. |
ENUM_AND_SET_COLUMN_CHARSET | Charsets of ENUM and SET columns. It has the same layout as COLUMN_CHARSET. If there are SET or ENUM columns and binlog_row_metadata=FULL, exactly one of ENUM_AND_SET_DEFAULT_CHARSET and ENUM_AND_SET_COLUMN_CHARSET appears (the encoder chooses the representation that uses the least amount of space). Otherwise, none of them appears. | The same format as for COLUMN_CHARSET, except it counts ENUM and SET columns rather than character columns. |
typedef uint16_t binary_log::Table_map_event::flag_set |
DEFAULT_CHARSET and COLUMN_CHARSET don't appear together, and ENUM_AND_SET_DEFAULT_CHARSET and ENUM_AND_SET_COLUMN_CHARSET don't appear together.
They are just alternative ways to pack character set information. When binlogging, it logs character sets in the way that occupies least storage.
SIMPLE_PRIMARY_KEY and PRIMARY_KEY_WITH_PREFIX don't appear together. SIMPLE_PRIMARY_KEY is for the primary keys which only use whole values of pk columns. PRIMARY_KEY_WITH_PREFIX is for the primary keys which just use part value of pk columns.
binary_log::Table_map_event::Table_map_event | ( | const char * | buf, |
const Format_description_event * | fde | ||
) |
The buffer layout for fixed data part is as follows: +-----------------------------------+ | table_id | Reserved for future use| +-----------------------------------+
The buffer layout for variable data part is as follows: +--------------------------------------------------------------------------+ | db len| db name | table len| table name | no of cols | array of col types| +--------------------------------------------------------------------------+ +---------------------------------------------+ | metadata len | metadata block | m_null_bits | +---------------------------------------------+
buf | Contains the serialized event. |
fde | An FDE event (see Rotate_event constructor for more info). |
|
inline |
|
override |
|
inline |
|
inline |
|
inline |
|
inline |
unsigned long binary_log::Table_map_event::m_colcnt |
unsigned char* binary_log::Table_map_event::m_coltype |
size_t binary_log::Table_map_event::m_data_size |
unsigned long long int binary_log::Table_map_event::m_dblen |
std::string binary_log::Table_map_event::m_dbnam |
event data size
Event body contents
unsigned char* binary_log::Table_map_event::m_field_metadata |
unsigned long binary_log::Table_map_event::m_field_metadata_size |
The size of field metadata buffer set by calling save_field_metadata()
flag_set binary_log::Table_map_event::m_flags |
unsigned char* binary_log::Table_map_event::m_null_bits |
field metadata
unsigned char* binary_log::Table_map_event::m_optional_metadata |
unsigned int binary_log::Table_map_event::m_optional_metadata_len |
Table_id binary_log::Table_map_event::m_table_id |
Event post header contents.
unsigned long long int binary_log::Table_map_event::m_tbllen |
std::string binary_log::Table_map_event::m_tblnam |