Commit 6bc7bd0e authored by Sergei Golubchik's avatar Sergei Golubchik

Fix code in make_sortkey() that only worked by chance

(assert added by MySQL verified that strnxfrm can only *increase*
the string length if from == to, and the latter is a random
decision made by individual items and String::realloc).
  
Fix it by avoiding the memcpy in the first place.
parent 0dc23679
......@@ -985,8 +985,8 @@ static void make_sortkey(register Sort_param *param,
if (maybe_null)
*to++=1;
/* All item->str() to use some extra byte for end null.. */
String tmp((char*) to,sort_field->length+4,cs);
char *tmp_buffer= param->tmp_buffer ? param->tmp_buffer : (char*)to;
String tmp(tmp_buffer, param->sort_length, cs);
String *res= item->str_result(&tmp);
if (!res)
{
......@@ -1011,19 +1011,11 @@ static void make_sortkey(register Sort_param *param,
length= res->length();
if (sort_field->need_strxnfrm)
{
char *from=(char*) res->ptr();
uint tmp_length __attribute__((unused));
if ((uchar*) from == to)
{
DBUG_ASSERT(sort_field->length >= length);
set_if_smaller(length,sort_field->length);
memcpy(param->tmp_buffer,from,length);
from=param->tmp_buffer;
}
tmp_length= cs->coll->strnxfrm(cs, to, sort_field->length,
item->max_char_length() *
cs->strxfrm_multiply,
(uchar*) from, length,
(uchar*) res->ptr(), length,
MY_STRXFRM_PAD_WITH_SPACE |
MY_STRXFRM_PAD_TO_MAXLEN);
DBUG_ASSERT(tmp_length == sort_field->length);
......@@ -1046,6 +1038,7 @@ static void make_sortkey(register Sort_param *param,
store_length(to + sort_field_length, length,
sort_field->suffix_length);
}
/* apply cs->sort_order for case-insensitive comparison if needed */
my_strnxfrm(cs,(uchar*)to,length,(const uchar*)res->ptr(),length);
cs->cset->fill(cs, (char *)to+length,diff,fill_char);
}
......
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