diff options
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/sql/field.cc b/sql/field.cc index eeff2ec9881..b4ba89f613c 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5881,7 +5881,8 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) memcpy(ptr,from,copy_length); if (copy_length < field_length) // Append spaces if shorter field_charset->cset->fill(field_charset,ptr+copy_length, - field_length-copy_length,' '); + field_length-copy_length, + field_charset->pad_char); if ((copy_length < length) && table->in_use->count_cuted_fields) { // Check if we loosed some info @@ -6401,6 +6402,17 @@ int Field_varstring::key_cmp(const byte *a,const byte *b) void Field_varstring::sort_string(char *to,uint length) { uint tot_length= length_bytes == 1 ? (uint) (uchar) *ptr : uint2korr(ptr); + + if (field_charset == &my_charset_bin) + { + /* Store length last in high-byte order to sort longer strings first */ + if (length_bytes == 1) + to[length-1]= tot_length; + else + mi_int2store(to+length-2, tot_length); + length-= length_bytes; + } + tot_length= my_strnxfrm(field_charset, (uchar*) to, length, (uchar*) ptr + length_bytes, @@ -7092,6 +7104,13 @@ int Field_blob::key_cmp(const byte *a,const byte *b) } +uint32 Field_blob::sort_length() const +{ + return (uint32) (current_thd->variables.max_sort_length + + (field_charset == &my_charset_bin ? 0 : packlength)); +} + + void Field_blob::sort_string(char *to,uint length) { char *blob; @@ -7101,6 +7120,31 @@ void Field_blob::sort_string(char *to,uint length) bzero(to,length); else { + if (field_charset == &my_charset_bin) + { + char *pos; + + /* + Store length of blob last in blob to shorter blobs before longer blobs + */ + length-= packlength; + pos= to+length; + + switch (packlength) { + case 1: + *pos= (char) blob_length; + break; + case 2: + mi_int2store(pos, blob_length); + break; + case 3: + mi_int3store(pos, blob_length); + break; + case 4: + mi_int4store(pos, blob_length); + break; + } + } memcpy_fixed(&blob,ptr+packlength,sizeof(char*)); blob_length=my_strnxfrm(field_charset, |