summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2014-12-18 00:13:16 +0100
committerSergei Golubchik <sergii@pisem.net>2014-12-18 00:13:16 +0100
commit724dbaabc0d06c4446417eb217d8536f193461f9 (patch)
treee85d8bf0f24b03f27060f994b178337db8471e19
parenta4ff2afcb4b1e16f1d467add82a7313d3da05a05 (diff)
downloadmariadb-git-724dbaabc0d06c4446417eb217d8536f193461f9.tar.gz
MDEV-7150 Wrong auto increment values on INSERT .. ON DUPLICATE KEY UPDATE when the inserted columns include NULL in an auto-increment column
when restoring auto-inc value in INSERT ... ON DUPLICATE KEY UPDATE, take into account that 1. it may be changed in the UPDATE clause (old code did that) 2. it may be changed in the INSERT clause and then cause a dup key (old code missed that)
-rw-r--r--mysql-test/r/insert_update_autoinc-7150.result9
-rw-r--r--mysql-test/t/insert_update_autoinc-7150.test8
-rw-r--r--sql/sql_insert.cc2
3 files changed, 18 insertions, 1 deletions
diff --git a/mysql-test/r/insert_update_autoinc-7150.result b/mysql-test/r/insert_update_autoinc-7150.result
new file mode 100644
index 00000000000..96773479310
--- /dev/null
+++ b/mysql-test/r/insert_update_autoinc-7150.result
@@ -0,0 +1,9 @@
+create table t1 (a int(10) auto_increment primary key, b int(11));
+insert t1 values (null,1);
+insert t1 values (null,2), (1,-1), (null,3) on duplicate key update b=values(b);
+select * from t1;
+a b
+1 -1
+2 2
+3 3
+drop table t1;
diff --git a/mysql-test/t/insert_update_autoinc-7150.test b/mysql-test/t/insert_update_autoinc-7150.test
new file mode 100644
index 00000000000..1229898b4aa
--- /dev/null
+++ b/mysql-test/t/insert_update_autoinc-7150.test
@@ -0,0 +1,8 @@
+#
+# MDEV-7150 Wrong auto increment values on INSERT .. ON DUPLICATE KEY UPDATE when the inserted columns include NULL in an auto-increment column
+#
+create table t1 (a int(10) auto_increment primary key, b int(11));
+insert t1 values (null,1);
+insert t1 values (null,2), (1,-1), (null,3) on duplicate key update b=values(b);
+select * from t1;
+drop table t1;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index ccfdf352f53..4500c4492c4 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1754,7 +1754,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
table->file->adjust_next_insert_id_after_explicit_value(table->next_number_field->val_int());
}
- else
+ else if (prev_insert_id_for_cur_row)
{
table->file->restore_auto_increment(prev_insert_id_for_cur_row);
}