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.1912 05/05/25 18:11:47 jimw@stripped +5 -0
Fix partial keys when converting VARCHAR to TEXT. (Bug #10543)
sql/sql_table.cc
1.246 05/05/25 18:11:44 jimw@stripped +15 -6
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.
sql/field.h
1.159 05/05/25 18:11:44 jimw@stripped +1 -0
Add Field::type_can_have_key_part() signature.
sql/field.cc
1.261 05/05/25 18:11:44 jimw@stripped +33 -0
Add Field::type_can_have_key_part() static method
mysql-test/t/type_varchar.test
1.6 05/05/25 18:11:44 jimw@stripped +12 -0
Add new regression test
mysql-test/r/type_varchar.result
1.6 05/05/25 18:11:44 jimw@stripped +23 -0
Update 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.260/sql/field.cc 2005-05-13 01:22:22 -07:00
+++ 1.261/sql/field.cc 2005-05-25 18:11:44 -07:00
@@ -982,6 +982,39 @@
Static help functions
*****************************************************************************/
+
+/*
+ Check whether a field type can be partially indexed by a key
+
+ This is a static method, rather than a virtual function, because we need
+ to check the type of a non-Field in mysql_alter_table().
+
+ SYNOPSIS
+ type_can_have_key_part()
+ type field type
+
+ RETURN
+ TRUE Type can have a prefixed key
+ FALSE Type can not have a prefixed key
+*/
+
+bool Field::type_can_have_key_part(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;
+ }
+}
+
+
/*
Numeric fields base class constructor
*/
--- 1.158/sql/field.h 2005-05-12 05:45:13 -07:00
+++ 1.159/sql/field.h 2005-05-25 18:11:44 -07:00
@@ -119,6 +119,7 @@
virtual Item_result result_type () const=0;
virtual Item_result cmp_type () const { return result_type(); }
virtual Item_result cast_to_int_type () const { return result_type(); }
+ static bool type_can_have_key_part(enum_field_types);
static enum_field_types field_type_merge(enum_field_types, enum_field_types);
static Item_result result_merge_type(enum_field_types);
bool eq(Field *field)
--- 1.245/sql/sql_table.cc 2005-05-16 05:21:31 -07:00
+++ 1.246/sql/sql_table.cc 2005-05-25 18:11:44 -07:00
@@ -3334,12 +3334,21 @@
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,
--- 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-25 18:11:44 -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-25 18:11:44 -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.1912) BUG#10543 | Jim Winstead | 26 May |