Skip to content

Commit 3b6742a

Browse files
committed
don't support REPLACE and INSERT ODKU with system_versioning_insert_history
they'll ignore the value of system_versioning_insert_history, just as DELETE and UPDATE do
1 parent 13901da commit 3b6742a

File tree

3 files changed

+18
-47
lines changed

3 files changed

+18
-47
lines changed

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

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ insert t1 (x) values (2) on duplicate key update x= 3, row_end= '1970-01-01 00:0
163163
ERROR 42S22: Unknown column 'row_end' in 'field list'
164164
insert t2 (y) values (1) on duplicate key update y= 3, row_end= '1970-01-01 00:00:00';
165165
ERROR HY000: The value specified for generated column 'row_end' in table 't2' has been ignored
166+
insert t2 (y,row_end) values (1, '1970-01-01 00:00:00') on duplicate key update y= 3;
167+
ERROR HY000: The value specified for generated column 'row_end' in table 't2' has been ignored
166168
insert into t1 values (4);
167169
insert into t1 set x= 5, row_start= '1980-01-01 00:00:00', row_end= '1980-01-01 00:00:01';
168170
insert into t1(x, row_start, row_end) values (6, '1980-01-01 00:00:01', '1980-01-01 00:00:00');
@@ -231,36 +233,13 @@ ERROR 42S22: Unknown column 'row_start' in 'field list'
231233
replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1;
232234
ERROR 42S22: Unknown column 'row_start' in 'field list'
233235
set @@system_versioning_insert_history= 1;
236+
# REPLACE ignores system_versioning_insert_history
234237
replace into t2 (a, row_end) values (0, '1980-01-01 00:00:00');
235-
ERROR HY000: Incorrect row_start value: 'now'
236-
replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1980-01-01 00:00:01');
237-
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
238-
a row_start row_end
239-
1 1980-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
240-
# Changing row_end via REPLACE is NOT possible, we just insert new row:
241-
replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1990-01-01 00:00:01');
242-
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
243-
a row_start row_end
244-
1 1980-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
245-
1 1980-01-01 00:00:00.000000 1990-01-01 00:00:01.000000
246-
# REPLACE is DELETE + INSERT
247-
set timestamp=unix_timestamp('2020-10-10 10:10:10');
248-
replace into t2 (a, row_start, row_end) values (1, '1971-01-01 00:00:00', '1980-01-01 00:00:01');
249-
set timestamp=default;
250-
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
251-
a row_start row_end
252-
1 1971-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
253-
1 1980-01-01 00:00:00.000000 1990-01-01 00:00:01.000000
254-
1 1980-01-01 00:00:00.000000 2020-10-10 10:10:10.000000
255-
replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1 for system_time all
256-
where x > 1 and row_end < TIMESTAMP'2038-01-19 03:14:07.999999';
257-
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
258-
a row_start row_end
259-
1 1971-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
260-
1 1980-01-01 00:00:00.000000 1990-01-01 00:00:01.000000
261-
1 1980-01-01 00:00:00.000000 2020-10-10 10:10:10.000000
262-
3 1980-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
263-
5 1980-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
238+
ERROR 42S22: Unknown column 'row_end' in 'field list'
239+
replace into t3 (z, row_start) values (0, '1980-01-01 00:00:00');
240+
ERROR HY000: The value specified for generated column 'row_start' in table 't3' has been ignored
241+
replace into t3 values (0, '1980-01-01 00:00:00', '1981-01-01 00:00:00');
242+
ERROR HY000: The value specified for generated column 'row_start' in table 't3' has been ignored
264243
# LOAD DATA
265244
select x, row_start, row_end into outfile 'DATAFILE' from t1 for system_time all;
266245
create or replace table t2 like t1;

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ update t2 set row_start= '1971-01-01 00:00:00';
127127
insert t1 (x) values (2) on duplicate key update x= 3, row_end= '1970-01-01 00:00:00';
128128
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
129129
insert t2 (y) values (1) on duplicate key update y= 3, row_end= '1970-01-01 00:00:00';
130+
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
131+
insert t2 (y,row_end) values (1, '1970-01-01 00:00:00') on duplicate key update y= 3;
130132
# this should work, row_start/row_end must be mentioned explicitly:
131133
insert into t1 values (4);
132134
insert into t1 set x= 5, row_start= '1980-01-01 00:00:00', row_end= '1980-01-01 00:00:01';
@@ -177,22 +179,13 @@ replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1980-
177179
--error ER_BAD_FIELD_ERROR
178180
replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1;
179181
set @@system_versioning_insert_history= 1;
180-
--replace_regex /'202\d-\d\d-\d\d .*'/'now'/
181-
--error ER_WRONG_VALUE
182+
--echo # REPLACE ignores system_versioning_insert_history
183+
--error ER_BAD_FIELD_ERROR
182184
replace into t2 (a, row_end) values (0, '1980-01-01 00:00:00');
183-
replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1980-01-01 00:00:01');
184-
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
185-
--echo # Changing row_end via REPLACE is NOT possible, we just insert new row:
186-
replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1990-01-01 00:00:01');
187-
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
188-
--echo # REPLACE is DELETE + INSERT
189-
set timestamp=unix_timestamp('2020-10-10 10:10:10');
190-
replace into t2 (a, row_start, row_end) values (1, '1971-01-01 00:00:00', '1980-01-01 00:00:01');
191-
set timestamp=default;
192-
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
193-
eval replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1 for system_time all
194-
where x > 1 and row_end < $MAX_TIMESTAMP;
195-
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
185+
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
186+
replace into t3 (z, row_start) values (0, '1980-01-01 00:00:00');
187+
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
188+
replace into t3 values (0, '1980-01-01 00:00:00', '1981-01-01 00:00:00');
196189

197190
--echo # LOAD DATA
198191
--let DATAFILE= $MYSQLTEST_VARDIR/tmp/test_versioning_t3.data

sql/sql_class.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5579,7 +5579,8 @@ class THD: public THD_count, /* this must be first */
55795579
{
55805580
DBUG_ASSERT(table->versioned());
55815581
return table->versioned(VERS_TIMESTAMP) &&
5582-
(variables.option_bits & OPTION_INSERT_HISTORY);
5582+
(variables.option_bits & OPTION_INSERT_HISTORY) &&
5583+
lex->duplicates == DUP_ERROR;
55835584
}
55845585

55855586
bool vers_insert_history(const Field *field)
@@ -5590,8 +5591,6 @@ class THD: public THD_count, /* this must be first */
55905591
return false;
55915592
if (lex->sql_command != SQLCOM_INSERT &&
55925593
lex->sql_command != SQLCOM_INSERT_SELECT &&
5593-
lex->sql_command != SQLCOM_REPLACE &&
5594-
lex->sql_command != SQLCOM_REPLACE_SELECT &&
55955594
lex->sql_command != SQLCOM_LOAD)
55965595
return false;
55975596
return !is_set_timestamp_forbidden(this);

0 commit comments

Comments
 (0)