diff options
author | Nikita Malyavin <nikitamalyavin@gmail.com> | 2020-03-17 02:59:11 +1000 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2020-03-31 17:42:34 +0200 |
commit | 244ff3e5a09eb1b4b3d4bc75371260550a47f576 (patch) | |
tree | 985147d3183c5d9d399e56cc452055eb23fc0fe2 | |
parent | 62e7ad2bbcf89f4a254be0bfbfcbb437f14e6e78 (diff) | |
download | mariadb-git-244ff3e5a09eb1b4b3d4bc75371260550a47f576.tar.gz |
forbid REPLACE/ODKU on tables containing WITHOUT OVERLAPS
-rw-r--r-- | mysql-test/suite/period/r/overlaps.result | 22 | ||||
-rw-r--r-- | mysql-test/suite/period/t/overlaps.test | 28 | ||||
-rw-r--r-- | sql/sql_insert.cc | 30 | ||||
-rw-r--r-- | sql/sql_insert.h | 2 | ||||
-rw-r--r-- | sql/sql_load.cc | 3 |
5 files changed, 85 insertions, 0 deletions
diff --git a/mysql-test/suite/period/r/overlaps.result b/mysql-test/suite/period/r/overlaps.result index 042c68d4f54..2d9af4e23c3 100644 --- a/mysql-test/suite/period/r/overlaps.result +++ b/mysql-test/suite/period/r/overlaps.result @@ -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; diff --git a/mysql-test/suite/period/t/overlaps.test b/mysql-test/suite/period/t/overlaps.test index fdd277350f2..a3399570bd8 100644 --- a/mysql-test/suite/period/t/overlaps.test +++ b/mysql-test/suite/period/t/overlaps.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; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 5de2cc6d539..c1e7d3bde79 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -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. diff --git a/sql/sql_insert.h b/sql/sql_insert.h index f1c2334235d..3f741640c1c 100644 --- a/sql/sql_insert.h +++ b/sql/sql_insert.h @@ -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); diff --git a/sql/sql_load.cc b/sql/sql_load.cc index b52846c1390..3d1f0bf0958 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -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; |