Skip to content

Commit 244ff3e

Browse files
FooBarriorvuvova
authored andcommitted
forbid REPLACE/ODKU on tables containing WITHOUT OVERLAPS
1 parent 62e7ad2 commit 244ff3e

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

mysql-test/suite/period/r/overlaps.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,26 @@ ERROR 23000: Duplicate entry 'test' for key 'b'
204204
insert into t values (1, '2020-03-05', '2020-03-10', 'test2');
205205
insert into t values (1, '2020-03-03', '2020-03-10', 'test3');
206206
ERROR 23000: Duplicate entry '1-2020-03-10-2020-03-03' for key 'x'
207+
create or replace table t (x int, s date, e date, period for apptime(s,e),
208+
unique(x, apptime without overlaps));
209+
replace into t values (1, '2020-03-03', '2020-03-10');
210+
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
211+
insert into t values (1, '2020-03-03', '2020-03-10')
212+
on duplicate key update x = 2;
213+
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
214+
select * from t;
215+
x s e
216+
select * into outfile 'tmp_t.txt' from t;
217+
load data infile 'tmp_t.txt' into table t;
218+
load data infile 'tmp_t.txt' replace into table t;
219+
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
220+
insert into t values (1, '2020-03-01', '2020-03-05');
221+
select * into outfile 'tmp_t.txt' from t;
222+
load data infile 'tmp_t.txt' into table t;
223+
ERROR 23000: Duplicate entry '1-2020-03-05-2020-03-01' for key 'x'
224+
load data infile 'tmp_t.txt' ignore into table t;
225+
Warnings:
226+
Warning 1062 Duplicate entry '1-2020-03-05-2020-03-01' for key 'x'
227+
load data infile 'tmp_t.txt' replace into table t;
228+
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
207229
create or replace database test;

mysql-test/suite/period/t/overlaps.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,32 @@ insert into t values (1, '2020-03-05', '2020-03-10', 'test2');
201201
--error ER_DUP_ENTRY
202202
insert into t values (1, '2020-03-03', '2020-03-10', 'test3');
203203

204+
let $MYSQLD_DATADIR= `select @@datadir`;
205+
create or replace table t (x int, s date, e date, period for apptime(s,e),
206+
unique(x, apptime without overlaps));
207+
--error ER_NOT_SUPPORTED_YET
208+
replace into t values (1, '2020-03-03', '2020-03-10');
209+
--error ER_NOT_SUPPORTED_YET
210+
insert into t values (1, '2020-03-03', '2020-03-10')
211+
on duplicate key update x = 2;
212+
213+
select * from t;
214+
select * into outfile 'tmp_t.txt' from t;
215+
load data infile 'tmp_t.txt' into table t;
216+
--error ER_NOT_SUPPORTED_YET
217+
load data infile 'tmp_t.txt' replace into table t;
218+
remove_file $MYSQLD_DATADIR/test/tmp_t.txt;
219+
220+
insert into t values (1, '2020-03-01', '2020-03-05');
221+
select * into outfile 'tmp_t.txt' from t;
222+
--error ER_DUP_ENTRY
223+
load data infile 'tmp_t.txt' into table t;
224+
225+
load data infile 'tmp_t.txt' ignore into table t;
226+
227+
--error ER_NOT_SUPPORTED_YET
228+
load data infile 'tmp_t.txt' replace into table t;
229+
230+
remove_file $MYSQLD_DATADIR/test/tmp_t.txt;
231+
204232
create or replace database test;

sql/sql_insert.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,33 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view)
14101410
}
14111411

14121412

1413+
/**
1414+
TODO remove when MDEV-17395 will be closed
1415+
1416+
Checks if REPLACE or ON DUPLICATE UPDATE was executed on table containing
1417+
WITHOUT OVERLAPS key.
1418+
1419+
@return
1420+
0 if no error
1421+
ER_NOT_SUPPORTED_YET if the above condidion was met
1422+
*/
1423+
int check_duplic_insert_without_overlaps(THD *thd, TABLE *table,
1424+
enum_duplicates duplic)
1425+
{
1426+
if (duplic == DUP_REPLACE || duplic == DUP_UPDATE)
1427+
{
1428+
for (uint k = 0; k < table->s->keys; k++)
1429+
{
1430+
if (table->key_info[k].without_overlaps)
1431+
{
1432+
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "WITHOUT OVERLAPS");
1433+
return ER_NOT_SUPPORTED_YET;
1434+
}
1435+
}
1436+
}
1437+
return 0;
1438+
}
1439+
14131440
/*
14141441
Check if table can be updated
14151442
@@ -1607,6 +1634,9 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
16071634
if (!table)
16081635
table= table_list->table;
16091636

1637+
if (check_duplic_insert_without_overlaps(thd, table, duplic) != 0)
1638+
DBUG_RETURN(true);
1639+
16101640
if (table->versioned(VERS_TIMESTAMP) && duplic == DUP_REPLACE)
16111641
{
16121642
// Additional memory may be required to create historical items.

sql/sql_insert.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void upgrade_lock_type_for_insert(THD *thd, thr_lock_type *lock_type,
3838
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
3939
TABLE_LIST *table_list);
4040
int vers_insert_history_row(TABLE *table);
41+
int check_duplic_insert_without_overlaps(THD *thd, TABLE *table,
42+
enum_duplicates duplic);
4143
int write_record(THD *thd, TABLE *table, COPY_INFO *info,
4244
select_result *returning= NULL);
4345
void kill_delayed_threads(void);

sql/sql_load.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list,
441441
is_concurrent= (table_list->lock_type == TL_WRITE_CONCURRENT_INSERT);
442442
#endif
443443

444+
if (check_duplic_insert_without_overlaps(thd, table, handle_duplicates) != 0)
445+
DBUG_RETURN(true);
446+
444447
if (!fields_vars.elements)
445448
{
446449
Field_iterator_table_ref field_iterator;

0 commit comments

Comments
 (0)