Commit 27481649 authored by unknown's avatar unknown

Bug#23170: LAST_INSERT_ID isn't reset to 0 in INSERT .. SELECT when no rows were

inserted.

The select_insert::send_eof() function now resets LAST_INSERT_ID variable if
no rows were inserted.


mysql-test/t/insert_select.test:
  Added a test case for bug#23170: LAST_INSERT_ID isn't reset to 0 in INSERT .. SELECT when no rows were inserted.
mysql-test/r/insert_select.result:
  Added a test case for bug#23170: LAST_INSERT_ID isn't reset to 0 in INSERT .. SELECT when no rows were inserted.
sql/sql_insert.cc:
  Bug#23170: LAST_INSERT_ID isn't reset to 0 in INSERT .. SELECT when no rows were
  inserted.The select_insert::send_eof() function now resets LAST_INSERT_ID variable if
  no rows were inserted.
parent d7798f8d
...@@ -717,3 +717,17 @@ select * from t1; ...@@ -717,3 +717,17 @@ select * from t1;
f1 f2 f1 f2
1 2 1 2
drop table t1; drop table t1;
create table t1(f1 int primary key auto_increment, f2 int unique);
insert into t1(f2) values(1);
select @@identity;
@@identity
1
insert ignore t1(f2) values(1);
select @@identity;
@@identity
0
insert ignore t1(f2) select 1;
select @@identity;
@@identity
0
drop table t1;
...@@ -279,3 +279,16 @@ insert into t1 values (1,1) on duplicate key update f2=2; ...@@ -279,3 +279,16 @@ insert into t1 values (1,1) on duplicate key update f2=2;
--disable_info --disable_info
select * from t1; select * from t1;
drop table t1; drop table t1;
#
# Bug#23170: LAST_INSERT_ID isn't reset to 0 in INSERT .. SELECT if no rows
# were inserted.
#
create table t1(f1 int primary key auto_increment, f2 int unique);
insert into t1(f2) values(1);
select @@identity;
insert ignore t1(f2) values(1);
select @@identity;
insert ignore t1(f2) select 1;
select @@identity;
drop table t1;
...@@ -2630,7 +2630,7 @@ bool select_insert::send_eof() ...@@ -2630,7 +2630,7 @@ bool select_insert::send_eof()
} }
if (last_insert_id) if (last_insert_id)
thd->insert_id(last_insert_id); // For binary log thd->insert_id(info.copied ? last_insert_id : 0); // For binary log
/* Write to binlog before commiting transaction */ /* Write to binlog before commiting transaction */
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
......
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