Background:
===========
In Row based replication statements such as CREATE TABLE ... SELECT, a CREATE
statement is generated from the table definition and replicated using
statement-based format, while the row insertions are replicated using row-based
format
For example: Query: create table t1 (a int) select b from t;
============
1) binlog-format= STATEMENT
MariaDB [test]> create table t1 (a int) select b from t;
|
#190719 13:07:55 server id 1 end_log_pos 502 CRC32 0x5c74db35 GTID 0-1-2 ddl
|
/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
|
# at 502
|
#190719 13:07:55 server id 1 end_log_pos 608 CRC32 0xa14ceae2 Query thread_id=4 exec_time=0 error_code=0
|
SET TIMESTAMP=1563521875/*!*/;
|
create table t1 (a int) select b from t
|
/*!*/;
|
2) binlog-format= ROW
MariaDB [test]> create table t1 (a int) select b from t;
|
#190719 13:06:01 server id 1 end_log_pos 502 CRC32 0x12f5a142 GTID 0-1-2 ddl
|
/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
|
BEGIN
|
/*!*/;
|
# at 502
|
#190719 13:06:01 server id 1 end_log_pos 645 CRC32 0xf3a1ca57 Query thread_id=4 exec_time=0 error_code=0
|
SET TIMESTAMP=1563521761/*!*/;
|
CREATE TABLE `t1` (
|
`a` int(11) DEFAULT NULL,
|
`b` int(11) DEFAULT NULL
|
)
|
Reported Bug:
=============
Query is "CREATE TABLE t1 AS SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE 1 = 0;"
The "TABLE_NAME" field in "INFORMATION_SCHEMA.TABLES" is defined as shown below.
`TABLE_NAME` varchar(64) NOT NULL DEFAULT ''
On master the above query gets executed successfully and it gets rewritten in the
binarylog as per the resulting table definition as shown below.
CREATE TABLE `t1` (`TABLE_NAME` varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '')
On Slave: The rewritten query arrives for execution. The
SQL_MODE='EMPTY_STRING_IS_NULL' is set. The above DDL is sent to parser for
validation. Parser invokes "Column_definition::check" for "TABLE_NAME" column.
The DEFAULT is '' (Empty String) and it gets mapped to NULL due to the
"SQL_MODE" which contradicts with field definition being "NOT NULL".
Hence it results in "ER_INVALID_DEFAULT", 1067, "Invalid default value for \'%-.192s\'"
error.
Replication behaves as expected.
Background:
===========
In Row based replication statements such as CREATE TABLE ... SELECT, a CREATE
statement is generated from the table definition and replicated using
statement-based format, while the row insertions are replicated using row-based
format
For example: Query: create table t1 (a int) select b from t;
============
1) binlog-format= STATEMENT
MariaDB [test]> create table t1 (a int) select b from t;
#190719 13:07:55 server id 1 end_log_pos 502 CRC32 0x5c74db35 GTID 0-1-2 ddl
/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
# at 502
#190719 13:07:55 server id 1 end_log_pos 608 CRC32 0xa14ceae2 Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1563521875/*!*/;
create table t1 (a int) select b from t
/*!*/;
2) binlog-format= ROW
MariaDB [test]> create table t1 (a int) select b from t;
#190719 13:06:01 server id 1 end_log_pos 502 CRC32 0x12f5a142 GTID 0-1-2 ddl
/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
BEGIN
/*!*/;
# at 502
#190719 13:06:01 server id 1 end_log_pos 645 CRC32 0xf3a1ca57 Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1563521761/*!*/;
CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
)
Reported Bug:
=============
Query is "CREATE TABLE t1 AS SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE 1 = 0;"
The "TABLE_NAME" field in "INFORMATION_SCHEMA.TABLES" is defined as shown below.
`TABLE_NAME` varchar(64) NOT NULL DEFAULT ''
On master the above query gets executed successfully and it gets rewritten in the
binarylog as per the resulting table definition as shown below.
CREATE TABLE `t1` (`TABLE_NAME` varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '')
On Slave: The rewritten query arrives for execution. The
SQL_MODE='EMPTY_STRING_IS_NULL' is set. The above DDL is sent to parser for
validation. Parser invokes "Column_definition::check" for "TABLE_NAME" column.
The DEFAULT is '' (Empty String) and it gets mapped to NULL due to the
"SQL_MODE" which contradicts with field definition being "NOT NULL".
Hence it results in "ER_INVALID_DEFAULT", 1067, "Invalid default value for \'%-.192s\'"
error.
Replication behaves as expected.