Below is the list of changes that have just been committed into a local
5.0 repository of jimw. When jimw does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.1839 05/05/17 15:48:09 jimw@stripped +3 -0
Fix preserving prefix of keys when converting VARCHAR to TEXT.
(Bug #10543)
sql/sql_table.cc
1.246 05/05/17 15:48:06 jimw@stripped +40 -6
Only reset the length of a key part when changing from a
non-prefixable key to a prefixable-key or vice versa, or
when the prefix is smaller than the length of the field.
mysql-test/t/type_varchar.test
1.6 05/05/17 15:48:06 jimw@stripped +12 -0
Add test for bug #10543
mysql-test/r/type_varchar.result
1.6 05/05/17 15:48:06 jimw@stripped +23 -0
Add results
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: jimw
# Host: rama.(none)
# Root: /home/jimw/my/mysql-5.0-10543
--- 1.245/sql/sql_table.cc 2005-05-16 05:21:31 -07:00
+++ 1.246/sql/sql_table.cc 2005-05-17 15:48:06 -07:00
@@ -2965,6 +2965,34 @@
/*
+ Check whether a field type can have a prefixed key
+
+ SYNOPSIS
+ type_can_have_prefix_key()
+ type field type
+
+ RETURN
+ TRUE Type can have a prefixed key
+ FALSE Type can not have a prefixed key
+*/
+
+static bool type_can_have_prefix_key(enum enum_field_types type)
+{
+ switch (type) {
+ case MYSQL_TYPE_VARCHAR:
+ case MYSQL_TYPE_TINY_BLOB:
+ case MYSQL_TYPE_MEDIUM_BLOB:
+ case MYSQL_TYPE_LONG_BLOB:
+ case MYSQL_TYPE_BLOB:
+ case MYSQL_TYPE_VAR_STRING:
+ case MYSQL_TYPE_STRING:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/*
Alter table
*/
@@ -3334,12 +3362,18 @@
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 a prefix according to its new type, or
+ should not have a prefix according to its previous type, or the
+ field length is less than the prefix length, unset the prefix
+ length.
+ */
+ if (!type_can_have_prefix_key(cfield->field->type()) ||
+ !type_can_have_prefix_key(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,
--- 1.5/mysql-test/r/type_varchar.result 2005-04-21 09:06:02 -07:00
+++ 1.6/mysql-test/r/type_varchar.result 2005-05-17 15:48:06 -07:00
@@ -392,3 +392,26 @@
a b min(t1.b)
22 NULL NULL
drop table t1, t2;
+create table t1 (f1 varchar(65500));
+create index index1 on t1(f1(10));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` varchar(65500) default NULL,
+ KEY `index1` (`f1`(10))
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+alter table t1 modify f1 varchar(255);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` varchar(255) default NULL,
+ KEY `index1` (`f1`(10))
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+alter table t1 modify f1 tinytext;
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` tinytext,
+ KEY `index1` (`f1`(10))
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop table t1;
--- 1.5/mysql-test/t/type_varchar.test 2005-04-21 09:06:02 -07:00
+++ 1.6/mysql-test/t/type_varchar.test 2005-05-17 15:48:06 -07:00
@@ -118,3 +118,15 @@
select t1.a, t1.b, min(t1.b) from t1 inner join t2 ON t2.a = t1.a
group by t1.b, t1.a;
drop table t1, t2;
+
+#
+# Bug #10543: convert varchar with index to text
+#
+create table t1 (f1 varchar(65500));
+create index index1 on t1(f1(10));
+show create table t1;
+alter table t1 modify f1 varchar(255);
+show create table t1;
+alter table t1 modify f1 tinytext;
+show create table t1;
+drop table t1;
| Thread |
|---|
| • bk commit into 5.0 tree (jimw:1.1839) BUG#10543 | Jim Winstead | 18 May |