Skip to content

Commit cf30074

Browse files
committed
MDEV-7968 Virtual column set to NULL using load data infile
Don't forget to set thd->lex->unit.insert_table_with_stored_vcol in the mysql_load(). Othewise virtual columns will not be updated.
1 parent 6f14531 commit cf30074

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
create table t1 ( c1 varchar(10), c2 varchar(10), c3 int );
2+
insert into t1 values ("a" , "b", 1), ("a" , "b", 2);
3+
create table t2 like t1 ;
4+
alter table t2 add column c4 bigint unsigned as (CONV(LEFT(MD5(concat(c1,c2,c3)), 16), 16, 10)) persistent unique key;
5+
select * into outfile 't1.csv' from t1;
6+
load data infile 't1.csv' into table t2 ;
7+
Warnings:
8+
Warning 1261 Row 1 doesn't contain data for all columns
9+
Warning 1261 Row 2 doesn't contain data for all columns
10+
select * from t2;
11+
c1 c2 c3 c4
12+
a b 1 7545402351885872315
13+
a b 2 6048842355806993119
14+
insert into t2 (c1,c2,c3) values ("a" , "b", 4);
15+
select * from t2;
16+
c1 c2 c3 c4
17+
a b 1 7545402351885872315
18+
a b 2 6048842355806993119
19+
a b 4 15541743660496249717
20+
drop table t1, t2;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# MDEV-7968 Virtual column set to NULL using load data infile
3+
#
4+
create table t1 ( c1 varchar(10), c2 varchar(10), c3 int );
5+
insert into t1 values ("a" , "b", 1), ("a" , "b", 2);
6+
create table t2 like t1 ;
7+
alter table t2 add column c4 bigint unsigned as (CONV(LEFT(MD5(concat(c1,c2,c3)), 16), 16, 10)) persistent unique key;
8+
select * into outfile 't1.csv' from t1;
9+
load data infile 't1.csv' into table t2 ;
10+
select * from t2;
11+
insert into t2 (c1,c2,c3) values ("a" , "b", 4);
12+
select * from t2;
13+
drop table t1, t2;

sql/sql_load.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,18 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
314314
table->prepare_triggers_for_insert_stmt_or_event();
315315
table->mark_columns_needed_for_insert();
316316

317+
if (table->vfield)
318+
{
319+
for (Field **vfield_ptr= table->vfield; *vfield_ptr; vfield_ptr++)
320+
{
321+
if ((*vfield_ptr)->stored_in_db)
322+
{
323+
thd->lex->unit.insert_table_with_stored_vcol= table;
324+
break;
325+
}
326+
}
327+
}
328+
317329
uint tot_length=0;
318330
bool use_blobs= 0, use_vars= 0;
319331
List_iterator_fast<Item> it(fields_vars);

0 commit comments

Comments
 (0)