Skip to content

Commit 5851e66

Browse files
committed
MDEV-19304 Segfault in ALTER TABLE after UPDATE for SIMULTANEOUS_ASSIGNMENT
For MODE_SIMULTANEOUS_ASSIGNMENT it is required to return back field offsets from record[1] to record[0]. 'continue' in warning branch did skip of rfield->move_field_offset() call.
1 parent 98758b5 commit 5851e66

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

mysql-test/suite/versioning/r/alter.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,5 +603,18 @@ select * from t1;
603603
a b
604604
1 0
605605
affected rows: 1
606+
#
607+
# MDEV-19304 Segfault in ALTER TABLE after UPDATE for SIMULTANEOUS_ASSIGNMENT
608+
#
609+
create or replace table t1 (a int, s timestamp(6) as row start, e timestamp(6) as row end, period for system_time(s,e)) engine=myisam with system versioning;
610+
insert into t1 values (null, null, null);
611+
insert into t1 values (null, null, null);
612+
set sql_mode= 'simultaneous_assignment';
613+
update t1 set e= 1;
614+
Warnings:
615+
Warning 1906 The value specified for generated column 'e' in table 't1' has been ignored
616+
Warning 1906 The value specified for generated column 'e' in table 't1' has been ignored
617+
alter table t1 force;
618+
set sql_mode= default;
606619
drop database test;
607620
create database test;

mysql-test/suite/versioning/t/alter.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,5 +503,16 @@ alter table t1 modify a int with system versioning;
503503
select * from t1;
504504
--disable_info
505505

506+
--echo #
507+
--echo # MDEV-19304 Segfault in ALTER TABLE after UPDATE for SIMULTANEOUS_ASSIGNMENT
508+
--echo #
509+
create or replace table t1 (a int, s timestamp(6) as row start, e timestamp(6) as row end, period for system_time(s,e)) engine=myisam with system versioning;
510+
insert into t1 values (null, null, null);
511+
insert into t1 values (null, null, null);
512+
set sql_mode= 'simultaneous_assignment';
513+
update t1 set e= 1;
514+
alter table t1 force;
515+
set sql_mode= default;
516+
506517
drop database test;
507518
create database test;

sql/sql_base.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8304,8 +8304,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
83048304
rfield->field_index == table->next_number_field->field_index)
83058305
table->auto_increment_field_not_null= TRUE;
83068306
Item::Type type= value->type();
8307-
bool vers_sys_field= table->versioned() && rfield->vers_sys_field();
8308-
if ((rfield->vcol_info || vers_sys_field) &&
8307+
const bool skip_sys_field= rfield->vers_sys_field(); // TODO: && !thd->vers_modify_history() [MDEV-16546]
8308+
if ((rfield->vcol_info || skip_sys_field) &&
83098309
type != Item::DEFAULT_VALUE_ITEM &&
83108310
type != Item::NULL_ITEM &&
83118311
table->s->table_category != TABLE_CATEGORY_TEMPORARY)
@@ -8314,15 +8314,14 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
83148314
ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN,
83158315
ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN),
83168316
rfield->field_name.str, table->s->table_name.str);
8317-
if (vers_sys_field)
8318-
continue;
83198317
}
83208318
if (only_unvers_fields && !rfield->vers_update_unversioned())
83218319
only_unvers_fields= false;
83228320

83238321
if (rfield->stored_in_db())
83248322
{
8325-
if (unlikely(value->save_in_field(rfield, 0) < 0) && !ignore_errors)
8323+
if (!skip_sys_field &&
8324+
unlikely(value->save_in_field(rfield, 0) < 0) && !ignore_errors)
83268325
{
83278326
my_message(ER_UNKNOWN_ERROR, ER_THD(thd, ER_UNKNOWN_ERROR), MYF(0));
83288327
goto err;

0 commit comments

Comments
 (0)