Commit 9daf583a authored by Sergei Golubchik's avatar Sergei Golubchik Committed by Eugene Kosov

fix CREATE ... SELECT

move table->vers_update_fields() where it belongs - into fill_record(),
right after table_arg->update_virtual_fields()
parent 1a06a482
...@@ -191,14 +191,14 @@ en SYS_DATATYPE as row end, ...@@ -191,14 +191,14 @@ en SYS_DATATYPE as row end,
period for system_time (st, en) period for system_time (st, en)
) with system versioning; ) with system versioning;
## For non-versioned table: ## 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; create or replace table t2 as select * from t1;
show create table t2; show create table t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( t2 CREATE TABLE `t2` (
`x23` int(11) DEFAULT NULL `x23` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 ) 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; create or replace table t3 as select * from t0;
select * from t0; select * from t0;
y st en y st en
...@@ -214,18 +214,19 @@ insert into t1 values (1); ...@@ -214,18 +214,19 @@ insert into t1 values (1);
select sys_trx_start from t1 into @sys_trx_start; select sys_trx_start from t1 into @sys_trx_start;
insert into t0 (y) values (2); insert into t0 (y) values (2);
select st from t0 into @st; 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; create or replace table t2 with system versioning as select * from t1;
show create table t2; show create table t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( t2 CREATE TABLE `t2` (
`x23` int(11) DEFAULT NULL `x23` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
#### sys_trx_start, sys_trx_end are copied; wildcard not expanded #### invisible fields are not copied
select * from t2 where sys_trx_start = @sys_trx_start; select * from t2;
x23 x23
1 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; create or replace table t3 with system versioning as select * from t0;
show create table t3; show create table t3;
Table Create Table Table Create Table
...@@ -234,13 +235,12 @@ t3 CREATE TABLE `t3` ( ...@@ -234,13 +235,12 @@ t3 CREATE TABLE `t3` (
`st` SYS_DATATYPE, `st` SYS_DATATYPE,
`en` SYS_DATATYPE `en` SYS_DATATYPE
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
#### st, en are plain fields now
select * from t3 where y > 2; select * from t3 where y > 2;
y st en y st en
select y from t3 where st = @st and sys_trx_start > @st; select y from t3 where st = @st and sys_trx_start > @st;
y y
2 2
### 3. explicit system fields are kept as system ### 3. source and target table with visible system fields
create or replace table t3 ( create or replace table t3 (
st SYS_DATATYPE as row start invisible, st SYS_DATATYPE as row start invisible,
en SYS_DATATYPE as row end invisible, en SYS_DATATYPE as row end invisible,
...@@ -254,9 +254,11 @@ t3 CREATE TABLE `t3` ( ...@@ -254,9 +254,11 @@ t3 CREATE TABLE `t3` (
`en` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE, `en` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE,
PERIOD FOR SYSTEM_TIME (`st`, `en`) PERIOD FOR SYSTEM_TIME (`st`, `en`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select y from t3 where st = @st; select y from t3;
y y
2 2
select y from t3 where st = @st;
y
### 4. system fields not or wrongly selected ### 4. system fields not or wrongly selected
create or replace table t3 with system versioning select x23 from t1; create or replace table t3 with system versioning select x23 from t1;
show create table t3; show create table t3;
...@@ -286,9 +288,11 @@ t3 CREATE TABLE `t3` ( ...@@ -286,9 +288,11 @@ t3 CREATE TABLE `t3` (
`x23` int(11) DEFAULT NULL, `x23` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL `y` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) 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 x23 y
1 3 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; create or replace table t2 like t0;
insert into t2 (y) values (1), (2); insert into t2 (y) values (1), (2);
delete from t2 where y = 2; delete from t2 where y = 2;
......
...@@ -196,12 +196,12 @@ eval create or replace table t0( ...@@ -196,12 +196,12 @@ eval create or replace table t0(
) with system versioning; ) with system versioning;
--echo ## For non-versioned table: --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; create or replace table t2 as select * from t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE --replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t2; 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; create or replace table t3 as select * from t0;
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 --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; ...@@ -213,22 +213,21 @@ select sys_trx_start from t1 into @sys_trx_start;
insert into t0 (y) values (2); insert into t0 (y) values (2);
select st from t0 into @st; 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; create or replace table t2 with system versioning as select * from t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE --replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t2; show create table t2;
--echo #### sys_trx_start, sys_trx_end are copied; wildcard not expanded --echo #### invisible fields are not copied
select * from t2 where sys_trx_start = @sys_trx_start; 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; 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 --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; show create table t3;
--echo #### st, en are plain fields now
select * from t3 where y > 2; select * from t3 where y > 2;
select y from t3 where st = @st and sys_trx_start > @st; 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 --replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval create or replace table t3 ( eval create or replace table t3 (
st $sys_datatype as row start invisible, st $sys_datatype as row start invisible,
...@@ -237,6 +236,7 @@ eval create or replace table t3 ( ...@@ -237,6 +236,7 @@ eval create or replace table t3 (
) with system versioning as select * from t0; ) 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 --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; show create table t3;
select y from t3;
select y from t3 where st = @st; select y from t3 where st = @st;
--echo ### 4. system fields not or wrongly selected --echo ### 4. system fields not or wrongly selected
...@@ -261,6 +261,7 @@ insert into t2 values (3); ...@@ -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; 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 --replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t3; 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; 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; create or replace table t2 like t0;
......
...@@ -8017,6 +8017,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values, ...@@ -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); List_iterator_fast<Item> f(fields),v(values);
Item *value, *fld; Item *value, *fld;
Item_field *field; Item_field *field;
bool only_unvers_fields= update && table_arg->versioned();
bool save_abort_on_warning= thd->abort_on_warning; bool save_abort_on_warning= thd->abort_on_warning;
bool save_no_errors= thd->no_errors; bool save_no_errors= thd->no_errors;
DBUG_ENTER("fill_record"); DBUG_ENTER("fill_record");
...@@ -8068,6 +8069,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values, ...@@ -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), ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
rfield->field_name.str, table->s->table_name.str); 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 (table->versioned() && rfield->vers_sys_field())
{ {
if (type == Item::DEFAULT_VALUE_ITEM) if (type == Item::DEFAULT_VALUE_ITEM)
...@@ -8092,6 +8095,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values, ...@@ -8092,6 +8095,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
if (table_arg->vfield && if (table_arg->vfield &&
table_arg->update_virtual_fields(table_arg->file, VCOL_UPDATE_FOR_WRITE)) table_arg->update_virtual_fields(table_arg->file, VCOL_UPDATE_FOR_WRITE))
goto err; goto err;
if (table_arg->versioned() && !only_unvers_fields)
table_arg->vers_update_fields();
thd->abort_on_warning= save_abort_on_warning; thd->abort_on_warning= save_abort_on_warning;
thd->no_errors= save_no_errors; thd->no_errors= save_no_errors;
DBUG_RETURN(thd->is_error()); DBUG_RETURN(thd->is_error());
...@@ -8350,6 +8355,8 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values, ...@@ -8350,6 +8355,8 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
if (table->vfield && if (table->vfield &&
table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE)) table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE))
goto err; goto err;
if (table->versioned())
table->vers_update_fields();
thd->abort_on_warning= abort_on_warning_saved; thd->abort_on_warning= abort_on_warning_saved;
DBUG_RETURN(thd->is_error()); DBUG_RETURN(thd->is_error());
......
...@@ -1051,9 +1051,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, ...@@ -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, if ((res= table_list->view_check_option(thd,
(values_list.elements == 1 ? (values_list.elements == 1 ?
0 : 0 :
...@@ -3860,8 +3857,6 @@ int select_insert::send_data(List<Item> &values) ...@@ -3860,8 +3857,6 @@ int select_insert::send_data(List<Item> &values)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
table->vers_write= versioned_write; table->vers_write= versioned_write;
if (table->versioned())
table->vers_update_fields();
if (table_list) // Not CREATE ... SELECT if (table_list) // Not CREATE ... SELECT
{ {
switch (table_list->view_check_option(thd, info.ignore)) { switch (table_list->view_check_option(thd, info.ignore)) {
......
...@@ -855,9 +855,6 @@ int mysql_update(THD *thd, ...@@ -855,9 +855,6 @@ int mysql_update(THD *thd,
TRG_EVENT_UPDATE)) TRG_EVENT_UPDATE))
break; /* purecov: inspected */ break; /* purecov: inspected */
if (has_vers_fields && table->versioned())
table->vers_update_fields();
found++; found++;
if (!can_compare_record || compare_record(table)) if (!can_compare_record || compare_record(table))
...@@ -2278,9 +2275,6 @@ int multi_update::send_data(List<Item> &not_used_values) ...@@ -2278,9 +2275,6 @@ int multi_update::send_data(List<Item> &not_used_values)
if (table->default_field && table->update_default_fields(1, ignore)) if (table->default_field && table->update_default_fields(1, ignore))
DBUG_RETURN(1); DBUG_RETURN(1);
if (has_vers_fields && table->versioned())
table->vers_update_fields();
if ((error= cur_table->view_check_option(thd, ignore)) != if ((error= cur_table->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK) VIEW_CHECK_OK)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment