Skip to content

Commit ff3fd46

Browse files
author
evgen@moonbone.local
committed
Bug#29461: Sort order of the collation wasn't used when comparing characters
with the space character. When the my_strnncollsp_simple function compares two strings and one is a prefix of another then this function compares characters in the rest of longer key with the space character to find whether the longer key is greater or less. But the sort order of the collation isn't used in this comparison. This may lead to a wrong comparison result, wrongly created index or wrong order of the result set of a query with the ORDER BY clause. Now the my_strnncollsp_simple function uses collation sort order to compare the characters in the rest of longer key with the space character.
1 parent 5b1e1ee commit ff3fd46

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

mysql-test/r/ctype_collate.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,11 @@ check table t1 extended;
603603
Table Op Msg_type Msg_text
604604
test.t1 check status OK
605605
drop table t1;
606+
create table t1 (a varchar(2) character set latin7 collate latin7_general_ci,key(a));
607+
insert into t1 set a=0x4c20;
608+
insert into t1 set a=0x6c;
609+
insert into t1 set a=0x4c98;
610+
check table t1 extended;
611+
Table Op Msg_type Msg_text
612+
test.t1 check status OK
613+
drop table t1;

mysql-test/t/ctype_collate.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,14 @@ insert into t1 set f1=0x3F3F1E563F;
218218
insert into t1 set f1=0x3F3F;
219219
check table t1 extended;
220220
drop table t1;
221+
222+
#
223+
# Bug#29461: Sort order of the collation wasn't used when comparing characters
224+
# with the space character.
225+
#
226+
create table t1 (a varchar(2) character set latin7 collate latin7_general_ci,key(a));
227+
insert into t1 set a=0x4c20;
228+
insert into t1 set a=0x6c;
229+
insert into t1 set a=0x4c98;
230+
check table t1 extended;
231+
drop table t1;

strings/ctype-simple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ int my_strnncollsp_simple(CHARSET_INFO * cs, const uchar *a, uint a_length,
179179
}
180180
for (end= a + a_length-length; a < end ; a++)
181181
{
182-
if (*a != ' ')
182+
if (map[*a] != ' ')
183183
return (map[*a] < ' ') ? -swap : swap;
184184
}
185185
}

0 commit comments

Comments
 (0)