Skip to content

Commit

Permalink
MDEV-21792 Server aborts upon attempt to create foreign key on spatia…
Browse files Browse the repository at this point in the history
…l field

- mbmaxlen is always 0 for binary field. Ignore the assert of checking
field->prefix_len % field->col->mbmaxlen == 0.
  • Loading branch information
Thirunarayanan committed Mar 23, 2020
1 parent 81f7000 commit f7599f4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions mysql-test/suite/innodb/r/foreign_key.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions mysql-test/suite/innodb/t/foreign_key.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion storage/innobase/dict/dict0dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion storage/innobase/include/dict0mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -733,6 +733,9 @@ struct dict_col_t{
| 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
Expand Down

0 comments on commit f7599f4

Please sign in to comment.