Bug #121739 Add column DEFAULT information to the Table_map optional metadata (binlog_row_metadata=FULL)

Submitted: 11 Nov 1:54
Reporter: Minjae LEE Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: Replication Severity:S4 (Feature request)
Version:8.4.11 OS:Any
Assigned to: CPU Architecture:Any
Tags: binlog_row_metadata, Table_map

[11 Nov 1:54] Minjae LEE
Description:
With binlog_row_metadata=FULL, a Table_map_log_event carries enough optional metadata to rebuild most of a table definition from the binary log alone: column names, signedness, character sets, ENUM/SET values, geometry types, the primary key, column visibility and vector dimensionality.

The column DEFAULT is not part of it. A reader of the binary log cannot tell from the event whether a column has a default, or what it is.

Change data capture tools use the FULL metadata to follow the table structure without parsing DDL statements. This matters most when the DDL statement is not in the binary log at all. A common case is a replica-first schema change, where ALTER TABLE runs on each server with sql_log_bin=OFF: the next Table_map event is then the only place where the new structure appears.

Without the default, such a tool cannot pass the exact schema on when it migrates a schema change to a sink table. It creates or evolves downstream tables and schemas without column defaults, so the sink table no longer matches the source definition. In particular, a NOT NULL column that has a DEFAULT on the source becomes a required column without a default downstream. When such a column is added to a table, schema registries that enforce backward compatibility reject the new schema, and the sink table cannot get the column default.

Debezium's schema-history-free mode for MySQL, which rebuilds the table schema from Table_map events, documents this as a limitation: https://github.com/debezium/debezium/pull/7593

How to repeat:
Start a server with --binlog-row-metadata=FULL --log-bin=binlog and run:

CREATE DATABASE d;
USE d;
CREATE TABLE t (
  id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  status VARCHAR(10) NOT NULL DEFAULT 'NEW',
  qty INT NOT NULL DEFAULT 1,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO t (qty) VALUES (3);
FLUSH BINARY LOGS;

Then print the table metadata:

mysqlbinlog --print-table-metadata -v binlog.000003

Output with the server and mysqlbinlog both at 8.4.11 (MySQL Community Server, Linux aarch64):

Table_map: `d`.`t` mapped to number 85
# has_generated_invisible_primary_key=0
# Columns(`id` BIGINT NOT NULL,
#         `status` VARCHAR(10) NOT NULL CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
#         `qty` INT NOT NULL,
#         `created_at` TIMESTAMP NOT NULL)
# Primary Key(id)

The event does not show that status, qty and created_at have defaults.

Suggested fix:
Add a new optional metadata field type to Table_map_event::Optional_metadata_field_type, written only when binlog_row_metadata=FULL, in the same way COLUMN_VISIBILITY and VECTOR_DIMENSIONALITY were added. It would carry, for the columns that have a default, the default value or expression as text.

Readers that do not know the new field type skip it, as they do for the existing ones, so this is compatible with existing readers. The default setting binlog_row_metadata=MINIMAL is not affected, so the size of the binary log does not change unless FULL is enabled.

If logging the default expressions is considered too large for every Table_map event, a bitmap of the columns that have a default would already let a reader know that the information exists and must be fetched from the server.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.