[Commits] 60c1dc1: MDEV-6997: SET STATEMENT last_insert_id FOR ... does not affect the value written to the binlog

sanja at mariadb.com sanja at mariadb.com
Wed Feb 25 20:01:03 EET 2015


revision-id: 60c1dc1ab24bfe9b3f4a898fe5e7cb070ee02cf7
parent(s): d0d6284cab70af148269d95744f615454cac24bb
committer: Oleksandr Byelkin
branch nick: work-maria-10.1-MDEV-6997-real
timestamp: 2015-02-25 19:00:57 +0100
message:

MDEV-6997: SET STATEMENT last_insert_id FOR ... does not affect the value written to the binlog

Problem was in reinitialization of first_successful_insert_id_in_prev_stmt_for_binlog after setting variables.

---
 mysql-test/r/set_statement.result                    |  2 --
 mysql-test/r/set_statement_notembedded_binlog.result |  8 ++++++++
 mysql-test/t/set_statement.test                      |  2 --
 mysql-test/t/set_statement_notembedded_binlog.test   | 15 +++++++++++++++
 sql/sql_parse.cc                                     |  4 ++++
 sql/sys_vars.cc                                      |  2 +-
 6 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/mysql-test/r/set_statement.result b/mysql-test/r/set_statement.result
index efe5286..21d1fae 100644
--- a/mysql-test/r/set_statement.result
+++ b/mysql-test/r/set_statement.result
@@ -1068,8 +1068,6 @@ set statement default_master_connection=default for select 1;
 ERROR 42000: The system variable default_master_connection cannot be set in SET STATEMENT.
 set statement default_master_connection=default for select 1;
 ERROR 42000: The system variable default_master_connection cannot be set in SET STATEMENT.
-set statement last_insert_id=1 for select 1;
-ERROR 42000: The system variable last_insert_id cannot be set in SET STATEMENT.
 set statement sql_log_off=default for select 1;
 ERROR 42000: The system variable sql_log_off cannot be set in SET STATEMENT.
 set statement long_query_time=default for select 1;
diff --git a/mysql-test/r/set_statement_notembedded_binlog.result b/mysql-test/r/set_statement_notembedded_binlog.result
new file mode 100644
index 0000000..f80a052
--- /dev/null
+++ b/mysql-test/r/set_statement_notembedded_binlog.result
@@ -0,0 +1,8 @@
+drop table if exists t1;
+drop view if exists t1;
+reset master;
+set statement last_insert_id = 112 for create table t1 as select last_insert_id();
+show binlog events limit 4,1;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+x	x	x	x	x	LAST_INSERT_ID=112
+drop table t1;
diff --git a/mysql-test/t/set_statement.test b/mysql-test/t/set_statement.test
index a658071..abbed0c 100644
--- a/mysql-test/t/set_statement.test
+++ b/mysql-test/t/set_statement.test
@@ -1015,8 +1015,6 @@ set statement default_master_connection=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement default_master_connection=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement last_insert_id=1 for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement sql_log_off=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement long_query_time=default for select 1;
diff --git a/mysql-test/t/set_statement_notembedded_binlog.test b/mysql-test/t/set_statement_notembedded_binlog.test
new file mode 100644
index 0000000..eb9953a
--- /dev/null
+++ b/mysql-test/t/set_statement_notembedded_binlog.test
@@ -0,0 +1,15 @@
+
+source include/have_log_bin.inc;
+source include/not_embedded.inc;
+
+--disable_warnings
+drop table if exists t1;
+drop view if exists t1;
+--enable_warnings
+
+
+reset master;
+set statement last_insert_id = 112 for create table t1 as select last_insert_id();
+--replace_column 1 x 2 x 3 x 4 x 5 x
+show binlog events limit 4,1;
+drop table t1;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 5af700b..54abfd0 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2728,6 +2728,10 @@ static bool do_execute_sp(THD *thd, sp_head *sp)
         my_error(ER_WRONG_ARGUMENTS, MYF(0), "SET");
       goto error;
     }
+    if (!thd->in_sub_stmt) /* stored functions and triggers are a special case */
+    {
+      thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
+    }
   }
 
   /*
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index a7d5843..d29e173 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -3619,7 +3619,7 @@ static ulonglong read_last_insert_id(THD *thd)
 }
 static Sys_var_session_special Sys_last_insert_id(
        "last_insert_id", "The value to be returned from LAST_INSERT_ID()",
-       NO_SET_STMT sys_var::ONLY_SESSION, NO_CMD_LINE,
+       sys_var::ONLY_SESSION, NO_CMD_LINE,
        VALID_RANGE(0, ULONGLONG_MAX), BLOCK_SIZE(1),
        NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
        ON_UPDATE(update_last_insert_id), ON_READ(read_last_insert_id));


More information about the commits mailing list