Skip to content

Commit 0d1d0d7

Browse files
committed
MDEV-11706 Assertion `is_stat_field || !table || (!table->write_set || bitmap_is_set(table->write_set, field_index) || (table->vcol_set && bitmap_is_set(table->vcol_set, field_index)))' failed in Field_time::store_TIME_with_warning
vcols and triggers. Revert 094f4cf, backport the correct fix (Table_triggers_list::mark_fields_used() not marking vcols) from 10.2.
1 parent ab93a4d commit 0d1d0d7

File tree

9 files changed

+39
-39
lines changed

9 files changed

+39
-39
lines changed

mysql-test/suite/vcol/inc/vcol_trigger_sp.inc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ drop table t1,t2;
110110
drop procedure p1;
111111

112112
--echo #
113-
--echo # Bug mdev-3845: values of virtual columns are not computed for triggers
113+
--echo # MDEV-3845 values of virtual columns are not computed for triggers
114114
--echo #
115115

116116
CREATE TABLE t1 (
@@ -149,3 +149,10 @@ DROP TRIGGER t1_ins_aft;
149149
DROP TRIGGER t1_del_bef;
150150
DROP TABLE t1,t2;
151151

152+
#
153+
# MDEV-11706 Assertion `is_stat_field || !table || (!table->write_set || bitmap_is_set(table->write_set, field_index) || (table->vcol_set && bitmap_is_set(table->vcol_set, field_index)))' failed in Field_time::store_TIME_with_warning
154+
#
155+
create table t1 (i int, t time not null, vt time(4) as (t) virtual);
156+
create trigger trg before update on t1 for each row set @a = 1;
157+
insert ignore into t1 (i) values (1);
158+
drop table t1;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ a b c
8686
drop table t1,t2;
8787
drop procedure p1;
8888
#
89-
# Bug mdev-3845: values of virtual columns are not computed for triggers
89+
# MDEV-3845 values of virtual columns are not computed for triggers
9090
#
9191
CREATE TABLE t1 (
9292
a INTEGER UNSIGNED NULL DEFAULT NULL,
@@ -125,3 +125,9 @@ c
125125
DROP TRIGGER t1_ins_aft;
126126
DROP TRIGGER t1_del_bef;
127127
DROP TABLE t1,t2;
128+
create table t1 (i int, t time not null, vt time(4) as (t) virtual);
129+
create trigger trg before update on t1 for each row set @a = 1;
130+
insert ignore into t1 (i) values (1);
131+
Warnings:
132+
Warning 1364 Field 't' doesn't have a default value
133+
drop table t1;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ a b c
8686
drop table t1,t2;
8787
drop procedure p1;
8888
#
89-
# Bug mdev-3845: values of virtual columns are not computed for triggers
89+
# MDEV-3845 values of virtual columns are not computed for triggers
9090
#
9191
CREATE TABLE t1 (
9292
a INTEGER UNSIGNED NULL DEFAULT NULL,
@@ -125,3 +125,9 @@ c
125125
DROP TRIGGER t1_ins_aft;
126126
DROP TRIGGER t1_del_bef;
127127
DROP TABLE t1,t2;
128+
create table t1 (i int, t time not null, vt time(4) as (t) virtual);
129+
create trigger trg before update on t1 for each row set @a = 1;
130+
insert ignore into t1 (i) values (1);
131+
Warnings:
132+
Warning 1364 Field 't' doesn't have a default value
133+
drop table t1;

sql/sql_base.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9033,9 +9033,7 @@ fill_record(THD * thd, List<Item> &fields, List<Item> &values,
90339033
/* Update virtual fields*/
90349034
thd->abort_on_warning= FALSE;
90359035
if (vcol_table && vcol_table->vfield &&
9036-
update_virtual_fields(thd, vcol_table,
9037-
vcol_table->triggers ? VCOL_UPDATE_ALL :
9038-
VCOL_UPDATE_FOR_WRITE))
9036+
update_virtual_fields(thd, vcol_table, VCOL_UPDATE_FOR_WRITE))
90399037
goto err;
90409038
thd->abort_on_warning= save_abort_on_warning;
90419039
thd->no_errors= save_no_errors;
@@ -9099,9 +9097,7 @@ fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
90999097
if (item_field && item_field->field &&
91009098
(table= item_field->field->table) &&
91019099
table->vfield)
9102-
result= update_virtual_fields(thd, table,
9103-
table->triggers ? VCOL_UPDATE_ALL :
9104-
VCOL_UPDATE_FOR_WRITE);
9100+
result= update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE);
91059101
}
91069102
}
91079103
return result;
@@ -9186,9 +9182,7 @@ fill_record(THD *thd, Field **ptr, List<Item> &values, bool ignore_errors,
91869182
/* Update virtual fields*/
91879183
thd->abort_on_warning= FALSE;
91889184
if (table->vfield &&
9189-
update_virtual_fields(thd, table,
9190-
table->triggers ? VCOL_UPDATE_ALL :
9191-
VCOL_UPDATE_FOR_WRITE))
9185+
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE))
91929186
goto err;
91939187
thd->abort_on_warning= abort_on_warning_saved;
91949188
DBUG_RETURN(thd->is_error());
@@ -9241,9 +9235,7 @@ fill_record_n_invoke_before_triggers(THD *thd, Field **ptr,
92419235
{
92429236
TABLE *table= (*ptr)->table;
92439237
if (table->vfield)
9244-
result= update_virtual_fields(thd, table,
9245-
table->triggers ? VCOL_UPDATE_ALL :
9246-
VCOL_UPDATE_FOR_WRITE);
9238+
result= update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE);
92479239
}
92489240
return result;
92499241

sql/sql_delete.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
328328
! thd->is_error())
329329
{
330330
if (table->vfield)
331-
update_virtual_fields(thd, table,
332-
table->triggers ? VCOL_UPDATE_ALL :
333-
VCOL_UPDATE_FOR_READ);
331+
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ);
334332
thd->examined_row_count++;
335333
// thd->is_error() is tested to disallow delete row on error
336334
if (!select || select->skip_record(thd) > 0)
@@ -1073,4 +1071,3 @@ bool multi_delete::send_eof()
10731071
}
10741072
return 0;
10751073
}
1076-

sql/sql_trigger.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,9 @@ void Table_triggers_list::mark_fields_used(trg_event_type event)
22462246
bitmap_set_bit(trigger_table->read_set, trg_field->field_idx);
22472247
if (trg_field->get_settable_routine_parameter())
22482248
bitmap_set_bit(trigger_table->write_set, trg_field->field_idx);
2249+
if (trigger_table->field[trg_field->field_idx]->vcol_info)
2250+
trigger_table->mark_virtual_col(trigger_table->
2251+
field[trg_field->field_idx]);
22492252
}
22502253
}
22512254
}

sql/sql_update.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,7 @@ int mysql_update(THD *thd,
569569
while (!(error=info.read_record(&info)) && !thd->killed)
570570
{
571571
if (table->vfield)
572-
update_virtual_fields(thd, table,
573-
table->triggers ? VCOL_UPDATE_ALL :
574-
VCOL_UPDATE_FOR_READ);
572+
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ);
575573
thd->examined_row_count++;
576574
if (!select || (error= select->skip_record(thd)) > 0)
577575
{
@@ -695,9 +693,7 @@ int mysql_update(THD *thd,
695693
while (!(error=info.read_record(&info)) && !thd->killed)
696694
{
697695
if (table->vfield)
698-
update_virtual_fields(thd, table,
699-
table->triggers ? VCOL_UPDATE_ALL :
700-
VCOL_UPDATE_FOR_READ);
696+
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ);
701697
thd->examined_row_count++;
702698
if (!select || select->skip_record(thd) > 0)
703699
{
@@ -2235,10 +2231,7 @@ int multi_update::do_updates()
22352231
{
22362232
int error;
22372233
if (table->vfield &&
2238-
update_virtual_fields(thd, table,
2239-
(table->triggers ?
2240-
VCOL_UPDATE_ALL :
2241-
VCOL_UPDATE_FOR_WRITE)))
2234+
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE))
22422235
goto err2;
22432236
if ((error= cur_table->view_check_option(thd, ignore)) !=
22442237
VIEW_CHECK_OK)

sql/table.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6557,11 +6557,9 @@ bool is_simple_order(ORDER *order)
65576557
@details
65586558
The function computes the values of the virtual columns of the table and
65596559
stores them in the table record buffer.
6560-
If vcol_update_mode is set to VCOL_UPDATE_ALL then all virtual column are
6561-
computed. Otherwise, only fields from vcol_set are computed: all of them,
6562-
if vcol_update_mode is set to VCOL_UPDATE_FOR_WRITE, and, only those with
6563-
the stored_in_db flag set to false, if vcol_update_mode is equal to
6564-
VCOL_UPDATE_FOR_READ.
6560+
Only fields from vcol_set are computed: all of them, if vcol_update_mode is
6561+
set to VCOL_UPDATE_FOR_WRITE, and, only those with the stored_in_db flag
6562+
set to false, if vcol_update_mode is equal to VCOL_UPDATE_FOR_READ.
65656563
65666564
@retval
65676565
0 Success
@@ -6583,9 +6581,8 @@ int update_virtual_fields(THD *thd, TABLE *table,
65836581
{
65846582
vfield= (*vfield_ptr);
65856583
DBUG_ASSERT(vfield->vcol_info && vfield->vcol_info->expr_item);
6586-
if ((bitmap_is_set(table->vcol_set, vfield->field_index) &&
6587-
(vcol_update_mode == VCOL_UPDATE_FOR_WRITE || !vfield->stored_in_db)) ||
6588-
vcol_update_mode == VCOL_UPDATE_ALL)
6584+
if (bitmap_is_set(table->vcol_set, vfield->field_index) &&
6585+
(vcol_update_mode == VCOL_UPDATE_FOR_WRITE || !vfield->stored_in_db))
65896586
{
65906587
/* Compute the actual value of the virtual fields */
65916588
error= vfield->vcol_info->expr_item->save_in_field(vfield, 0);

sql/table.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
302302
enum enum_vcol_update_mode
303303
{
304304
VCOL_UPDATE_FOR_READ= 0,
305-
VCOL_UPDATE_FOR_WRITE,
306-
VCOL_UPDATE_ALL
305+
VCOL_UPDATE_FOR_WRITE
307306
};
308307

309308
typedef struct st_filesort_info

0 commit comments

Comments
 (0)