fix CREATE ... SELECT

move table->vers_update_fields() where it belongs - into fill_record(),
right after table_arg->update_virtual_fields()
This commit is contained in:
Sergei Golubchik 2017-12-24 01:48:21 +01:00 committed by Eugene Kosov
parent 1a06a48230
commit 9daf583ab6
5 changed files with 30 additions and 29 deletions

View file

@ -191,14 +191,14 @@ en SYS_DATATYPE as row end,
period for system_time (st, en)
) with system versioning;
## For non-versioned table:
### 1. implicit system fields are not included
### 1. invisible fields are not included
create or replace table t2 as select * from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`x23` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
### 2. explicit system fields are included
### 2. all visible fields are included
create or replace table t3 as select * from t0;
select * from t0;
y st en
@ -214,18 +214,19 @@ insert into t1 values (1);
select sys_trx_start from t1 into @sys_trx_start;
insert into t0 (y) values (2);
select st from t0 into @st;
### 1. implicit system fields are included as implicit
create or replace table t2 with system versioning as select * from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`x23` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
#### sys_trx_start, sys_trx_end are copied; wildcard not expanded
select * from t2 where sys_trx_start = @sys_trx_start;
#### invisible fields are not copied
select * from t2;
x23
1
### 2. explicit system fields are included as non-system
select * from t2 where sys_trx_start <= @sys_trx_start;
x23
### 2. source table with visible system fields, target with invisible
create or replace table t3 with system versioning as select * from t0;
show create table t3;
Table Create Table
@ -234,13 +235,12 @@ t3 CREATE TABLE `t3` (
`st` SYS_DATATYPE,
`en` SYS_DATATYPE
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
#### st, en are plain fields now
select * from t3 where y > 2;
y st en
select y from t3 where st = @st and sys_trx_start > @st;
y
2
### 3. explicit system fields are kept as system
### 3. source and target table with visible system fields
create or replace table t3 (
st SYS_DATATYPE as row start invisible,
en SYS_DATATYPE as row end invisible,
@ -254,9 +254,11 @@ t3 CREATE TABLE `t3` (
`en` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE,
PERIOD FOR SYSTEM_TIME (`st`, `en`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select y from t3 where st = @st;
select y from t3;
y
2
select y from t3 where st = @st;
y
### 4. system fields not or wrongly selected
create or replace table t3 with system versioning select x23 from t1;
show create table t3;
@ -286,9 +288,11 @@ t3 CREATE TABLE `t3` (
`x23` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select * from t3 for system_time all where sys_trx_start = @sys_trx_start and sys_trx_end = @sys_trx_end;
select * from t3 for system_time all;
x23 y
1 3
select * from t3 for system_time all where sys_trx_start = @sys_trx_start and sys_trx_end = @sys_trx_end;
x23 y
create or replace table t2 like t0;
insert into t2 (y) values (1), (2);
delete from t2 where y = 2;

View file

@ -196,12 +196,12 @@ eval create or replace table t0(
) with system versioning;
--echo ## For non-versioned table:
--echo ### 1. implicit system fields are not included
--echo ### 1. invisible fields are not included
create or replace table t2 as select * from t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t2;
--echo ### 2. explicit system fields are included
--echo ### 2. all visible fields are included
create or replace table t3 as select * from t0;
select * from t0;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE
@ -213,22 +213,21 @@ select sys_trx_start from t1 into @sys_trx_start;
insert into t0 (y) values (2);
select st from t0 into @st;
--echo ### 1. implicit system fields are included as implicit
create or replace table t2 with system versioning as select * from t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t2;
--echo #### sys_trx_start, sys_trx_end are copied; wildcard not expanded
select * from t2 where sys_trx_start = @sys_trx_start;
--echo #### invisible fields are not copied
select * from t2;
select * from t2 where sys_trx_start <= @sys_trx_start;
--echo ### 2. explicit system fields are included as non-system
--echo ### 2. source table with visible system fields, target with invisible
create or replace table t3 with system versioning as select * from t0;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE
show create table t3;
--echo #### st, en are plain fields now
select * from t3 where y > 2;
select y from t3 where st = @st and sys_trx_start > @st;
--echo ### 3. explicit system fields are kept as system
--echo ### 3. source and target table with visible system fields
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval create or replace table t3 (
st $sys_datatype as row start invisible,
@ -237,6 +236,7 @@ eval create or replace table t3 (
) with system versioning as select * from t0;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE
show create table t3;
select y from t3;
select y from t3 where st = @st;
--echo ### 4. system fields not or wrongly selected
@ -261,6 +261,7 @@ insert into t2 values (3);
create or replace table t3 with system versioning select * from t1 for system_time all, t2;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t3;
select * from t3 for system_time all;
select * from t3 for system_time all where sys_trx_start = @sys_trx_start and sys_trx_end = @sys_trx_end;
create or replace table t2 like t0;

View file

@ -8017,6 +8017,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
List_iterator_fast<Item> f(fields),v(values);
Item *value, *fld;
Item_field *field;
bool only_unvers_fields= update && table_arg->versioned();
bool save_abort_on_warning= thd->abort_on_warning;
bool save_no_errors= thd->no_errors;
DBUG_ENTER("fill_record");
@ -8068,6 +8069,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
rfield->field_name.str, table->s->table_name.str);
}
if (only_unvers_fields && !rfield->vers_update_unversioned())
only_unvers_fields= false;
if (table->versioned() && rfield->vers_sys_field())
{
if (type == Item::DEFAULT_VALUE_ITEM)
@ -8092,6 +8095,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
if (table_arg->vfield &&
table_arg->update_virtual_fields(table_arg->file, VCOL_UPDATE_FOR_WRITE))
goto err;
if (table_arg->versioned() && !only_unvers_fields)
table_arg->vers_update_fields();
thd->abort_on_warning= save_abort_on_warning;
thd->no_errors= save_no_errors;
DBUG_RETURN(thd->is_error());
@ -8350,6 +8355,8 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
if (table->vfield &&
table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE))
goto err;
if (table->versioned())
table->vers_update_fields();
thd->abort_on_warning= abort_on_warning_saved;
DBUG_RETURN(thd->is_error());

View file

@ -1051,9 +1051,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
}
}
if (table->versioned())
table->vers_update_fields();
if ((res= table_list->view_check_option(thd,
(values_list.elements == 1 ?
0 :
@ -3860,8 +3857,6 @@ int select_insert::send_data(List<Item> &values)
DBUG_RETURN(1);
}
table->vers_write= versioned_write;
if (table->versioned())
table->vers_update_fields();
if (table_list) // Not CREATE ... SELECT
{
switch (table_list->view_check_option(thd, info.ignore)) {

View file

@ -855,9 +855,6 @@ update_begin:
TRG_EVENT_UPDATE))
break; /* purecov: inspected */
if (has_vers_fields && table->versioned())
table->vers_update_fields();
found++;
if (!can_compare_record || compare_record(table))
@ -2278,9 +2275,6 @@ int multi_update::send_data(List<Item> &not_used_values)
if (table->default_field && table->update_default_fields(1, ignore))
DBUG_RETURN(1);
if (has_vers_fields && table->versioned())
table->vers_update_fields();
if ((error= cur_table->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK)
{