Commit 53eb9871 authored by unknown's avatar unknown

A fix (bug #6142: SELECT DISTINCT on key field crashes server)


sql/opt_range.cc:
  A fix (bug #6142: SELECT DISTINCT on key field crashes server)
  Code clean-up.
parent 00bbd9a2
...@@ -1897,3 +1897,9 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1897,3 +1897,9 @@ id select_type table type possible_keys key key_len ref rows Extra
drop table t1; drop table t1;
drop table t2; drop table t2;
drop table t3; drop table t3;
create table t1 (
a varchar(30), b varchar(30), primary key(a), key(b)
) engine=innodb;
select distinct a from t1;
a
drop table t1;
...@@ -577,3 +577,13 @@ explain select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b; ...@@ -577,3 +577,13 @@ explain select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b;
drop table t1; drop table t1;
drop table t2; drop table t2;
drop table t3; drop table t3;
#
# Bug #6142: a problem with the empty innodb table
#
create table t1 (
a varchar(30), b varchar(30), primary key(a), key(b)
) engine=innodb;
select distinct a from t1;
drop table t1;
...@@ -7040,17 +7040,16 @@ get_constant_key_infix(KEY *index_info, SEL_ARG *index_range_tree, ...@@ -7040,17 +7040,16 @@ get_constant_key_infix(KEY *index_info, SEL_ARG *index_range_tree,
static inline uint static inline uint
get_field_keypart(KEY *index, Field *field) get_field_keypart(KEY *index, Field *field)
{ {
KEY_PART_INFO *part= index->key_part; KEY_PART_INFO *part, *end;
uint key_part_num= 0; uint key_part_num= 0;
while (part != part + index->key_parts) for (part= index->key_part, end= part + index->key_parts; part < end; part++)
{ {
key_part_num++; key_part_num++;
if (field->eq(part->field)) if (field->eq(part->field))
return key_part_num; return key_part_num;
part++;
} }
return key_part_num; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment