diff options
author | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2020-03-23 13:13:20 +0530 |
---|---|---|
committer | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2020-03-23 13:18:00 +0530 |
commit | f7599f47999bb197dba36e54d0d5677b3b15f12a (patch) | |
tree | cfc08485849a5f2272e57d19f3068804a849fc51 | |
parent | 81f700015e746ac590b55bcb21bf21ba0d6febfc (diff) | |
download | mariadb-git-f7599f47999bb197dba36e54d0d5677b3b15f12a.tar.gz |
MDEV-21792 Server aborts upon attempt to create foreign key on spatial field
- mbmaxlen is always 0 for binary field. Ignore the assert of checking
field->prefix_len % field->col->mbmaxlen == 0.
-rw-r--r-- | mysql-test/suite/innodb/r/foreign_key.result | 4 | ||||
-rw-r--r-- | mysql-test/suite/innodb/t/foreign_key.test | 8 | ||||
-rw-r--r-- | storage/innobase/dict/dict0dict.cc | 3 | ||||
-rw-r--r-- | storage/innobase/include/dict0mem.h | 5 |
4 files changed, 18 insertions, 2 deletions
diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index 288b6bb835d..dc88643fcf9 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -522,3 +522,7 @@ test.t1 check status OK DROP TABLE t1; SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency; # End of 10.2 tests +CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)), +FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB; +ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") +# End of 10.4 tests diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index 06cab983656..672539b9271 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -498,4 +498,12 @@ SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency; --echo # End of 10.2 tests +# MDEV-21792 Server aborts upon attempt to create foreign key on spatial field +# Fail to create foreign key for spatial fields +--error ER_CANT_CREATE_TABLE +CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)), + FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB; + +-- echo # End of 10.4 tests + --source include/wait_until_count_sessions.inc diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 29d33643c75..947fce1ae3a 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -1839,7 +1839,8 @@ dict_index_add_to_cache( > field->col->max_prefix) { /* Set the max_prefix value based on the prefix_len. */ - ut_ad(field->prefix_len % field->col->mbmaxlen == 0); + ut_ad(field->col->is_binary() + || field->prefix_len % field->col->mbmaxlen == 0); field->col->max_prefix = field->prefix_len; } ut_ad(field->col->ord_part == 1); diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 36721f1942a..31f10f6f9a9 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -2,7 +2,7 @@ Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, Facebook Inc. -Copyright (c) 2013, 2019, MariaDB Corporation. +Copyright (c) 2013, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -733,6 +733,9 @@ public: | CHAR_COLL_MASK << 16 | DATA_LONG_TRUE_VARCHAR)); } + + /** @return whether the column values are comparable by memcmp() */ + inline bool is_binary() const { return prtype & DATA_BINARY_TYPE; } }; /** Index information put in a list of virtual column structure. Index |