1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

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
This commit is contained in:
Sergei Golubchik
2022-10-18 15:56:28 +02:00
parent 13901dafe1
commit 3b6742a106
3 changed files with 18 additions and 47 deletions

View File

@@ -163,6 +163,8 @@ insert t1 (x) values (2) on duplicate key update x= 3, row_end= '1970-01-01 00:0
ERROR 42S22: Unknown column 'row_end' in 'field list' ERROR 42S22: Unknown column 'row_end' in 'field list'
insert t2 (y) values (1) on duplicate key update y= 3, row_end= '1970-01-01 00:00:00'; insert t2 (y) values (1) on duplicate key update y= 3, row_end= '1970-01-01 00:00:00';
ERROR HY000: The value specified for generated column 'row_end' in table 't2' has been ignored ERROR HY000: The value specified for generated column 'row_end' in table 't2' has been ignored
insert t2 (y,row_end) values (1, '1970-01-01 00:00:00') on duplicate key update y= 3;
ERROR HY000: The value specified for generated column 'row_end' in table 't2' has been ignored
insert into t1 values (4); insert into t1 values (4);
insert into t1 set x= 5, row_start= '1980-01-01 00:00:00', row_end= '1980-01-01 00:00:01'; insert into t1 set x= 5, row_start= '1980-01-01 00:00:00', row_end= '1980-01-01 00:00:01';
insert into t1(x, row_start, row_end) values (6, '1980-01-01 00:00:01', '1980-01-01 00:00:00'); 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'
replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1; replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1;
ERROR 42S22: Unknown column 'row_start' in 'field list' ERROR 42S22: Unknown column 'row_start' in 'field list'
set @@system_versioning_insert_history= 1; set @@system_versioning_insert_history= 1;
# REPLACE ignores system_versioning_insert_history
replace into t2 (a, row_end) values (0, '1980-01-01 00:00:00'); replace into t2 (a, row_end) values (0, '1980-01-01 00:00:00');
ERROR HY000: Incorrect row_start value: 'now' ERROR 42S22: Unknown column 'row_end' in 'field list'
replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1980-01-01 00:00:01'); replace into t3 (z, row_start) values (0, '1980-01-01 00:00:00');
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end; ERROR HY000: The value specified for generated column 'row_start' in table 't3' has been ignored
a row_start row_end replace into t3 values (0, '1980-01-01 00:00:00', '1981-01-01 00:00:00');
1 1980-01-01 00:00:00.000000 1980-01-01 00:00:01.000000 ERROR HY000: The value specified for generated column 'row_start' in table 't3' has been ignored
# Changing row_end via REPLACE is NOT possible, we just insert new row:
replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1990-01-01 00:00:01');
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
a row_start row_end
1 1980-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
1 1980-01-01 00:00:00.000000 1990-01-01 00:00:01.000000
# REPLACE is DELETE + INSERT
set timestamp=unix_timestamp('2020-10-10 10:10:10');
replace into t2 (a, row_start, row_end) values (1, '1971-01-01 00:00:00', '1980-01-01 00:00:01');
set timestamp=default;
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
a row_start row_end
1 1971-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
1 1980-01-01 00:00:00.000000 1990-01-01 00:00:01.000000
1 1980-01-01 00:00:00.000000 2020-10-10 10:10:10.000000
replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1 for system_time all
where x > 1 and row_end < TIMESTAMP'2038-01-19 03:14:07.999999';
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
a row_start row_end
1 1971-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
1 1980-01-01 00:00:00.000000 1990-01-01 00:00:01.000000
1 1980-01-01 00:00:00.000000 2020-10-10 10:10:10.000000
3 1980-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
5 1980-01-01 00:00:00.000000 1980-01-01 00:00:01.000000
# LOAD DATA # LOAD DATA
select x, row_start, row_end into outfile 'DATAFILE' from t1 for system_time all; select x, row_start, row_end into outfile 'DATAFILE' from t1 for system_time all;
create or replace table t2 like t1; create or replace table t2 like t1;

View File

@@ -127,6 +127,8 @@ update t2 set row_start= '1971-01-01 00:00:00';
insert t1 (x) values (2) on duplicate key update x= 3, row_end= '1970-01-01 00:00:00'; insert t1 (x) values (2) on duplicate key update x= 3, row_end= '1970-01-01 00:00:00';
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN --error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
insert t2 (y) values (1) on duplicate key update y= 3, row_end= '1970-01-01 00:00:00'; insert t2 (y) values (1) on duplicate key update y= 3, row_end= '1970-01-01 00:00:00';
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
insert t2 (y,row_end) values (1, '1970-01-01 00:00:00') on duplicate key update y= 3;
# this should work, row_start/row_end must be mentioned explicitly: # this should work, row_start/row_end must be mentioned explicitly:
insert into t1 values (4); insert into t1 values (4);
insert into t1 set x= 5, row_start= '1980-01-01 00:00:00', row_end= '1980-01-01 00:00:01'; 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-
--error ER_BAD_FIELD_ERROR --error ER_BAD_FIELD_ERROR
replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1; replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1;
set @@system_versioning_insert_history= 1; set @@system_versioning_insert_history= 1;
--replace_regex /'202\d-\d\d-\d\d .*'/'now'/ --echo # REPLACE ignores system_versioning_insert_history
--error ER_WRONG_VALUE --error ER_BAD_FIELD_ERROR
replace into t2 (a, row_end) values (0, '1980-01-01 00:00:00'); replace into t2 (a, row_end) values (0, '1980-01-01 00:00:00');
replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1980-01-01 00:00:01'); --error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end; replace into t3 (z, row_start) values (0, '1980-01-01 00:00:00');
--echo # Changing row_end via REPLACE is NOT possible, we just insert new row: --error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
replace into t2 (a, row_start, row_end) values (1, '1980-01-01 00:00:00', '1990-01-01 00:00:01'); replace into t3 values (0, '1980-01-01 00:00:00', '1981-01-01 00:00:00');
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
--echo # REPLACE is DELETE + INSERT
set timestamp=unix_timestamp('2020-10-10 10:10:10');
replace into t2 (a, row_start, row_end) values (1, '1971-01-01 00:00:00', '1980-01-01 00:00:01');
set timestamp=default;
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
eval replace into t2 (a, row_start, row_end) select x, row_start, row_end from t1 for system_time all
where x > 1 and row_end < $MAX_TIMESTAMP;
select a, row_start, row_end from t2 for system_time all order by a, row_start, row_end;
--echo # LOAD DATA --echo # LOAD DATA
--let DATAFILE= $MYSQLTEST_VARDIR/tmp/test_versioning_t3.data --let DATAFILE= $MYSQLTEST_VARDIR/tmp/test_versioning_t3.data

View File

@@ -5579,7 +5579,8 @@ public:
{ {
DBUG_ASSERT(table->versioned()); DBUG_ASSERT(table->versioned());
return table->versioned(VERS_TIMESTAMP) && return table->versioned(VERS_TIMESTAMP) &&
(variables.option_bits & OPTION_INSERT_HISTORY); (variables.option_bits & OPTION_INSERT_HISTORY) &&
lex->duplicates == DUP_ERROR;
} }
bool vers_insert_history(const Field *field) bool vers_insert_history(const Field *field)
@@ -5590,8 +5591,6 @@ public:
return false; return false;
if (lex->sql_command != SQLCOM_INSERT && if (lex->sql_command != SQLCOM_INSERT &&
lex->sql_command != SQLCOM_INSERT_SELECT && lex->sql_command != SQLCOM_INSERT_SELECT &&
lex->sql_command != SQLCOM_REPLACE &&
lex->sql_command != SQLCOM_REPLACE_SELECT &&
lex->sql_command != SQLCOM_LOAD) lex->sql_command != SQLCOM_LOAD)
return false; return false;
return !is_set_timestamp_forbidden(this); return !is_set_timestamp_forbidden(this);