Skip to content

Commit b8f51c0

Browse files
committed
bugfix: update-behind-insert
sql_insert.cc calls handler->ha_update_row() for REPLACE and INSERT... ON DUPLICATE KEY UPDATE
1 parent 54ab7db commit b8f51c0

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

mysql-test/suite/vcol/r/update.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ index(c(100), d(20)));
3535
insert t1 (a,b,h) values (repeat('g', 10000), repeat('x', 2800), 1);
3636
update t1 set a = repeat(cast(1 as char), 2000);
3737
drop table t1;
38+
create table t1(a blob not null, b int, c varbinary (10) generated always as (a) virtual, unique (c(9)));
39+
insert t1 (a,b) values ('a', 1);
40+
replace t1 set a = 'a',b =1;
41+
insert t1 (a,b) values ('a', 1) on duplicate key update a='b', b=2;
42+
select * from t1;
43+
a b c
44+
b 2 b
45+
drop table t1;

mysql-test/suite/vcol/t/update.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ create table t1 (
4646
insert t1 (a,b,h) values (repeat('g', 10000), repeat('x', 2800), 1);
4747
update t1 set a = repeat(cast(1 as char), 2000);
4848
drop table t1;
49+
#
50+
# UPDATE disguised as INSERT
51+
#
52+
create table t1(a blob not null, b int, c varbinary (10) generated always as (a) virtual, unique (c(9)));
53+
insert t1 (a,b) values ('a', 1);
54+
replace t1 set a = 'a',b =1;
55+
insert t1 (a,b) values ('a', 1) on duplicate key update a='b', b=2;
56+
select * from t1;
57+
drop table t1;

sql/sql_insert.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,12 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
16961696
HA_READ_KEY_EXACT))))
16971697
goto err;
16981698
}
1699+
if (table->vfield)
1700+
{
1701+
table->move_fields(table->field, table->record[1], table->record[0]);
1702+
table->update_virtual_fields(VCOL_UPDATE_INDEXED);
1703+
table->move_fields(table->field, table->record[0], table->record[1]);
1704+
}
16991705
if (info->handle_duplicates == DUP_UPDATE)
17001706
{
17011707
int res= 0;

0 commit comments

Comments
 (0)