24
24
#include <drizzled/server_includes.h>
26
#include <drizzled/drizzled_error_messages.h>
28
/// How to write record_ref.
29
#define WRITE_REF(file,from) \
30
if (my_b_write((file),(uchar*) (from),param->ref_length)) \
33
/* functions defined in this file */
35
static char **make_char_array(char **old_pos, register uint fields,
36
uint length, myf my_flag);
37
static uchar *read_buffpek_from_file(IO_CACHE *buffer_file, uint count,
25
#include <drizzled/sql_sort.h>
26
#include <drizzled/error.h>
27
#include <drizzled/probes.h>
28
#include <drizzled/session.h>
29
#include <drizzled/table.h>
30
#include <drizzled/table_list.h>
32
/* functions defined in this file */
34
static char **make_char_array(char **old_pos, register uint32_t fields,
36
static unsigned char *read_buffpek_from_file(IO_CACHE *buffer_file, uint32_t count,
39
38
static ha_rows find_all_keys(SORTPARAM *param,SQL_SELECT *select,
40
uchar * *sort_keys, IO_CACHE *buffer_file,
39
unsigned char * *sort_keys, IO_CACHE *buffer_file,
41
40
IO_CACHE *tempfile,IO_CACHE *indexfile);
42
static int write_keys(SORTPARAM *param,uchar * *sort_keys,
43
uint count, IO_CACHE *buffer_file, IO_CACHE *tempfile);
44
static void make_sortkey(SORTPARAM *param,uchar *to, uchar *ref_pos);
41
static int write_keys(SORTPARAM *param,unsigned char * *sort_keys,
42
uint32_t count, IO_CACHE *buffer_file, IO_CACHE *tempfile);
43
static void make_sortkey(SORTPARAM *param,unsigned char *to, unsigned char *ref_pos);
45
44
static void register_used_fields(SORTPARAM *param);
46
static int merge_index(SORTPARAM *param,uchar *sort_buffer,
45
static int merge_index(SORTPARAM *param,unsigned char *sort_buffer,
48
uint maxbuffer,IO_CACHE *tempfile,
47
uint32_t maxbuffer,IO_CACHE *tempfile,
49
48
IO_CACHE *outfile);
50
static bool save_index(SORTPARAM *param,uchar **sort_keys, uint count,
51
FILESORT_INFO *table_sort);
52
static uint suffix_length(uint32_t string_length);
53
static uint sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
49
static bool save_index(SORTPARAM *param,unsigned char **sort_keys, uint32_t count,
50
filesort_info_st *table_sort);
51
static uint32_t suffix_length(uint32_t string_length);
52
static uint32_t sortlength(Session *session, SORT_FIELD *sortorder, uint32_t s_length,
54
53
bool *multi_byte_charset);
55
static SORT_ADDON_FIELD *get_addon_fields(THD *thd, Field **ptabfield,
56
uint sortlength, uint *plength);
54
static SORT_ADDON_FIELD *get_addon_fields(Session *session, Field **ptabfield,
55
uint32_t sortlength, uint32_t *plength);
57
56
static void unpack_addon_fields(struct st_sort_addon_field *addon_field,
61
60
Creates a set of pointers that can be used to read the rows
68
67
The result set is stored in table->io_cache or
69
68
table->record_pointers.
71
@param thd Current thread
70
@param session Current thread
72
71
@param table Table to sort
73
72
@param sortorder How to sort the table
74
73
@param s_length Number of elements in sortorder
75
74
@param select condition to apply to the rows
76
75
@param max_rows Return only this many rows
77
76
@param sort_positions Set to 1 if we want to force sorting by position
78
(Needed by UPDATE/INSERT or ALTER TABLE)
77
(Needed by UPDATE/INSERT or ALTER Table)
79
78
@param examined_rows Store number of examined rows here
92
91
examined_rows will be set to number of examined rows
95
ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
94
ha_rows filesort(Session *session, Table *table, SORT_FIELD *sortorder, uint32_t s_length,
96
95
SQL_SELECT *select, ha_rows max_rows,
97
96
bool sort_positions, ha_rows *examined_rows)
100
99
uint32_t memavl, min_sort_memory;
102
101
BUFFPEK *buffpek;
103
102
ha_rows records= HA_POS_ERROR;
104
uchar **sort_keys= 0;
105
IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile;
103
unsigned char **sort_keys= 0;
104
IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile;
107
106
bool multi_byte_charset;
109
FILESORT_INFO table_sort;
110
TABLE_LIST *tab= table->pos_in_table_list;
108
filesort_info_st table_sort;
109
TableList *tab= table->pos_in_table_list;
111
110
Item_subselect *subselect= tab ? tab->containing_subselect() : 0;
113
112
DRIZZLE_FILESORT_START();
116
115
Release InnoDB's adaptive hash index latch (if holding) before
119
ha_release_temporary_latches(thd);
118
ha_release_temporary_latches(session);
122
Don't use table->sort in filesort as it is also used by
123
QUICK_INDEX_MERGE_SELECT. Work with a copy and put it back at the end
121
Don't use table->sort in filesort as it is also used by
122
QUICK_INDEX_MERGE_SELECT. Work with a copy and put it back at the end
124
123
when index_merge select has finished with it.
126
memcpy(&table_sort, &table->sort, sizeof(FILESORT_INFO));
125
memcpy(&table_sort, &table->sort, sizeof(filesort_info_st));
127
126
table->sort.io_cache= NULL;
129
128
outfile= table_sort.io_cache;
130
129
my_b_clear(&tempfile);
131
130
my_b_clear(&buffpek_pointers);
134
133
memset(¶m, 0, sizeof(param));
135
param.sort_length= sortlength(thd, sortorder, s_length, &multi_byte_charset);
134
param.sort_length= sortlength(session, sortorder, s_length, &multi_byte_charset);
136
135
param.ref_length= table->file->ref_length;
137
136
param.addon_field= 0;
138
137
param.addon_length= 0;
139
138
if (!(table->file->ha_table_flags() & HA_FAST_KEY_READ) && !sort_positions)
142
Get the descriptors of all fields whose values are appended
141
Get the descriptors of all fields whose values are appended
143
142
to sorted fields and get its total length in param.spack_length.
145
param.addon_field= get_addon_fields(thd, table->field,
144
param.addon_field= get_addon_fields(session, table->field,
146
145
param.sort_length,
147
146
¶m.addon_length);
201
199
if (multi_byte_charset &&
202
!(param.tmp_buffer= (char*) my_malloc(param.sort_length,MYF(MY_WME))))
200
!(param.tmp_buffer= (char*) malloc(param.sort_length)))
205
memavl= thd->variables.sortbuff_size;
206
min_sort_memory= max((uint)MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
203
memavl= session->variables.sortbuff_size;
204
min_sort_memory= cmax((uint32_t)MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
207
205
while (memavl >= min_sort_memory)
209
207
uint32_t old_memavl;
210
208
uint32_t keys= memavl/(param.rec_length+sizeof(char*));
211
param.keys=(uint) min(records+1, keys);
209
param.keys=(uint32_t) cmin(records+1, keys);
212
210
if ((table_sort.sort_keys=
213
(uchar **) make_char_array((char **) table_sort.sort_keys,
214
param.keys, param.rec_length, MYF(0))))
211
(unsigned char **) make_char_array((char **) table_sort.sort_keys,
212
param.keys, param.rec_length)))
216
214
old_memavl=memavl;
217
215
if ((memavl=memavl/4*3) < min_sort_memory && old_memavl > min_sort_memory)
234
232
&tempfile, selected_records_file)) ==
237
maxbuffer= (uint) (my_b_tell(&buffpek_pointers)/sizeof(*buffpek));
235
maxbuffer= (uint32_t) (my_b_tell(&buffpek_pointers)/sizeof(*buffpek));
239
237
if (maxbuffer == 0) // The whole set is in memory
241
if (save_index(¶m,sort_keys,(uint) records, &table_sort))
239
if (save_index(¶m,sort_keys,(uint32_t) records, &table_sort))
246
244
if (table_sort.buffpek && table_sort.buffpek_len < maxbuffer)
248
x_free(table_sort.buffpek);
246
if (table_sort.buffpek)
247
free(table_sort.buffpek);
249
248
table_sort.buffpek= 0;
251
250
if (!(table_sort.buffpek=
252
(uchar *) read_buffpek_from_file(&buffpek_pointers, maxbuffer,
251
(unsigned char *) read_buffpek_from_file(&buffpek_pointers, maxbuffer,
253
252
table_sort.buffpek)))
255
254
buffpek= (BUFFPEK *) table_sort.buffpek;
270
269
param.keys=((param.keys*(param.rec_length+sizeof(char*))) /
271
270
param.rec_length-1);
272
271
maxbuffer--; // Offset from 0
273
if (merge_many_buff(¶m,(uchar*) sort_keys,buffpek,&maxbuffer,
272
if (merge_many_buff(¶m,(unsigned char*) sort_keys,buffpek,&maxbuffer,
276
275
if (flush_io_cache(&tempfile) ||
277
276
reinit_io_cache(&tempfile,READ_CACHE,0L,0,0))
279
if (merge_index(¶m,(uchar*) sort_keys,buffpek,maxbuffer,&tempfile,
278
if (merge_index(¶m,(unsigned char*) sort_keys,buffpek,maxbuffer,&tempfile,
313
315
my_message(ER_FILSORT_ABORT, ER(ER_FILSORT_ABORT),
314
316
MYF(ME_ERROR+ME_WAITTANG));
316
statistic_add(thd->status_var.filesort_rows,
318
statistic_add(session->status_var.filesort_rows,
317
319
(uint32_t) records, &LOCK_status);
318
320
*examined_rows= param.examined_rows;
319
memcpy(&table->sort, &table_sort, sizeof(FILESORT_INFO));
321
memcpy(&table->sort, &table_sort, sizeof(filesort_info_st));
320
322
DRIZZLE_FILESORT_END();
321
323
return(error ? HA_POS_ERROR : records);
325
void filesort_free_buffers(TABLE *table, bool full)
327
void filesort_free_buffers(Table *table, bool full)
327
329
if (table->sort.record_pointers)
329
my_free((uchar*) table->sort.record_pointers,MYF(0));
331
free((unsigned char*) table->sort.record_pointers);
330
332
table->sort.record_pointers=0;
334
336
if (table->sort.sort_keys )
336
x_free((uchar*) table->sort.sort_keys);
338
if ((unsigned char*) table->sort.sort_keys)
339
free((unsigned char*) table->sort.sort_keys);
337
340
table->sort.sort_keys= 0;
339
342
if (table->sort.buffpek)
341
x_free((uchar*) table->sort.buffpek);
344
if ((unsigned char*) table->sort.buffpek)
345
free((unsigned char*) table->sort.buffpek);
342
346
table->sort.buffpek= 0;
343
347
table->sort.buffpek_len= 0;
346
350
if (table->sort.addon_buf)
348
my_free((char *) table->sort.addon_buf, MYF(0));
349
my_free((char *) table->sort.addon_field, MYF(MY_ALLOW_ZERO_PTR));
352
free((char *) table->sort.addon_buf);
353
free((char *) table->sort.addon_field);
350
354
table->sort.addon_buf=0;
351
355
table->sort.addon_field=0;
375
378
/** Read 'count' number of buffer pointers into memory. */
377
static uchar *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count,
380
static unsigned char *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint32_t count,
380
383
uint32_t length= sizeof(BUFFPEK)*count;
384
unsigned char *tmp= buf;
382
385
if (count > UINT_MAX/sizeof(BUFFPEK))
383
386
return 0; /* sizeof(BUFFPEK)*count will overflow */
385
tmp= (uchar *)my_malloc(length, MYF(MY_WME));
388
tmp= (unsigned char *)malloc(length);
388
391
if (reinit_io_cache(buffpek_pointers,READ_CACHE,0L,0,0) ||
389
my_b_read(buffpek_pointers, (uchar*) tmp, length))
392
my_b_read(buffpek_pointers, (unsigned char*) tmp, length))
391
my_free((char*) tmp, MYF(0));
436
439
static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
440
unsigned char **sort_keys,
438
441
IO_CACHE *buffpek_pointers,
439
442
IO_CACHE *tempfile, IO_CACHE *indexfile)
441
444
int error,flag,quick_select;
442
uint idx,indexpos,ref_length;
443
uchar *ref_pos,*next_pos,ref_buff[MAX_REFLENGTH];
445
uint32_t idx,indexpos,ref_length;
446
unsigned char *ref_pos,*next_pos,ref_buff[MAX_REFLENGTH];
446
THD *thd= current_thd;
447
volatile THD::killed_state *killed= &thd->killed;
449
Session *session= current_session;
450
volatile Session::killed_state *killed= &session->killed;
449
452
MY_BITMAP *save_read_set, *save_write_set;
617
write_keys(SORTPARAM *param, register uchar **sort_keys, uint count,
623
write_keys(SORTPARAM *param, register unsigned char **sort_keys, uint32_t count,
618
624
IO_CACHE *buffpek_pointers, IO_CACHE *tempfile)
620
626
size_t sort_length, rec_length;
624
630
sort_length= param->sort_length;
625
631
rec_length= param->rec_length;
626
my_string_ptr_sort((uchar*) sort_keys, (uint) count, sort_length);
632
my_string_ptr_sort((unsigned char*) sort_keys, (uint32_t) count, sort_length);
627
633
if (!my_b_inited(tempfile) &&
628
open_cached_file(tempfile, mysql_tmpdir, TEMP_PREFIX, DISK_BUFFER_SIZE,
634
open_cached_file(tempfile, drizzle_tmpdir, TEMP_PREFIX, DISK_BUFFER_SIZE,
630
636
goto err; /* purecov: inspected */
631
637
/* check we won't have more buffpeks than we can possibly keep in memory */
634
640
buffpek.file_pos= my_b_tell(tempfile);
635
641
if ((ha_rows) count > param->max_rows)
636
count=(uint) param->max_rows; /* purecov: inspected */
642
count=(uint32_t) param->max_rows; /* purecov: inspected */
637
643
buffpek.count=(ha_rows) count;
638
644
for (end=sort_keys+count ; sort_keys != end ; sort_keys++)
639
if (my_b_write(tempfile, (uchar*) *sort_keys, (uint) rec_length))
645
if (my_b_write(tempfile, (unsigned char*) *sort_keys, (uint32_t) rec_length))
641
if (my_b_write(buffpek_pointers, (uchar*) &buffpek, sizeof(buffpek)))
647
if (my_b_write(buffpek_pointers, (unsigned char*) &buffpek, sizeof(buffpek)))
754
760
if (sort_field->need_strxnfrm)
756
762
char *from=(char*) res->ptr();
758
if ((uchar*) from == to)
764
if ((unsigned char*) from == to)
760
766
set_if_smaller(length,sort_field->length);
761
767
memcpy(param->tmp_buffer,from,length);
762
768
from=param->tmp_buffer;
764
770
tmp_length= my_strnxfrm(cs,to,sort_field->length,
765
(uchar*) from, length);
771
(unsigned char*) from, length);
766
772
assert(tmp_length == sort_field->length);
770
my_strnxfrm(cs,(uchar*)to,length,(const uchar*)res->ptr(),length);
776
my_strnxfrm(cs,(unsigned char*)to,length,(const unsigned char*)res->ptr(),length);
771
777
cs->cset->fill(cs, (char *)to+length,diff,fill_char);
792
#if SIZEOF_LONG_LONG > 4
793
to[7]= (uchar) value;
794
to[6]= (uchar) (value >> 8);
795
to[5]= (uchar) (value >> 16);
796
to[4]= (uchar) (value >> 24);
797
to[3]= (uchar) (value >> 32);
798
to[2]= (uchar) (value >> 40);
799
to[1]= (uchar) (value >> 48);
800
if (item->unsigned_flag) /* Fix sign */
801
to[0]= (uchar) (value >> 56);
803
to[0]= (uchar) (value >> 56) ^ 128; /* Reverse signbit */
805
to[3]= (uchar) value;
806
to[2]= (uchar) (value >> 8);
807
to[1]= (uchar) (value >> 16);
808
if (item->unsigned_flag) /* Fix sign */
809
to[0]= (uchar) (value >> 24);
811
to[0]= (uchar) (value >> 24) ^ 128; /* Reverse signbit */
798
to[7]= (unsigned char) value;
799
to[6]= (unsigned char) (value >> 8);
800
to[5]= (unsigned char) (value >> 16);
801
to[4]= (unsigned char) (value >> 24);
802
to[3]= (unsigned char) (value >> 32);
803
to[2]= (unsigned char) (value >> 40);
804
to[1]= (unsigned char) (value >> 48);
805
if (item->unsigned_flag) /* Fix sign */
806
to[0]= (unsigned char) (value >> 56);
808
to[0]= (unsigned char) (value >> 56) ^ 128; /* Reverse signbit */
815
811
case DECIMAL_RESULT:
959
static bool save_index(SORTPARAM *param, uchar **sort_keys, uint count,
960
FILESORT_INFO *table_sort)
955
static bool save_index(SORTPARAM *param, unsigned char **sort_keys, uint32_t count,
956
filesort_info_st *table_sort)
962
uint offset,res_length;
958
uint32_t offset,res_length;
965
my_string_ptr_sort((uchar*) sort_keys, (uint) count, param->sort_length);
961
my_string_ptr_sort((unsigned char*) sort_keys, (uint32_t) count, param->sort_length);
966
962
res_length= param->res_length;
967
963
offset= param->rec_length-res_length;
968
964
if ((ha_rows) count > param->max_rows)
969
count=(uint) param->max_rows;
970
if (!(to= table_sort->record_pointers=
971
(uchar*) my_malloc(res_length*count, MYF(MY_WME))))
965
count=(uint32_t) param->max_rows;
966
if (!(to= table_sort->record_pointers=
967
(unsigned char*) malloc(res_length*count)))
972
968
return(1); /* purecov: inspected */
973
for (uchar **end= sort_keys+count ; sort_keys != end ; sort_keys++)
969
for (unsigned char **end= sort_keys+count ; sort_keys != end ; sort_keys++)
975
971
memcpy(to, *sort_keys+offset, res_length);
982
978
/** Merge buffers to make < MERGEBUFF2 buffers. */
984
int merge_many_buff(SORTPARAM *param, uchar *sort_buffer,
985
BUFFPEK *buffpek, uint *maxbuffer, IO_CACHE *t_file)
980
int merge_many_buff(SORTPARAM *param, unsigned char *sort_buffer,
981
BUFFPEK *buffpek, uint32_t *maxbuffer, IO_CACHE *t_file)
988
984
IO_CACHE t_file2,*from_file,*to_file,*temp;
989
985
BUFFPEK *lastbuff;
991
987
if (*maxbuffer < MERGEBUFF2)
992
988
return(0); /* purecov: inspected */
993
989
if (flush_io_cache(t_file) ||
994
open_cached_file(&t_file2,mysql_tmpdir,TEMP_PREFIX,DISK_BUFFER_SIZE,
990
open_cached_file(&t_file2,drizzle_tmpdir,TEMP_PREFIX,DISK_BUFFER_SIZE,
996
992
return(1); /* purecov: inspected */
1035
1031
Read data to buffer.
1038
(uint)-1 if something goes wrong
1034
(uint32_t)-1 if something goes wrong
1041
uint read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
1037
uint32_t read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
1038
uint32_t rec_length)
1044
register uint count;
1040
register uint32_t count;
1047
if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
1043
if ((count=(uint32_t) cmin((ha_rows) buffpek->max_keys,buffpek->count)))
1049
if (pread(fromfile->file,(uchar*) buffpek->base, (length= rec_length*count),buffpek->file_pos) == 0)
1050
return((uint) -1); /* purecov: inspected */
1045
if (pread(fromfile->file,(unsigned char*) buffpek->base, (length= rec_length*count),buffpek->file_pos) == 0)
1046
return((uint32_t) -1); /* purecov: inspected */
1051
1047
buffpek->key=buffpek->base;
1052
1048
buffpek->file_pos+= length; /* New filepos */
1053
1049
buffpek->count-= count;
1068
1064
@param[in] key_length key length
1071
void reuse_freed_buff(QUEUE *queue, BUFFPEK *reuse, uint key_length)
1067
void reuse_freed_buff(QUEUE *queue, BUFFPEK *reuse, uint32_t key_length)
1073
uchar *reuse_end= reuse->base + reuse->max_keys * key_length;
1074
for (uint i= 0; i < queue->elements; ++i)
1069
unsigned char *reuse_end= reuse->base + reuse->max_keys * key_length;
1070
for (uint32_t i= 0; i < queue->elements; ++i)
1076
1072
BUFFPEK *bp= (BUFFPEK *) queue_element(queue, i);
1077
1073
if (bp->base + bp->max_keys * key_length == reuse->base)
1111
1107
int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
1112
IO_CACHE *to_file, uchar *sort_buffer,
1108
IO_CACHE *to_file, unsigned char *sort_buffer,
1113
1109
BUFFPEK *lastbuff, BUFFPEK *Fb, BUFFPEK *Tb,
1117
uint rec_length,res_length,offset;
1113
uint32_t rec_length,res_length,offset;
1118
1114
size_t sort_length;
1119
1115
uint32_t maxcount;
1120
1116
ha_rows max_rows,org_max_rows;
1121
1117
my_off_t to_start_filepos;
1118
unsigned char *strpos;
1123
1119
BUFFPEK *buffpek;
1125
1121
qsort2_cmp cmp;
1126
1122
void *first_cmp_arg;
1127
volatile THD::killed_state *killed= ¤t_thd->killed;
1128
THD::killed_state not_killable;
1123
volatile Session::killed_state *killed= ¤t_session->killed;
1124
Session::killed_state not_killable;
1130
status_var_increment(current_thd->status_var.filesort_merge_passes);
1126
status_var_increment(current_session->status_var.filesort_merge_passes);
1131
1127
if (param->not_killable)
1133
1129
killed= ¬_killable;
1134
not_killable= THD::NOT_KILLED;
1130
not_killable= Session::NOT_KILLED;
1157
1153
cmp= get_ptr_compare(sort_length);
1158
1154
first_cmp_arg= (void*) &sort_length;
1160
if (init_queue(&queue, (uint) (Tb-Fb)+1, offsetof(BUFFPEK,key), 0,
1156
if (init_queue(&queue, (uint32_t) (Tb-Fb)+1, offsetof(BUFFPEK,key), 0,
1161
1157
(queue_compare) cmp, first_cmp_arg))
1162
1158
return(1); /* purecov: inspected */
1163
1159
for (buffpek= Fb ; buffpek <= Tb ; buffpek++)
1165
1161
buffpek->base= strpos;
1166
1162
buffpek->max_keys= maxcount;
1167
strpos+= (uint) (error= (int) read_to_buffer(from_file, buffpek,
1163
strpos+= (uint32_t) (error= (int) read_to_buffer(from_file, buffpek,
1169
1165
if (error == -1)
1170
1166
goto err; /* purecov: inspected */
1171
1167
buffpek->max_keys= buffpek->mem_count; // If less data in buffers than expected
1172
queue_insert(&queue, (uchar*) buffpek);
1168
queue_insert(&queue, (unsigned char*) buffpek);
1175
1171
if (param->unique_buff)
1178
1174
Called by Unique::get()
1179
1175
Copy the first argument to param->unique_buff for unique removal.
1180
1176
Store it also in 'to_file'.
1212
1208
if (cmp) // Remove duplicates
1214
1210
if (!(*cmp)(first_cmp_arg, &(param->unique_buff),
1215
(uchar**) &buffpek->key))
1211
(unsigned char**) &buffpek->key))
1216
1212
goto skip_duplicate;
1217
1213
memcpy(param->unique_buff, buffpek->key, rec_length);
1221
if (my_b_write(to_file,(uchar*) buffpek->key, rec_length))
1217
if (my_b_write(to_file,(unsigned char*) buffpek->key, rec_length))
1223
1219
error=1; goto err; /* purecov: inspected */
1228
if (my_b_write(to_file, (uchar*) buffpek->key+offset, res_length))
1224
if (my_b_write(to_file, (unsigned char*) buffpek->key+offset, res_length))
1230
1226
error=1; goto err; /* purecov: inspected */
1275
1271
if ((ha_rows) buffpek->mem_count > max_rows)
1276
1272
{ /* Don't write too many records */
1277
buffpek->mem_count= (uint) max_rows;
1273
buffpek->mem_count= (uint32_t) max_rows;
1278
1274
buffpek->count= 0; /* Don't read more */
1280
1276
max_rows-= buffpek->mem_count;
1283
if (my_b_write(to_file,(uchar*) buffpek->key,
1279
if (my_b_write(to_file,(unsigned char*) buffpek->key,
1284
1280
(rec_length*buffpek->mem_count)))
1286
1282
error= 1; goto err; /* purecov: inspected */
1316
1312
/* Do a merge to output-file (save only positions) */
1318
static int merge_index(SORTPARAM *param, uchar *sort_buffer,
1319
BUFFPEK *buffpek, uint maxbuffer,
1314
static int merge_index(SORTPARAM *param, unsigned char *sort_buffer,
1315
BUFFPEK *buffpek, uint32_t maxbuffer,
1320
1316
IO_CACHE *tempfile, IO_CACHE *outfile)
1322
1318
if (merge_buffers(param,tempfile,outfile,sort_buffer,buffpek,buffpek,
1446
1438
The function first finds out what fields are used in the result set.
1447
1439
Then it calculates the length of the buffer to store the values of
1448
these fields together with the value of sort values.
1440
these fields together with the value of sort values.
1449
1441
If the calculated length is not greater than max_length_for_sort_data
1450
1442
the function allocates memory for an array of descriptors containing
1451
1443
layouts for the values of the non-sorted fields in the buffer and
1454
@param thd Current thread
1446
@param session Current thread
1455
1447
@param ptabfield Array of references to the table fields
1456
1448
@param sortlength Total length of sorted fields
1457
1449
@param[out] plength Total length of appended fields
1605
1597
if (tmp[0] & 128) /* Negative */
1606
1598
{ /* make complement */
1608
1600
for (i=0 ; i < sizeof(nr); i++)
1609
tmp[i]=tmp[i] ^ (uchar) 255;
1601
tmp[i]=tmp[i] ^ (unsigned char) 255;
1612
1604
{ /* Set high and move exponent one up */
1613
ushort exp_part=(((ushort) tmp[0] << 8) | (ushort) tmp[1] |
1615
exp_part+= (ushort) 1 << (16-1-DBL_EXP_DIG);
1616
tmp[0]= (uchar) (exp_part >> 8);
1617
tmp[1]= (uchar) exp_part;
1605
uint16_t exp_part=(((uint16_t) tmp[0] << 8) | (uint16_t) tmp[1] |
1607
exp_part+= (uint16_t) 1 << (16-1-DBL_EXP_DIG);
1608
tmp[0]= (unsigned char) (exp_part >> 8);
1609
tmp[1]= (unsigned char) exp_part;