Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mysql-test/suite/gcol/r/gcol_bugfixes.result
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,21 @@ a c1
Warnings:
Warning 1292 Incorrect datetime value: '0'
DROP TABLE t1;
#
# MDEV-40480 LOAD DATA leaves a stale STORED generated column after a
# BEFORE INSERT trigger changes its base column
#
create table t (
id int primary key,
v int not null,
g int generated always as (v * 2) stored,
note varchar(20)
) engine=innodb;
create trigger t_bi before insert on t for each row set new.v = 20;
select 2, 12, 'new' into outfile 'load_40480';
load data infile 'load_40480' into table t (id, v, note);
# The trigger sets v=20, so the STORED column g must be v*2 = 40, not 24.
select * from t;
id v g note
2 20 40 new
drop table t;
25 changes: 25 additions & 0 deletions mysql-test/suite/gcol/t/gcol_bugfixes.test
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,28 @@ UPDATE t1 SET a=2;
UPDATE t1 SET c1=1;
SELECT * FROM t1;
DROP TABLE t1;


--echo #
--echo # MDEV-40480 LOAD DATA leaves a stale STORED generated column after a
--echo # BEFORE INSERT trigger changes its base column
--echo #

create table t (
id int primary key,
v int not null,
g int generated always as (v * 2) stored,
note varchar(20)
) engine=innodb;

create trigger t_bi before insert on t for each row set new.v = 20;

select 2, 12, 'new' into outfile 'load_40480';
load data infile 'load_40480' into table t (id, v, note);

--echo # The trigger sets v=20, so the STORED column g must be v*2 = 40, not 24.
select * from t;

drop table t;
--let $datadir= `select @@datadir`
--remove_file $datadir/test/load_40480
14 changes: 3 additions & 11 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9372,17 +9372,9 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table,
Re-calculate virtual fields to cater for cases when base columns are
updated by the triggers.
*/
if (table->vfield && fields.elements)
{
Item *fld= (Item_field*) fields.head();
Item_field *item_field= fld->field_for_view_update();
if (item_field)
{
DBUG_ASSERT(table == item_field->field->table);
result|= table->update_virtual_fields(table->file,
VCOL_UPDATE_FOR_WRITE);
}
}
if (table->vfield)
result|= table->update_virtual_fields(table->file,
VCOL_UPDATE_FOR_WRITE);
}
return result;
}
Expand Down