818
813
Item *item=sort_field->item;
819
814
maybe_null= item->maybe_null;
821
815
switch (sort_field->result_type) {
822
816
case STRING_RESULT:
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;
818
const CHARSET_INFO * const cs=item->collation.collation;
819
char fill_char= ((cs->state & MY_CS_BINSORT) ? (char) 0 : ' ');
821
uint32_t sort_field_length;
825
/* All item->str() to use some extra byte for end null.. */
826
String tmp((char*) to,sort_field->length+4,cs);
827
String *res= item->str_result(&tmp);
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);
831
memset(to-1, 0, sort_field->length+1);
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);
835
This should only happen during extreme conditions if we run out
836
of memory or have an item marked not null when it can be null.
837
This code is here mainly to avoid a hard crash in this case.
840
memset(to, 0, sort_field->length); // Avoid crash
844
length= res->length();
845
sort_field_length= sort_field->length - sort_field->suffix_length;
846
diff=(int) (sort_field_length - length);
850
length= sort_field_length;
852
if (sort_field->suffix_length)
854
/* Store length last in result_string */
855
store_length(to + sort_field_length, length,
856
sort_field->suffix_length);
858
if (sort_field->need_strxnfrm)
860
char *from=(char*) res->ptr();
862
if ((unsigned char*) from == to)
864
set_if_smaller(length,sort_field->length);
865
memcpy(tmp_buffer,from,length);
868
tmp_length= my_strnxfrm(cs,to,sort_field->length,
869
(unsigned char*) from, length);
870
assert(tmp_length == sort_field->length);
874
my_strnxfrm(cs,(unsigned char*)to,length,(const unsigned char*)res->ptr(),length);
875
cs->cset->fill(cs, (char *)to+length,diff,fill_char);
887
881
int64_t value= item->val_int_result();
891
885
if (item->null_value)
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);
896
to[7]= (unsigned char) value;
897
to[6]= (unsigned char) (value >> 8);
898
to[5]= (unsigned char) (value >> 16);
899
to[4]= (unsigned char) (value >> 24);
900
to[3]= (unsigned char) (value >> 32);
901
to[2]= (unsigned char) (value >> 40);
902
to[1]= (unsigned char) (value >> 48);
909
903
if (item->unsigned_flag) /* Fix sign */
910
904
to[0]= (unsigned char) (value >> 56);
912
906
to[0]= (unsigned char) (value >> 56) ^ 128; /* Reverse signbit */
915
909
case DECIMAL_RESULT:
917
911
my_decimal dec_buf, *dec_val= item->val_decimal_result(&dec_buf);
1060
bool SortParam::save_index(unsigned char **sort_keys, uint32_t count, filesort_info *table_sort)
1051
bool SortParam::save_index(unsigned char **sort_keys, uint32_t count,
1052
filesort_info *table_sort)
1062
1054
uint32_t offset;
1063
1055
unsigned char *to;
1065
1057
internal::my_string_ptr_sort((unsigned char*) sort_keys, (uint32_t) count, sort_length);
1066
1058
offset= rec_length - res_length;
1068
1059
if ((ha_rows) count > max_rows)
1069
1060
count=(uint32_t) max_rows;
1071
if (!(to= table_sort->record_pointers= (unsigned char*) malloc(res_length*count)))
1061
if (!(to= table_sort->record_pointers=
1062
(unsigned char*) malloc(res_length*count)))
1074
1065
for (unsigned char **end_ptr= sort_keys+count ; sort_keys != end_ptr ; sort_keys++)
1500
1486
sortorder->result_type= sortorder->item->result_type();
1501
1487
if (sortorder->item->result_as_int64_t())
1502
1488
sortorder->result_type= INT_RESULT;
1504
1489
switch (sortorder->result_type) {
1505
1490
case STRING_RESULT:
1506
sortorder->length=sortorder->item->max_length;
1491
sortorder->length=sortorder->item->max_length;
1507
1492
set_if_smaller(sortorder->length,
1508
1493
getSession().variables.max_sort_length);
1509
if (use_strnxfrm((cs=sortorder->item->collation.collation)))
1494
if (use_strnxfrm((cs=sortorder->item->collation.collation)))
1511
1496
sortorder->length= cs->coll->strnxfrmlen(cs, sortorder->length);
1512
sortorder->need_strxnfrm= 1;
1513
*multi_byte_charset= 1;
1497
sortorder->need_strxnfrm= 1;
1498
*multi_byte_charset= 1;
1515
1500
else if (cs == &my_charset_bin)
1517
1502
/* Store length last to be able to sort blob/varbinary */
1518
1503
sortorder->suffix_length= suffix_length(sortorder->length);
1519
1504
sortorder->length+= sortorder->suffix_length;
1522
1507
case INT_RESULT:
1523
sortorder->length=8; // Size of intern int64_t
1508
sortorder->length=8; // Size of intern int64_t
1525
1510
case DECIMAL_RESULT:
1526
1511
sortorder->length=
1527
1512
my_decimal_get_binary_size(sortorder->item->max_length -