Commit 724dbaab authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-7150 Wrong auto increment values on INSERT .. ON DUPLICATE KEY UPDATE...

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)
parent a4ff2afc
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;
#
# 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;
...@@ -1754,7 +1754,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) ...@@ -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()); 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); table->file->restore_auto_increment(prev_insert_id_for_cur_row);
} }
......
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