Commit 244ff3e5 authored by Nikita Malyavin's avatar Nikita Malyavin Committed by Sergei Golubchik

forbid REPLACE/ODKU on tables containing WITHOUT OVERLAPS

parent 62e7ad2b
......@@ -204,4 +204,26 @@ ERROR 23000: Duplicate entry 'test' for key 'b'
insert into t values (1, '2020-03-05', '2020-03-10', 'test2');
insert into t values (1, '2020-03-03', '2020-03-10', 'test3');
ERROR 23000: Duplicate entry '1-2020-03-10-2020-03-03' for key 'x'
create or replace table t (x int, s date, e date, period for apptime(s,e),
unique(x, apptime without overlaps));
replace into t values (1, '2020-03-03', '2020-03-10');
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
insert into t values (1, '2020-03-03', '2020-03-10')
on duplicate key update x = 2;
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
select * from t;
x s e
select * into outfile 'tmp_t.txt' from t;
load data infile 'tmp_t.txt' into table t;
load data infile 'tmp_t.txt' replace into table t;
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
insert into t values (1, '2020-03-01', '2020-03-05');
select * into outfile 'tmp_t.txt' from t;
load data infile 'tmp_t.txt' into table t;
ERROR 23000: Duplicate entry '1-2020-03-05-2020-03-01' for key 'x'
load data infile 'tmp_t.txt' ignore into table t;
Warnings:
Warning 1062 Duplicate entry '1-2020-03-05-2020-03-01' for key 'x'
load data infile 'tmp_t.txt' replace into table t;
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
create or replace database test;
......@@ -201,4 +201,32 @@ insert into t values (1, '2020-03-05', '2020-03-10', 'test2');
--error ER_DUP_ENTRY
insert into t values (1, '2020-03-03', '2020-03-10', 'test3');
let $MYSQLD_DATADIR= `select @@datadir`;
create or replace table t (x int, s date, e date, period for apptime(s,e),
unique(x, apptime without overlaps));
--error ER_NOT_SUPPORTED_YET
replace into t values (1, '2020-03-03', '2020-03-10');
--error ER_NOT_SUPPORTED_YET
insert into t values (1, '2020-03-03', '2020-03-10')
on duplicate key update x = 2;
select * from t;
select * into outfile 'tmp_t.txt' from t;
load data infile 'tmp_t.txt' into table t;
--error ER_NOT_SUPPORTED_YET
load data infile 'tmp_t.txt' replace into table t;
remove_file $MYSQLD_DATADIR/test/tmp_t.txt;
insert into t values (1, '2020-03-01', '2020-03-05');
select * into outfile 'tmp_t.txt' from t;
--error ER_DUP_ENTRY
load data infile 'tmp_t.txt' into table t;
load data infile 'tmp_t.txt' ignore into table t;
--error ER_NOT_SUPPORTED_YET
load data infile 'tmp_t.txt' replace into table t;
remove_file $MYSQLD_DATADIR/test/tmp_t.txt;
create or replace database test;
......@@ -1410,6 +1410,33 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view)
}
/**
TODO remove when MDEV-17395 will be closed
Checks if REPLACE or ON DUPLICATE UPDATE was executed on table containing
WITHOUT OVERLAPS key.
@return
0 if no error
ER_NOT_SUPPORTED_YET if the above condidion was met
*/
int check_duplic_insert_without_overlaps(THD *thd, TABLE *table,
enum_duplicates duplic)
{
if (duplic == DUP_REPLACE || duplic == DUP_UPDATE)
{
for (uint k = 0; k < table->s->keys; k++)
{
if (table->key_info[k].without_overlaps)
{
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "WITHOUT OVERLAPS");
return ER_NOT_SUPPORTED_YET;
}
}
}
return 0;
}
/*
Check if table can be updated
......@@ -1607,6 +1634,9 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
if (!table)
table= table_list->table;
if (check_duplic_insert_without_overlaps(thd, table, duplic) != 0)
DBUG_RETURN(true);
if (table->versioned(VERS_TIMESTAMP) && duplic == DUP_REPLACE)
{
// Additional memory may be required to create historical items.
......
......@@ -38,6 +38,8 @@ void upgrade_lock_type_for_insert(THD *thd, thr_lock_type *lock_type,
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
TABLE_LIST *table_list);
int vers_insert_history_row(TABLE *table);
int check_duplic_insert_without_overlaps(THD *thd, TABLE *table,
enum_duplicates duplic);
int write_record(THD *thd, TABLE *table, COPY_INFO *info,
select_result *returning= NULL);
void kill_delayed_threads(void);
......
......@@ -441,6 +441,9 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list,
is_concurrent= (table_list->lock_type == TL_WRITE_CONCURRENT_INSERT);
#endif
if (check_duplic_insert_without_overlaps(thd, table, handle_duplicates) != 0)
DBUG_RETURN(true);
if (!fields_vars.elements)
{
Field_iterator_table_ref field_iterator;
......
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