Skip to content

Commit

Permalink
MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CR…
Browse files Browse the repository at this point in the history
…EATE ... SELECT in ORACLE mode

- Adding optional qualifiers to data types:
    CREATE TABLE t1 (a schema.DATE);
  Qualifiers now work only for three pre-defined schemas:

    mariadb_schema
    oracle_schema
    maxdb_schema

  These schemas are virtual (hard-coded) for now, but may turn into real
  databases on disk in the future.

- mariadb_schema.TYPE now always resolves to a true MariaDB data
  type TYPE without sql_mode specific translations.

- oracle_schema.DATE translates to MariaDB DATETIME.

- maxdb_schema.TIMESTAMP translates to MariaDB DATETIME.

- Fixing SHOW CREATE TABLE to use a qualifier for a data type TYPE
  if the current sql_mode translates TYPE to something else.

The above changes fix the reported problem, so this script:

    SET sql_mode=ORACLE;
    CREATE TABLE t2 AS SELECT mariadb_date_column FROM t1;

is now replicated as:

    SET sql_mode=ORACLE;
    CREATE TABLE t2 (mariadb_date_column mariadb_schema.DATE);

and the slave can unambiguously treat DATE as the true MariaDB DATE
without ORACLE specific translation to DATETIME.

Similar,

    SET sql_mode=MAXDB;
    CREATE TABLE t2 AS SELECT mariadb_timestamp_column FROM t1;

is now replicated as:

    SET sql_mode=MAXDB;
    CREATE TABLE t2 (mariadb_timestamp_column mariadb_schema.TIMESTAMP);

so the slave treats TIMESTAMP as the true MariaDB TIMESTAMP
without MAXDB specific translation to DATETIME.
  • Loading branch information
abarkov committed Jul 31, 2020
1 parent 6053eb1 commit 59730a0
Show file tree
Hide file tree
Showing 28 changed files with 861 additions and 59 deletions.
1 change: 1 addition & 0 deletions libmysqld/CMakeLists.txt
Expand Up @@ -108,6 +108,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/sql_explain.cc ../sql/sql_explain.h
../sql/sql_analyze_stmt.cc ../sql/sql_analyze_stmt.h
../sql/compat56.cc
../sql/sql_schema.cc
../sql/sql_type.cc ../sql/sql_type.h
../sql/sql_mode.cc
../sql/table_cache.cc ../sql/mf_iocache_encr.cc
Expand Down
10 changes: 10 additions & 0 deletions mysql-test/main/lowercase_fs_off.result
Expand Up @@ -158,3 +158,13 @@ show triggers like '%T1%';
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
drop table t1;
set GLOBAL sql_mode=default;
#
# MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode
#
# Compatibility schema names respect the filesystem case sensitivity
CREATE TABLE t1 (a MARIADB_SCHEMA.date);
ERROR HY000: Unknown data type: 'MARIADB_SCHEMA.date'
CREATE TABLE t1 (a Mariadb_schema.date);
ERROR HY000: Unknown data type: 'Mariadb_schema.date'
CREATE TABLE t1 (a mariadb_schema.date);
DROP TABLE t1;
15 changes: 15 additions & 0 deletions mysql-test/main/lowercase_fs_off.test
Expand Up @@ -129,3 +129,18 @@ let $datadir= `select @@datadir`;
remove_file $datadir/mysql_upgrade_info;

set GLOBAL sql_mode=default;


--echo #
--echo # MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode
--echo #

--echo # Compatibility schema names respect the filesystem case sensitivity

--error ER_UNKNOWN_ERROR
CREATE TABLE t1 (a MARIADB_SCHEMA.date);
--error ER_UNKNOWN_ERROR
CREATE TABLE t1 (a Mariadb_schema.date);

CREATE TABLE t1 (a mariadb_schema.date);
DROP TABLE t1;
1 change: 1 addition & 0 deletions mysql-test/mysql-test-run.pl
Expand Up @@ -179,6 +179,7 @@ END
binlog_encryption-
csv-
compat/oracle-
compat/maxdb-
encryption-
federated-
funcs_1-
Expand Down
65 changes: 65 additions & 0 deletions mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.result
@@ -0,0 +1,65 @@
include/master-slave.inc
[connection master]
#
# MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:00:00');
SET sql_mode=DEFAULT;
CREATE TABLE t1 (a TIMESTAMP);
INSERT INTO t1 VALUES (NULL);
INSERT INTO t1 VALUES ('2001-01-01 10:20:30');
SET sql_mode=MAXDB;
CREATE TABLE t2 SELECT * FROM t1;
SET timestamp=DEFAULT;
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Gtid # # GTID #-#-#
master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a TIMESTAMP)
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Annotate_rows # # INSERT INTO t1 VALUES (NULL)
master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Annotate_rows # # INSERT INTO t1 VALUES ('2001-01-01 10:20:30')
master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `test`; CREATE TABLE "t2" (
"a" mariadb_schema.timestamp NOT NULL DEFAULT current_timestamp()
)
master-bin.000001 # Annotate_rows # # CREATE TABLE t2 SELECT * FROM t1
master-bin.000001 # Table_map # # table_id: # (test.t2)
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
connection slave;
SELECT * FROM t1;
a
2001-01-01 10:00:00
2001-01-01 10:20:30
SET sql_mode=DEFAULT;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SET sql_mode=MAXDB;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE "t1" (
"a" mariadb_schema.timestamp NOT NULL DEFAULT current_timestamp()
)
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE "t2" (
"a" mariadb_schema.timestamp NOT NULL DEFAULT current_timestamp()
)
connection master;
DROP TABLE t1, t2;
include/rpl_end.inc
34 changes: 34 additions & 0 deletions mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.test
@@ -0,0 +1,34 @@
--source include/have_binlog_format_row.inc
--source include/master-slave.inc

--echo #
--echo # MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode
--echo #

SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:00:00');
SET sql_mode=DEFAULT;
CREATE TABLE t1 (a TIMESTAMP);
INSERT INTO t1 VALUES (NULL);
INSERT INTO t1 VALUES ('2001-01-01 10:20:30');
SET sql_mode=MAXDB;
CREATE TABLE t2 SELECT * FROM t1;
SET timestamp=DEFAULT;

--let $binlog_file = LAST
source include/show_binlog_events.inc;


--sync_slave_with_master
SELECT * FROM t1;
SET sql_mode=DEFAULT;
SHOW CREATE TABLE t1;
SHOW CREATE TABLE t2;

SET sql_mode=MAXDB;
SHOW CREATE TABLE t1;
SHOW CREATE TABLE t2;

--connection master
DROP TABLE t1, t2;

--source include/rpl_end.inc
53 changes: 53 additions & 0 deletions mysql-test/suite/compat/maxdb/type_timestamp.result
@@ -0,0 +1,53 @@
#
# MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode
#
SET sql_mode=DEFAULT;
CREATE TABLE t1 (
def_timestamp TIMESTAMP,
mdb_timestamp mariadb_schema.TIMESTAMP,
ora_timestamp oracle_schema.TIMESTAMP,
max_timestamp maxdb_schema.TIMESTAMP
);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`def_timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`mdb_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`ora_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`max_timestamp` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SET sql_mode=MAXDB;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE "t1" (
"def_timestamp" mariadb_schema.timestamp NOT NULL DEFAULT current_timestamp(),
"mdb_timestamp" mariadb_schema.timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
"ora_timestamp" mariadb_schema.timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
"max_timestamp" datetime DEFAULT NULL
)
DROP TABLE t1;
SET sql_mode=MAXDB;
CREATE TABLE t1 (
def_timestamp TIMESTAMP,
mdb_timestamp mariadb_schema.TIMESTAMP,
ora_timestamp oracle_schema.TIMESTAMP,
max_timestamp maxdb_schema.TIMESTAMP
);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE "t1" (
"def_timestamp" datetime DEFAULT NULL,
"mdb_timestamp" mariadb_schema.timestamp NOT NULL DEFAULT current_timestamp(),
"ora_timestamp" mariadb_schema.timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
"max_timestamp" datetime DEFAULT NULL
)
SET sql_mode=DEFAULT;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`def_timestamp` datetime DEFAULT NULL,
`mdb_timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`ora_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`max_timestamp` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
29 changes: 29 additions & 0 deletions mysql-test/suite/compat/maxdb/type_timestamp.test
@@ -0,0 +1,29 @@
--echo #
--echo # MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode
--echo #


SET sql_mode=DEFAULT;
CREATE TABLE t1 (
def_timestamp TIMESTAMP,
mdb_timestamp mariadb_schema.TIMESTAMP,
ora_timestamp oracle_schema.TIMESTAMP,
max_timestamp maxdb_schema.TIMESTAMP
);
SHOW CREATE TABLE t1;
SET sql_mode=MAXDB;
SHOW CREATE TABLE t1;
DROP TABLE t1;


SET sql_mode=MAXDB;
CREATE TABLE t1 (
def_timestamp TIMESTAMP,
mdb_timestamp mariadb_schema.TIMESTAMP,
ora_timestamp oracle_schema.TIMESTAMP,
max_timestamp maxdb_schema.TIMESTAMP
);
SHOW CREATE TABLE t1;
SET sql_mode=DEFAULT;
SHOW CREATE TABLE t1;
DROP TABLE t1;
86 changes: 86 additions & 0 deletions mysql-test/suite/compat/oracle/r/rpl_mariadb_date.result
@@ -0,0 +1,86 @@
include/master-slave.inc
[connection master]
SET SQL_MODE=DEFAULT;
CREATE TABLE t1 (a DATE);
INSERT INTO t1 VALUES (NULL);
INSERT INTO t1 VALUES ('2001-01-01');
SET SQL_MODE= ORACLE;
CREATE TABLE t2 SELECT * FROM t1;
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Gtid # # GTID #-#-#
master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a DATE)
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Annotate_rows # # INSERT INTO t1 VALUES (NULL)
master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Annotate_rows # # INSERT INTO t1 VALUES ('2001-01-01')
master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `test`; CREATE TABLE "t2" (
"a" mariadb_schema.date DEFAULT NULL
)
master-bin.000001 # Annotate_rows # # CREATE TABLE t2 SELECT * FROM t1
master-bin.000001 # Table_map # # table_id: # (test.t2)
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
SET SQL_MODE= DEFAULT;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SET SQL_MODE= ORACLE;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE "t1" (
"a" mariadb_schema.date DEFAULT NULL
)
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE "t2" (
"a" mariadb_schema.date DEFAULT NULL
)
connection slave;
SELECT * FROM t1;
a
NULL
2001-01-01
SELECT * FROM t2;
a
NULL
2001-01-01
SET SQL_MODE= DEFAULT;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SET SQL_MODE= ORACLE;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE "t1" (
"a" mariadb_schema.date DEFAULT NULL
)
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE "t2" (
"a" mariadb_schema.date DEFAULT NULL
)
connection master;
DROP TABLE t1, t2;
include/rpl_end.inc

0 comments on commit 59730a0

Please sign in to comment.