818
818
Item *item=sort_field->item;
819
819
maybe_null= item->maybe_null;
820
821
switch (sort_field->result_type) {
821
822
case STRING_RESULT:
823
const CHARSET_INFO * const cs=item->collation.collation;
824
char fill_char= ((cs->state & MY_CS_BINSORT) ? (char) 0 : ' ');
826
uint32_t sort_field_length;
824
const CHARSET_INFO * const cs=item->collation.collation;
825
char fill_char= ((cs->state & MY_CS_BINSORT) ? (char) 0 : ' ');
827
uint32_t sort_field_length;
830
/* All item->str() to use some extra byte for end null.. */
831
String tmp((char*) to,sort_field->length+4,cs);
832
String *res= item->str_result(&tmp);
836
memset(to-1, 0, sort_field->length+1);
831
/* All item->str() to use some extra byte for end null.. */
832
String tmp((char*) to,sort_field->length+4,cs);
833
String *res= item->str_result(&tmp);
837
memset(to-1, 0, sort_field->length+1);
841
This should only happen during extreme conditions if we run out
842
of memory or have an item marked not null when it can be null.
843
This code is here mainly to avoid a hard crash in this case.
846
memset(to, 0, sort_field->length); // Avoid crash
850
length= res->length();
851
sort_field_length= sort_field->length - sort_field->suffix_length;
852
diff=(int) (sort_field_length - length);
856
length= sort_field_length;
858
if (sort_field->suffix_length)
860
/* Store length last in result_string */
861
store_length(to + sort_field_length, length,
862
sort_field->suffix_length);
864
if (sort_field->need_strxnfrm)
866
char *from=(char*) res->ptr();
868
if ((unsigned char*) from == to)
870
set_if_smaller(length,sort_field->length);
871
memcpy(tmp_buffer,from,length);
874
tmp_length= my_strnxfrm(cs,to,sort_field->length,
875
(unsigned char*) from, length);
876
assert(tmp_length == sort_field->length);
840
This should only happen during extreme conditions if we run out
841
of memory or have an item marked not null when it can be null.
842
This code is here mainly to avoid a hard crash in this case.
845
memset(to, 0, sort_field->length); // Avoid crash
880
my_strnxfrm(cs,(unsigned char*)to,length,(const unsigned char*)res->ptr(),length);
881
cs->cset->fill(cs, (char *)to+length,diff,fill_char);
849
length= res->length();
850
sort_field_length= sort_field->length - sort_field->suffix_length;
851
diff=(int) (sort_field_length - length);
855
length= sort_field_length;
857
if (sort_field->suffix_length)
859
/* Store length last in result_string */
860
store_length(to + sort_field_length, length,
861
sort_field->suffix_length);
863
if (sort_field->need_strxnfrm)
865
char *from=(char*) res->ptr();
867
if ((unsigned char*) from == to)
869
set_if_smaller(length,sort_field->length);
870
memcpy(tmp_buffer,from,length);
873
tmp_length= my_strnxfrm(cs,to,sort_field->length,
874
(unsigned char*) from, length);
875
assert(tmp_length == sort_field->length);
879
my_strnxfrm(cs,(unsigned char*)to,length,(const unsigned char*)res->ptr(),length);
880
cs->cset->fill(cs, (char *)to+length,diff,fill_char);
886
887
int64_t value= item->val_int_result();
890
891
if (item->null_value)
901
to[7]= (unsigned char) value;
902
to[6]= (unsigned char) (value >> 8);
903
to[5]= (unsigned char) (value >> 16);
904
to[4]= (unsigned char) (value >> 24);
905
to[3]= (unsigned char) (value >> 32);
906
to[2]= (unsigned char) (value >> 40);
907
to[1]= (unsigned char) (value >> 48);
902
to[7]= (unsigned char) value;
903
to[6]= (unsigned char) (value >> 8);
904
to[5]= (unsigned char) (value >> 16);
905
to[4]= (unsigned char) (value >> 24);
906
to[3]= (unsigned char) (value >> 32);
907
to[2]= (unsigned char) (value >> 40);
908
to[1]= (unsigned char) (value >> 48);
908
909
if (item->unsigned_flag) /* Fix sign */
909
910
to[0]= (unsigned char) (value >> 56);
911
912
to[0]= (unsigned char) (value >> 56) ^ 128; /* Reverse signbit */
914
915
case DECIMAL_RESULT:
916
917
my_decimal dec_buf, *dec_val= item->val_decimal_result(&dec_buf);
1496
1500
sortorder->result_type= sortorder->item->result_type();
1497
1501
if (sortorder->item->result_as_int64_t())
1498
1502
sortorder->result_type= INT_RESULT;
1499
1504
switch (sortorder->result_type) {
1500
1505
case STRING_RESULT:
1501
sortorder->length=sortorder->item->max_length;
1506
sortorder->length=sortorder->item->max_length;
1502
1507
set_if_smaller(sortorder->length,
1503
1508
getSession().variables.max_sort_length);
1504
if (use_strnxfrm((cs=sortorder->item->collation.collation)))
1509
if (use_strnxfrm((cs=sortorder->item->collation.collation)))
1506
1511
sortorder->length= cs->coll->strnxfrmlen(cs, sortorder->length);
1507
sortorder->need_strxnfrm= 1;
1508
*multi_byte_charset= 1;
1512
sortorder->need_strxnfrm= 1;
1513
*multi_byte_charset= 1;
1510
1515
else if (cs == &my_charset_bin)
1512
1517
/* Store length last to be able to sort blob/varbinary */
1513
1518
sortorder->suffix_length= suffix_length(sortorder->length);
1514
1519
sortorder->length+= sortorder->suffix_length;
1517
1522
case INT_RESULT:
1518
sortorder->length=8; // Size of intern int64_t
1523
sortorder->length=8; // Size of intern int64_t
1520
1525
case DECIMAL_RESULT:
1521
1526
sortorder->length=
1522
1527
my_decimal_get_binary_size(sortorder->item->max_length -