Commit dc90f5cc authored by unknown's avatar unknown

log.cc:

  If FOREIGN_KEY_CHECKS=0, wrap in binlog SQL statements inside SET FOREIGN_...=0; ... ; SET FOREIGN_...=1


sql/log.cc:
  If FOREIGN_KEY_CHECKS=0, wrap in binlog SQL statements inside SET FOREIGN_...=0; ... ; SET FOREIGN_...=1
parent cceae057
...@@ -1071,6 +1071,12 @@ bool MYSQL_LOG::write(Log_event* event_info) ...@@ -1071,6 +1071,12 @@ bool MYSQL_LOG::write(Log_event* event_info)
No check for auto events flag here - this write method should No check for auto events flag here - this write method should
never be called if auto-events are enabled never be called if auto-events are enabled
*/ */
/*
1. Write first log events which describe the 'run environment'
of the SQL command
*/
if (thd) if (thd)
{ {
if (thd->last_insert_id_used) if (thd->last_insert_id_used)
...@@ -1109,11 +1115,50 @@ bool MYSQL_LOG::write(Log_event* event_info) ...@@ -1109,11 +1115,50 @@ bool MYSQL_LOG::write(Log_event* event_info)
if (e.write(file)) if (e.write(file))
goto err; goto err;
} }
/* If the user has set FOREIGN_KEY_CHECKS=0 we wrap every SQL
command in the binlog inside:
SET FOREIGN_KEY_CHECKS=0;
<command>;
SET FOREIGN_KEY_CHECKS=1; */
if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS)
{
char buf[256], *p;
p= strmov(buf, "SET FOREIGN_KEY_CHECKS=0");
Query_log_event e(thd, buf, (ulong) (p - buf), 0);
e.set_log_pos(this);
if (e.write(file))
goto err;
}
} }
/*
2. Write the SQL command
*/
event_info->set_log_pos(this); event_info->set_log_pos(this);
if (event_info->write(file) || if (event_info->write(file) ||
file == &log_file && flush_io_cache(file)) file == &log_file && flush_io_cache(file))
goto err; goto err;
/*
3. Write log events to reset the 'run environment' of the SQL command
*/
if (thd && thd->options & OPTION_NO_FOREIGN_KEY_CHECKS)
{
char buf[256], *p;
p= strmov(buf, "SET FOREIGN_KEY_CHECKS=1");
Query_log_event e(thd, buf, (ulong) (p - buf), 0);
e.set_log_pos(this);
if (e.write(file) ||
file == &log_file && flush_io_cache(file))
goto err;
}
error=0; error=0;
/* /*
......
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