Skip to content

Commit 19b2514

Browse files
author
Davi Arnaut
committed
Add an event to send column information in RBR
Although Table_map events include some column metadata information, such as type and length, it lacks the necessary information to fully deduce column's definition and to interpret its values. For example, it lacks information such as the column name, whether an integer type is signed or unsigned, or the character set of string types. This makes it rather difficult for external programs to extract meaningful row data from row-based events. In order to enable external programs to fully deduce the table/column definitions, a new Table_metadata event is added. The purpose of this event is to describe the structure and other properties of the table and its columns, such as name, SQL type name, character set, etc. Each Table_metadata event follows a Table_map. Whether Table_metadata events are written to the binary log can be controlled using the system variable binlog_rows_table_metadata_events.
1 parent c3a613f commit 19b2514

17 files changed

+6040
-21
lines changed

client/mysqlbinlog.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,37 @@ write_event_header_and_base64(Log_event *ev, FILE *result_file,
669669
}
670670

671671

672+
/**
673+
Attach a Table_metadata event to its respective Table_map event;
674+
675+
@param event The Table_metadata event.
676+
@param print_event_info Print context.
677+
678+
@remark Upon successful attachment, the Table_map takes ownership
679+
over the Table_metadata event.
680+
681+
@return false if successful, true otherwise.
682+
*/
683+
static bool
684+
attach_to_table_map_event(Table_metadata_log_event *event,
685+
PRINT_EVENT_INFO *print_event_info)
686+
{
687+
Table_map_log_event *table_map;
688+
ulong table_map_id= event->get_table_id();
689+
DBUG_ENTER("process_table_metadata_event");
690+
691+
if (!(table_map= print_event_info->m_table_map.get_table(table_map_id)))
692+
table_map= print_event_info->m_table_map_ignored.get_table(table_map_id);
693+
694+
if (!table_map)
695+
DBUG_RETURN(true);
696+
697+
table_map->set_table_metadata_event(event);
698+
699+
DBUG_RETURN(false);
700+
}
701+
702+
672703
/**
673704
Print the given event, and either delete it or delegate the deletion
674705
to someone else.
@@ -903,6 +934,13 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
903934
my_free(fname);
904935
break;
905936
}
937+
case TABLE_METADATA_EVENT:
938+
{
939+
Table_metadata_log_event *event= (Table_metadata_log_event *) ev;
940+
destroy_evt= attach_to_table_map_event(event, print_event_info);
941+
event->print(result_file, print_event_info);
942+
break;
943+
}
906944
case TABLE_MAP_EVENT:
907945
{
908946
Table_map_log_event *map= ((Table_map_log_event *)ev);

mysql-test/include/show_binlog_events2.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
--let $binlog_start=107
1+
--let $binlog_start=130
22
--replace_result $binlog_start <binlog_start>
33
--replace_column 2 # 5 #
44
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/

0 commit comments

Comments
 (0)