MySQL 8.3.0
Source Code Documentation
mysql::binlog::event::Table_map_event Class Reference

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>

Inheritance diagram for mysql::binlog::event::Table_map_event:
[legend]

Classes

struct  Optional_metadata_fields
 Metadata_fields organizes m_optional_metadata into a structured format which is easy to access. More...
 

Public Types

enum  Table_map_event_offset { TM_MAPID_OFFSET = 0 , TM_FLAGS_OFFSET = 6 }
 Constants representing offsets. More...
 
enum  Optional_metadata_field_type {
  SIGNEDNESS = 1 , DEFAULT_CHARSET , COLUMN_CHARSET , COLUMN_NAME ,
  SET_STR_VALUE , ENUM_STR_VALUE , GEOMETRY_TYPE , SIMPLE_PRIMARY_KEY ,
  PRIMARY_KEY_WITH_PREFIX , ENUM_AND_SET_DEFAULT_CHARSET , ENUM_AND_SET_COLUMN_CHARSET , COLUMN_VISIBILITY
}
 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. More...
 
typedef uint16_t flag_set
 
- Public Types inherited from mysql::binlog::event::Binary_log_event
enum  enum_post_header_length {
  QUERY_HEADER_MINIMAL_LEN = (4 + 4 + 1 + 2) , QUERY_HEADER_LEN = (QUERY_HEADER_MINIMAL_LEN + 2) , STOP_HEADER_LEN = 0 , START_V3_HEADER_LEN = (2 + ST_SERVER_VER_LEN + 4) ,
  ROTATE_HEADER_LEN = 8 , INTVAR_HEADER_LEN = 0 , APPEND_BLOCK_HEADER_LEN = 4 , DELETE_FILE_HEADER_LEN = 4 ,
  RAND_HEADER_LEN = 0 , USER_VAR_HEADER_LEN = 0 , FORMAT_DESCRIPTION_HEADER_LEN = (START_V3_HEADER_LEN + 1 + LOG_EVENT_TYPES) , XID_HEADER_LEN = 0 ,
  BEGIN_LOAD_QUERY_HEADER_LEN = APPEND_BLOCK_HEADER_LEN , ROWS_HEADER_LEN_V1 = 8 , TABLE_MAP_HEADER_LEN = 8 , EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN = (4 + 4 + 4 + 1) ,
  EXECUTE_LOAD_QUERY_HEADER_LEN , INCIDENT_HEADER_LEN = 2 , HEARTBEAT_HEADER_LEN = 0 , IGNORABLE_HEADER_LEN = 0 ,
  ROWS_HEADER_LEN_V2 = 10 , TRANSACTION_CONTEXT_HEADER_LEN = 18 , VIEW_CHANGE_HEADER_LEN = 52 , XA_PREPARE_HEADER_LEN = 0 ,
  TRANSACTION_PAYLOAD_HEADER_LEN = 0
}
 The lengths for the fixed data part of each event. 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 mysql::binlog::event::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_eventoperator= (const Binary_log_event &)=default
 
Binary_log_eventoperator= (Binary_log_event &&)=default
 
enum Log_event_type get_event_type () const
 Helper method. More...
 
const Log_event_headerheader () const
 Return a const pointer to the header of the log event. More...
 
Log_event_headerheader ()
 Return a non-const pointer to the header of the log event. More...
 
const Log_event_footerfooter () const
 Return a const pointer to the footer of the log event. More...
 
Log_event_footerfooter ()
 Return a non-const pointer to the footer of the log event. More...
 
Event_readerreader ()
 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 mysql::binlog::event::Binary_log_event
static const int LOG_EVENT_TYPES = (ENUM_END_EVENT - 1)
 
- Protected Member Functions inherited from mysql::binlog::event::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...
 

Detailed Description

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.

Binary Format

The Post-Header has the following components:

Post-Header for Table_map_event
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:

Body for Table_map_event
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.

Table_map_event column types: numerical identifier and metadata
Name Identifier Size of metadata in bytes

Description of metadata

MYSQL_TYPE_DECIMAL0 0

No column metadata.

MYSQL_TYPE_TINY1 0

No column metadata.

MYSQL_TYPE_SHORT2 0

No column metadata.

MYSQL_TYPE_LONG3 0

No column metadata.

MYSQL_TYPE_FLOAT4 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_DOUBLE5 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_NULL6 0

No column metadata.

MYSQL_TYPE_TIMESTAMP7 0

No column metadata.

MYSQL_TYPE_LONGLONG8 0

No column metadata.

MYSQL_TYPE_INT249 0

No column metadata.

MYSQL_TYPE_DATE10 0

No column metadata.

MYSQL_TYPE_TIME11 0

No column metadata.

MYSQL_TYPE_DATETIME12 0

No column metadata.

MYSQL_TYPE_YEAR13 0

No column metadata.

MYSQL_TYPE_NEWDATE14

This enumeration value is only used internally and cannot exist in a binlog.

MYSQL_TYPE_VARCHAR15 2 bytes

2 byte unsigned integer representing the maximum length of the string.

MYSQL_TYPE_BIT16 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_NEWDECIMAL246 2 bytes

A 1 byte unsigned int representing the precision, followed by a 1 byte unsigned int representing the number of decimals.

MYSQL_TYPE_ENUM247

This enumeration value is only used internally and cannot exist in a binlog.

MYSQL_TYPE_SET248

This enumeration value is only used internally and cannot exist in a binlog.

MYSQL_TYPE_TINY_BLOB249

This enumeration value is only used internally and cannot exist in a binlog.

MYSQL_TYPE_MEDIUM_BLOB250

This enumeration value is only used internally and cannot exist in a binlog.

MYSQL_TYPE_LONG_BLOB251

This enumeration value is only used internally and cannot exist in a binlog.

MYSQL_TYPE_BLOB252 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_STRING253 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_STRING254 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_GEOMETRY255 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_ARRAY15 up to 4 bytes
  • The first byte holds the MySQL type for the elements.
  • The following 0, 1, 2, or 3 bytes holds the metadata for the MySQL type for the elements. The contents of these bytes depends on the element type, as described in the other rows of this table.

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.

Table_map_event optional metadata types: numerical identifier and metadata. Optional metadata fields are stored in TLV fields. Format of values are described in this table.
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.

Member Typedef Documentation

◆ flag_set

Member Enumeration Documentation

◆ Optional_metadata_field_type

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.

Enumerator
SIGNEDNESS 
DEFAULT_CHARSET 
COLUMN_CHARSET 
COLUMN_NAME 
SET_STR_VALUE 
ENUM_STR_VALUE 
GEOMETRY_TYPE 
SIMPLE_PRIMARY_KEY 
PRIMARY_KEY_WITH_PREFIX 
ENUM_AND_SET_DEFAULT_CHARSET 
ENUM_AND_SET_COLUMN_CHARSET 
COLUMN_VISIBILITY 

◆ Table_map_event_offset

Constants representing offsets.

Enumerator
TM_MAPID_OFFSET 

TM = "Table Map".

TM_FLAGS_OFFSET 

Constructor & Destructor Documentation

◆ Table_map_event() [1/3]

mysql::binlog::event::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 |
+---------------------------------------------+
Parameters
bufContains the serialized event.
fdeAn FDE event (see Rotate_event constructor for more info).

◆ Table_map_event() [2/3]

mysql::binlog::event::Table_map_event::Table_map_event ( const Table_id tid,
unsigned long  colcnt,
const char *  dbnam,
size_t  dblen,
const char *  tblnam,
size_t  tbllen 
)
inline

◆ ~Table_map_event()

mysql::binlog::event::Table_map_event::~Table_map_event ( )
override

◆ Table_map_event() [3/3]

mysql::binlog::event::Table_map_event::Table_map_event ( )
inline

Member Function Documentation

◆ get_db_name()

std::string mysql::binlog::event::Table_map_event::get_db_name ( )
inline

◆ get_table_id()

unsigned long long mysql::binlog::event::Table_map_event::get_table_id ( )
inline

◆ get_table_name()

std::string mysql::binlog::event::Table_map_event::get_table_name ( )
inline

Member Data Documentation

◆ m_colcnt

unsigned long mysql::binlog::event::Table_map_event::m_colcnt

◆ m_coltype

unsigned char* mysql::binlog::event::Table_map_event::m_coltype

◆ m_data_size

size_t mysql::binlog::event::Table_map_event::m_data_size

◆ m_dblen

unsigned long long int mysql::binlog::event::Table_map_event::m_dblen

◆ m_dbnam

std::string mysql::binlog::event::Table_map_event::m_dbnam

event data size

Event body contents

◆ m_field_metadata

unsigned char* mysql::binlog::event::Table_map_event::m_field_metadata

◆ m_field_metadata_size

unsigned long mysql::binlog::event::Table_map_event::m_field_metadata_size

The size of field metadata buffer set by calling save_field_metadata()

◆ m_flags

flag_set mysql::binlog::event::Table_map_event::m_flags

◆ m_null_bits

unsigned char* mysql::binlog::event::Table_map_event::m_null_bits

field metadata

◆ m_optional_metadata

unsigned char* mysql::binlog::event::Table_map_event::m_optional_metadata

◆ m_optional_metadata_len

unsigned int mysql::binlog::event::Table_map_event::m_optional_metadata_len

◆ m_table_id

Table_id mysql::binlog::event::Table_map_event::m_table_id

Event post header contents.

◆ m_tbllen

unsigned long long int mysql::binlog::event::Table_map_event::m_tbllen

◆ m_tblnam

std::string mysql::binlog::event::Table_map_event::m_tblnam

The documentation for this class was generated from the following files: