Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
ef9ef1f9
Commit
ef9ef1f9
authored
May 25, 2005
by
jimw@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix partial keys when converting VARCHAR to TEXT. (Bug #10543)
parent
b763679f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
6 deletions
+84
-6
mysql-test/r/type_varchar.result
mysql-test/r/type_varchar.result
+23
-0
mysql-test/t/type_varchar.test
mysql-test/t/type_varchar.test
+12
-0
sql/field.cc
sql/field.cc
+33
-0
sql/field.h
sql/field.h
+1
-0
sql/sql_table.cc
sql/sql_table.cc
+15
-6
No files found.
mysql-test/r/type_varchar.result
View file @
ef9ef1f9
...
@@ -392,3 +392,26 @@ group by t1.b, t1.a;
...
@@ -392,3 +392,26 @@ group by t1.b, t1.a;
a b min(t1.b)
a b min(t1.b)
22 NULL NULL
22 NULL NULL
drop table t1, t2;
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;
mysql-test/t/type_varchar.test
View file @
ef9ef1f9
...
@@ -118,3 +118,15 @@ insert into t2 values (22), (22);
...
@@ -118,3 +118,15 @@ insert into t2 values (22), (22);
select
t1
.
a
,
t1
.
b
,
min
(
t1
.
b
)
from
t1
inner
join
t2
ON
t2
.
a
=
t1
.
a
select
t1
.
a
,
t1
.
b
,
min
(
t1
.
b
)
from
t1
inner
join
t2
ON
t2
.
a
=
t1
.
a
group
by
t1
.
b
,
t1
.
a
;
group
by
t1
.
b
,
t1
.
a
;
drop
table
t1
,
t2
;
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
;
sql/field.cc
View file @
ef9ef1f9
...
@@ -982,6 +982,39 @@ Item_result Field::result_merge_type(enum_field_types field_type)
...
@@ -982,6 +982,39 @@ Item_result Field::result_merge_type(enum_field_types field_type)
Static help functions
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
Numeric fields base class constructor
*/
*/
...
...
sql/field.h
View file @
ef9ef1f9
...
@@ -119,6 +119,7 @@ class Field
...
@@ -119,6 +119,7 @@ class Field
virtual
Item_result
result_type
()
const
=
0
;
virtual
Item_result
result_type
()
const
=
0
;
virtual
Item_result
cmp_type
()
const
{
return
result_type
();
}
virtual
Item_result
cmp_type
()
const
{
return
result_type
();
}
virtual
Item_result
cast_to_int_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
enum_field_types
field_type_merge
(
enum_field_types
,
enum_field_types
);
static
Item_result
result_merge_type
(
enum_field_types
);
static
Item_result
result_merge_type
(
enum_field_types
);
bool
eq
(
Field
*
field
)
bool
eq
(
Field
*
field
)
...
...
sql/sql_table.cc
View file @
ef9ef1f9
...
@@ -3334,12 +3334,21 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
...
@@ -3334,12 +3334,21 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
continue
;
// Field is removed
continue
;
// Field is removed
uint
key_part_length
=
key_part
->
length
;
uint
key_part_length
=
key_part
->
length
;
if
(
cfield
->
field
)
// Not new field
if
(
cfield
->
field
)
// Not new field
{
// Check if sub key
{
if
(
cfield
->
field
->
type
()
!=
FIELD_TYPE_BLOB
&&
/*
(
cfield
->
field
->
pack_length
()
==
key_part_length
||
If the field can't have only a part used in a key according to its
cfield
->
length
<=
key_part_length
/
new type, or should not be used partially according to its
key_part
->
field
->
charset
()
->
mbmaxlen
))
previous type, or the field length is less than the key part
key_part_length
=
0
;
// Use whole field
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_part_length
/=
key_part
->
field
->
charset
()
->
mbmaxlen
;
key_parts
.
push_back
(
new
key_part_spec
(
cfield
->
field_name
,
key_parts
.
push_back
(
new
key_part_spec
(
cfield
->
field_name
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment