Skip to content

Commit 9daf583

Browse files
vuvovakevgs
authored andcommitted
fix CREATE ... SELECT
move table->vers_update_fields() where it belongs - into fill_record(), right after table_arg->update_virtual_fields()
1 parent 1a06a48 commit 9daf583

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ en SYS_DATATYPE as row end,
191191
period for system_time (st, en)
192192
) with system versioning;
193193
## For non-versioned table:
194-
### 1. implicit system fields are not included
194+
### 1. invisible fields are not included
195195
create or replace table t2 as select * from t1;
196196
show create table t2;
197197
Table Create Table
198198
t2 CREATE TABLE `t2` (
199199
`x23` int(11) DEFAULT NULL
200200
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
201-
### 2. explicit system fields are included
201+
### 2. all visible fields are included
202202
create or replace table t3 as select * from t0;
203203
select * from t0;
204204
y st en
@@ -214,18 +214,19 @@ insert into t1 values (1);
214214
select sys_trx_start from t1 into @sys_trx_start;
215215
insert into t0 (y) values (2);
216216
select st from t0 into @st;
217-
### 1. implicit system fields are included as implicit
218217
create or replace table t2 with system versioning as select * from t1;
219218
show create table t2;
220219
Table Create Table
221220
t2 CREATE TABLE `t2` (
222221
`x23` int(11) DEFAULT NULL
223222
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
224-
#### sys_trx_start, sys_trx_end are copied; wildcard not expanded
225-
select * from t2 where sys_trx_start = @sys_trx_start;
223+
#### invisible fields are not copied
224+
select * from t2;
226225
x23
227226
1
228-
### 2. explicit system fields are included as non-system
227+
select * from t2 where sys_trx_start <= @sys_trx_start;
228+
x23
229+
### 2. source table with visible system fields, target with invisible
229230
create or replace table t3 with system versioning as select * from t0;
230231
show create table t3;
231232
Table Create Table
@@ -234,13 +235,12 @@ t3 CREATE TABLE `t3` (
234235
`st` SYS_DATATYPE,
235236
`en` SYS_DATATYPE
236237
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
237-
#### st, en are plain fields now
238238
select * from t3 where y > 2;
239239
y st en
240240
select y from t3 where st = @st and sys_trx_start > @st;
241241
y
242242
2
243-
### 3. explicit system fields are kept as system
243+
### 3. source and target table with visible system fields
244244
create or replace table t3 (
245245
st SYS_DATATYPE as row start invisible,
246246
en SYS_DATATYPE as row end invisible,
@@ -254,9 +254,11 @@ t3 CREATE TABLE `t3` (
254254
`en` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE,
255255
PERIOD FOR SYSTEM_TIME (`st`, `en`)
256256
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
257-
select y from t3 where st = @st;
257+
select y from t3;
258258
y
259259
2
260+
select y from t3 where st = @st;
261+
y
260262
### 4. system fields not or wrongly selected
261263
create or replace table t3 with system versioning select x23 from t1;
262264
show create table t3;
@@ -286,9 +288,11 @@ t3 CREATE TABLE `t3` (
286288
`x23` int(11) DEFAULT NULL,
287289
`y` int(11) DEFAULT NULL
288290
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
289-
select * from t3 for system_time all where sys_trx_start = @sys_trx_start and sys_trx_end = @sys_trx_end;
291+
select * from t3 for system_time all;
290292
x23 y
291293
1 3
294+
select * from t3 for system_time all where sys_trx_start = @sys_trx_start and sys_trx_end = @sys_trx_end;
295+
x23 y
292296
create or replace table t2 like t0;
293297
insert into t2 (y) values (1), (2);
294298
delete from t2 where y = 2;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ eval create or replace table t0(
196196
) with system versioning;
197197

198198
--echo ## For non-versioned table:
199-
--echo ### 1. implicit system fields are not included
199+
--echo ### 1. invisible fields are not included
200200
create or replace table t2 as select * from t1;
201201
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
202202
show create table t2;
203203

204-
--echo ### 2. explicit system fields are included
204+
--echo ### 2. all visible fields are included
205205
create or replace table t3 as select * from t0;
206206
select * from t0;
207207
--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;
213213
insert into t0 (y) values (2);
214214
select st from t0 into @st;
215215

216-
--echo ### 1. implicit system fields are included as implicit
217216
create or replace table t2 with system versioning as select * from t1;
218217
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
219218
show create table t2;
220-
--echo #### sys_trx_start, sys_trx_end are copied; wildcard not expanded
221-
select * from t2 where sys_trx_start = @sys_trx_start;
219+
--echo #### invisible fields are not copied
220+
select * from t2;
221+
select * from t2 where sys_trx_start <= @sys_trx_start;
222222

223-
--echo ### 2. explicit system fields are included as non-system
223+
--echo ### 2. source table with visible system fields, target with invisible
224224
create or replace table t3 with system versioning as select * from t0;
225225
--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
226226
show create table t3;
227-
--echo #### st, en are plain fields now
228227
select * from t3 where y > 2;
229228
select y from t3 where st = @st and sys_trx_start > @st;
230229

231-
--echo ### 3. explicit system fields are kept as system
230+
--echo ### 3. source and target table with visible system fields
232231
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
233232
eval create or replace table t3 (
234233
st $sys_datatype as row start invisible,
@@ -237,6 +236,7 @@ eval create or replace table t3 (
237236
) with system versioning as select * from t0;
238237
--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
239238
show create table t3;
239+
select y from t3;
240240
select y from t3 where st = @st;
241241

242242
--echo ### 4. system fields not or wrongly selected
@@ -261,6 +261,7 @@ insert into t2 values (3);
261261
create or replace table t3 with system versioning select * from t1 for system_time all, t2;
262262
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
263263
show create table t3;
264+
select * from t3 for system_time all;
264265
select * from t3 for system_time all where sys_trx_start = @sys_trx_start and sys_trx_end = @sys_trx_end;
265266

266267
create or replace table t2 like t0;

sql/sql_base.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8017,6 +8017,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
80178017
List_iterator_fast<Item> f(fields),v(values);
80188018
Item *value, *fld;
80198019
Item_field *field;
8020+
bool only_unvers_fields= update && table_arg->versioned();
80208021
bool save_abort_on_warning= thd->abort_on_warning;
80218022
bool save_no_errors= thd->no_errors;
80228023
DBUG_ENTER("fill_record");
@@ -8068,6 +8069,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
80688069
ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
80698070
rfield->field_name.str, table->s->table_name.str);
80708071
}
8072+
if (only_unvers_fields && !rfield->vers_update_unversioned())
8073+
only_unvers_fields= false;
80718074
if (table->versioned() && rfield->vers_sys_field())
80728075
{
80738076
if (type == Item::DEFAULT_VALUE_ITEM)
@@ -8092,6 +8095,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
80928095
if (table_arg->vfield &&
80938096
table_arg->update_virtual_fields(table_arg->file, VCOL_UPDATE_FOR_WRITE))
80948097
goto err;
8098+
if (table_arg->versioned() && !only_unvers_fields)
8099+
table_arg->vers_update_fields();
80958100
thd->abort_on_warning= save_abort_on_warning;
80968101
thd->no_errors= save_no_errors;
80978102
DBUG_RETURN(thd->is_error());
@@ -8350,6 +8355,8 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
83508355
if (table->vfield &&
83518356
table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE))
83528357
goto err;
8358+
if (table->versioned())
8359+
table->vers_update_fields();
83538360
thd->abort_on_warning= abort_on_warning_saved;
83548361
DBUG_RETURN(thd->is_error());
83558362

sql/sql_insert.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
10511051
}
10521052
}
10531053

1054-
if (table->versioned())
1055-
table->vers_update_fields();
1056-
10571054
if ((res= table_list->view_check_option(thd,
10581055
(values_list.elements == 1 ?
10591056
0 :
@@ -3860,8 +3857,6 @@ int select_insert::send_data(List<Item> &values)
38603857
DBUG_RETURN(1);
38613858
}
38623859
table->vers_write= versioned_write;
3863-
if (table->versioned())
3864-
table->vers_update_fields();
38653860
if (table_list) // Not CREATE ... SELECT
38663861
{
38673862
switch (table_list->view_check_option(thd, info.ignore)) {

sql/sql_update.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,6 @@ int mysql_update(THD *thd,
855855
TRG_EVENT_UPDATE))
856856
break; /* purecov: inspected */
857857

858-
if (has_vers_fields && table->versioned())
859-
table->vers_update_fields();
860-
861858
found++;
862859

863860
if (!can_compare_record || compare_record(table))
@@ -2278,9 +2275,6 @@ int multi_update::send_data(List<Item> &not_used_values)
22782275
if (table->default_field && table->update_default_fields(1, ignore))
22792276
DBUG_RETURN(1);
22802277

2281-
if (has_vers_fields && table->versioned())
2282-
table->vers_update_fields();
2283-
22842278
if ((error= cur_table->view_check_option(thd, ignore)) !=
22852279
VIEW_CHECK_OK)
22862280
{

0 commit comments

Comments
 (0)