Commit d6976a7e authored by Monty's avatar Monty

MDEV-16234 CREATE TABLE .. SELECT LASTVAL breaks replication

Fixed by marking NEXTVAL() and LASTVAL() to be replicated row based
parent 14e5db6f
include/master-slave.inc
[connection master]
#
# MDEV-16234
# CREATE TABLE .. SELECT LASTVAL is written to binlog as single
# statement, causes discrepancy between master and slave
#
CREATE SEQUENCE s1 ENGINE=InnoDB;
SELECT NEXTVAL(s1);
NEXTVAL(s1)
1
CREATE TABLE t1 ENGINE=InnoDB SELECT LASTVAL(s1) AS a;
INSERT INTO t1 VALUES (NEXTVAL(s1));
INSERT INTO t1 VALUES (LASTVAL(s1));
SELECT * FROM t1;
a
1
2
2
SELECT * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1001 1 9223372036854775806 1 1 1000 0 0
connection slave;
SELECT * FROM t1;
a
1
2
2
SELECT * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1001 1 9223372036854775806 1 1 1000 0 0
connection master;
DROP TABLE t1;
DROP SEQUENCE s1;
include/rpl_end.inc
--source include/have_innodb.inc
--source include/have_binlog_format_mixed.inc
--source include/master-slave.inc
--echo #
--echo # MDEV-16234
--echo # CREATE TABLE .. SELECT LASTVAL is written to binlog as single
--echo # statement, causes discrepancy between master and slave
--echo #
CREATE SEQUENCE s1 ENGINE=InnoDB;
SELECT NEXTVAL(s1);
CREATE TABLE t1 ENGINE=InnoDB SELECT LASTVAL(s1) AS a;
INSERT INTO t1 VALUES (NEXTVAL(s1));
INSERT INTO t1 VALUES (LASTVAL(s1));
SELECT * FROM t1;
SELECT * from s1;
--sync_slave_with_master
SELECT * FROM t1;
SELECT * from s1;
# Cleanup
--connection master
DROP TABLE t1;
DROP SEQUENCE s1;
--source include/rpl_end.inc
...@@ -6791,6 +6791,7 @@ Item *LEX::create_item_func_nextval(THD *thd, Table_ident *table_ident) ...@@ -6791,6 +6791,7 @@ Item *LEX::create_item_func_nextval(THD *thd, Table_ident *table_ident)
TL_WRITE_ALLOW_WRITE, TL_WRITE_ALLOW_WRITE,
MDL_SHARED_WRITE)))) MDL_SHARED_WRITE))))
return NULL; return NULL;
thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
return new (thd->mem_root) Item_func_nextval(thd, table); return new (thd->mem_root) Item_func_nextval(thd, table);
} }
...@@ -6803,6 +6804,7 @@ Item *LEX::create_item_func_lastval(THD *thd, Table_ident *table_ident) ...@@ -6803,6 +6804,7 @@ Item *LEX::create_item_func_lastval(THD *thd, Table_ident *table_ident)
TL_READ, TL_READ,
MDL_SHARED_READ)))) MDL_SHARED_READ))))
return NULL; return NULL;
thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
return new (thd->mem_root) Item_func_lastval(thd, table); return new (thd->mem_root) Item_func_lastval(thd, table);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment