Commit 112411b0 authored by Michael Widenius's avatar Michael Widenius

Fixed MySQL bug #69861 LAST_INSERT_ID is replicated incorrectly if replication filters are used


mysql-test/suite/rpl/r/last_insert_id.result:
  Test case for last_insert_id
mysql-test/suite/rpl/t/last_insert_id.cnf:
  Test case for last_insert_id
mysql-test/suite/rpl/t/last_insert_id.test:
  Test case for last_insert_id
sql/log_event.cc:
  Added DBUG_PRINT
  Set thd->first_successful_insert_id_in_prev_stmt_for_binlog when setting thd->first_successful_insert_id_in_prev_stmt.
  This is required to get last_insert_id() replicated.
  This is analog to how read_first_successful_insert_id_in_prev_stmt() works.
sql/rpl_utility.cc:
  Added DBUG_PRINT
parent 7907b9b4
include/rpl_init.inc [topology=1->2->3]
create table t1 (id int not null auto_increment primary key, i int) engine=InnoDB;
insert into t1 (i) values (-1);
insert into t1 (i) values (LAST_INSERT_ID());
select * from t1;
id i
1 -1
2 1
select * from t1;
id i
1 -1
2 1
select * from t1;
id i
1 -1
2 1
drop table t1;
include/rpl_end.inc
!include suite/rpl/my.cnf
[mysqld.1]
log-slave-updates
loose-innodb
[mysqld.2]
log-slave-updates
loose-innodb
replicate-ignore-table=db.t2
[mysqld.3]
log-slave-updates
loose-innodb
[ENV]
SERVER_MYPORT_3= @mysqld.3.port
SERVER_MYSOCK_3= @mysqld.3.socket
--source include/have_innodb.inc
--source include/have_binlog_format_mixed_or_statement.inc
--let $rpl_topology=1->2->3
--source include/rpl_init.inc
connection server_1;
create table t1 (id int not null auto_increment primary key, i int) engine=InnoDB;
insert into t1 (i) values (-1);
insert into t1 (i) values (LAST_INSERT_ID());
select * from t1;
save_master_pos;
connection server_2;
sync_with_master;
select * from t1;
save_master_pos;
connection server_3;
sync_with_master;
select * from t1;
connection server_1;
drop table t1;
--source include/rpl_end.inc
......@@ -5933,6 +5933,7 @@ void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
{
DBUG_ENTER("Intvar_log_event::do_apply_event");
/*
We are now in a statement until the associated query log event has
been processed.
......@@ -5940,18 +5941,23 @@ int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
const_cast<Relay_log_info*>(rli)->set_flag(Relay_log_info::IN_STMT);
if (rli->deferred_events_collecting)
return rli->deferred_events->add(this);
{
DBUG_PRINT("info",("deferring event"));
DBUG_RETURN(rli->deferred_events->add(this));
}
switch (type) {
case LAST_INSERT_ID_EVENT:
thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 1;
thd->first_successful_insert_id_in_prev_stmt= val;
thd->first_successful_insert_id_in_prev_stmt_for_binlog=
thd->first_successful_insert_id_in_prev_stmt= val;
DBUG_PRINT("info",("last_insert_id_event: %ld", (long) val));
break;
case INSERT_ID_EVENT:
thd->force_one_auto_inc_interval(val);
break;
}
return 0;
DBUG_RETURN(0);
}
int Intvar_log_event::do_update_pos(Relay_log_info *rli)
......
......@@ -1145,7 +1145,7 @@ bool Deferred_log_events::is_empty()
bool Deferred_log_events::execute(Relay_log_info *rli)
{
bool res= false;
DBUG_ENTER("Deferred_log_events::execute");
DBUG_ASSERT(rli->deferred_events_collecting);
rli->deferred_events_collecting= false;
......@@ -1156,7 +1156,7 @@ bool Deferred_log_events::execute(Relay_log_info *rli)
res= ev->apply_event(rli);
}
rli->deferred_events_collecting= true;
return res;
DBUG_RETURN(res);
}
void Deferred_log_events::rewind()
......
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