mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Bug#50542 5.5.x doesn't check length of key prefixes:
corruption and crash results An index creation statement where the index key is larger/wider than the column it references should throw an error. A statement like: CREATE TABLE t1 (a CHAR(1), PRIMARY KEY (A(255))) did not error, but a segmentation fault followed when an insertion was attempted on the table The partial key validiation clause has been restructured to (hopefully) better document which uses of partial keys are valid.
This commit is contained in:
@ -3292,22 +3292,21 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
}
|
||||
}
|
||||
}
|
||||
// Catch invalid use of partial keys
|
||||
else if (!f_is_geom(sql_field->pack_flag) &&
|
||||
((column->length > length &&
|
||||
!Field::type_can_have_key_part (sql_field->sql_type)) ||
|
||||
((f_is_packed(sql_field->pack_flag) ||
|
||||
((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
|
||||
(key_info->flags & HA_NOSAME))) &&
|
||||
column->length != length)))
|
||||
{
|
||||
/* Catch invalid uses of partial keys.
|
||||
A key is identified as 'partial' if column->length != length.
|
||||
A partial key is invalid if they data type does
|
||||
not allow it, or the field is packed (as in MyISAM),
|
||||
or the storage engine doesn't allow prefixed search and
|
||||
the key is primary key.
|
||||
*/
|
||||
|
||||
// is the key partial?
|
||||
column->length != length &&
|
||||
// is prefix length bigger than field length?
|
||||
(column->length > length ||
|
||||
// can the field have a partial key?
|
||||
!Field::type_can_have_key_part (sql_field->sql_type) ||
|
||||
// a packed field can't be used in a partial key
|
||||
f_is_packed(sql_field->pack_flag) ||
|
||||
// does the storage engine allow prefixed search?
|
||||
((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
|
||||
// and is this a 'unique' key?
|
||||
(key_info->flags & HA_NOSAME))))
|
||||
{
|
||||
my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user