summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <evgen@moonbone.local>2007-02-09 22:25:09 +0300
committerunknown <evgen@moonbone.local>2007-02-09 22:25:09 +0300
commit27481649da888b3b8fc244c79231732bbf542ed5 (patch)
tree5de1750759adba44229208a231218412005757ec
parentd7798f8dd8ed0dcb0788e3a564f7ed9b776e34c8 (diff)
downloadmariadb-git-27481649da888b3b8fc244c79231732bbf542ed5.tar.gz
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.
-rw-r--r--mysql-test/r/insert_select.result14
-rw-r--r--mysql-test/t/insert_select.test13
-rw-r--r--sql/sql_insert.cc2
3 files changed, 28 insertions, 1 deletions
diff --git a/mysql-test/r/insert_select.result b/mysql-test/r/insert_select.result
index 82cc1b036a7..2e0acf303c2 100644
--- a/mysql-test/r/insert_select.result
+++ b/mysql-test/r/insert_select.result
@@ -717,3 +717,17 @@ select * from t1;
f1 f2
1 2
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;
diff --git a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test
index 6302d5f1dae..5c60fc8e1f0 100644
--- a/mysql-test/t/insert_select.test
+++ b/mysql-test/t/insert_select.test
@@ -279,3 +279,16 @@ insert into t1 values (1,1) on duplicate key update f2=2;
--disable_info
select * from 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;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 1ea01b07166..39d7f8e9b58 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -2630,7 +2630,7 @@ bool select_insert::send_eof()
}
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 */
if (mysql_bin_log.is_open())
{