summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2005-05-25 18:11:47 -0700
committerunknown <jimw@mysql.com>2005-05-25 18:11:47 -0700
commitf0329bfb8c9215272cc176c874f79d14a02d20fa (patch)
treedf8ba3b3f75b02647220adb07b938891c3179959 /sql/sql_table.cc
parentf0f9b5959eecb87b369fc45c981d926b79de0c61 (diff)
downloadmariadb-git-f0329bfb8c9215272cc176c874f79d14a02d20fa.tar.gz
Fix partial keys when converting VARCHAR to TEXT. (Bug #10543)
mysql-test/r/type_varchar.result: Update results mysql-test/t/type_varchar.test: Add new regression test sql/field.cc: Add Field::type_can_have_key_part() static method sql/field.h: Add Field::type_can_have_key_part() signature. sql/sql_table.cc: Only reset the length of a key part when changing from a field type that can't be used partially to a field that can, or vice versa, or when the part is smaller than the length of the field.
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc21
1 files changed, 15 insertions, 6 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 4ddef3fc653..2768d503751 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -3334,12 +3334,21 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
continue; // Field is removed
uint key_part_length=key_part->length;
if (cfield->field) // Not new field
- { // Check if sub key
- if (cfield->field->type() != FIELD_TYPE_BLOB &&
- (cfield->field->pack_length() == key_part_length ||
- cfield->length <= key_part_length /
- key_part->field->charset()->mbmaxlen))
- key_part_length=0; // Use whole field
+ {
+ /*
+ If the field can't have only a part used in a key according to its
+ new type, or should not be used partially according to its
+ previous type, or the field length is less than the key part
+ length, unset the key part length.
+
+ BLOBs may have cfield->length == 0, which is why we test it before
+ checking whether cfield->length < key_part_length (in chars).
+ */
+ if (!Field::type_can_have_key_part(cfield->field->type()) ||
+ !Field::type_can_have_key_part(cfield->sql_type) ||
+ (cfield->length && (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;
key_parts.push_back(new key_part_spec(cfield->field_name,