mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Merge next-mr -> next-4284.
This commit is contained in:
@ -5792,6 +5792,35 @@ bool alter_table_manage_keys(TABLE *table, int indexes_were_disabled,
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
/**
|
||||
maximum possible length for certain blob types.
|
||||
|
||||
@param[in] type Blob type (e.g. MYSQL_TYPE_TINY_BLOB)
|
||||
|
||||
@return
|
||||
length
|
||||
*/
|
||||
|
||||
static uint
|
||||
blob_length_by_type(enum_field_types type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MYSQL_TYPE_TINY_BLOB:
|
||||
return 255;
|
||||
case MYSQL_TYPE_BLOB:
|
||||
return 65535;
|
||||
case MYSQL_TYPE_MEDIUM_BLOB:
|
||||
return 16777215;
|
||||
case MYSQL_TYPE_LONG_BLOB:
|
||||
return 4294967295U;
|
||||
default:
|
||||
DBUG_ASSERT(0); // we should never go here
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Prepare column and key definitions for CREATE TABLE in ALTER TABLE.
|
||||
|
||||
@ -6087,6 +6116,14 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
|
||||
BLOBs may have cfield->length == 0, which is why we test it before
|
||||
checking whether cfield->length < key_part_length (in chars).
|
||||
|
||||
In case of TEXTs we check the data type maximum length *in bytes*
|
||||
to key part length measured *in characters* (i.e. key_part_length
|
||||
devided to mbmaxlen). This is because it's OK to have:
|
||||
CREATE TABLE t1 (a tinytext, key(a(254)) character set utf8);
|
||||
In case of this example:
|
||||
- data type maximum length is 255.
|
||||
- key_part_length is 1016 (=254*4, where 4 is mbmaxlen)
|
||||
*/
|
||||
if (!Field::type_can_have_key_part(cfield->field->type()) ||
|
||||
!Field::type_can_have_key_part(cfield->sql_type) ||
|
||||
@ -6094,8 +6131,11 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
(key_info->flags & HA_SPATIAL) ||
|
||||
(cfield->field->field_length == key_part_length &&
|
||||
!f_is_blob(key_part->key_type)) ||
|
||||
(cfield->length && (cfield->length < key_part_length /
|
||||
key_part->field->charset()->mbmaxlen)))
|
||||
(cfield->length && (((cfield->sql_type >= MYSQL_TYPE_TINY_BLOB &&
|
||||
cfield->sql_type <= MYSQL_TYPE_BLOB) ?
|
||||
blob_length_by_type(cfield->sql_type) :
|
||||
cfield->length) <
|
||||
key_part_length / key_part->field->charset()->mbmaxlen)))
|
||||
key_part_length= 0; // Use whole field
|
||||
}
|
||||
key_part_length /= key_part->field->charset()->mbmaxlen;
|
||||
|
Reference in New Issue
Block a user