44
44
/* Functions defined in this file */
46
static ha_rows find_all_keys(MI_SORT_PARAM *info,uint keys,
46
static ha_rows find_all_keys(MI_SORT_PARAM *info,uint32_t keys,
47
47
unsigned char **sort_keys,
48
48
DYNAMIC_ARRAY *buffpek,int *maxbuffer,
49
49
IO_CACHE *tempfile,
50
50
IO_CACHE *tempfile_for_exceptions);
51
51
static int write_keys(MI_SORT_PARAM *info,unsigned char **sort_keys,
52
uint count, BUFFPEK *buffpek,IO_CACHE *tempfile);
52
uint32_t count, BUFFPEK *buffpek,IO_CACHE *tempfile);
53
53
static int write_key(MI_SORT_PARAM *info, unsigned char *key,
54
54
IO_CACHE *tempfile);
55
55
static int write_index(MI_SORT_PARAM *info,unsigned char * *sort_keys,
57
static int merge_many_buff(MI_SORT_PARAM *info,uint keys,
57
static int merge_many_buff(MI_SORT_PARAM *info,uint32_t keys,
58
58
unsigned char * *sort_keys,
59
59
BUFFPEK *buffpek,int *maxbuffer,
61
static uint read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
63
static int merge_buffers(MI_SORT_PARAM *info,uint keys,
61
static uint32_t read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
62
uint32_t sort_length);
63
static int merge_buffers(MI_SORT_PARAM *info,uint32_t keys,
64
64
IO_CACHE *from_file, IO_CACHE *to_file,
65
65
unsigned char * *sort_keys, BUFFPEK *lastbuff,
66
66
BUFFPEK *Fb, BUFFPEK *Tb);
70
70
static int write_keys_varlen(MI_SORT_PARAM *info,unsigned char **sort_keys,
71
uint count, BUFFPEK *buffpek,
71
uint32_t count, BUFFPEK *buffpek,
72
72
IO_CACHE *tempfile);
73
static uint read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek,
73
static uint32_t read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek,
74
uint32_t sort_length);
75
75
static int write_merge_key(MI_SORT_PARAM *info, IO_CACHE *to_file,
76
unsigned char *key, uint sort_length, uint count);
76
unsigned char *key, uint32_t sort_length, uint32_t count);
77
77
static int write_merge_key_varlen(MI_SORT_PARAM *info,
79
unsigned char* key, uint sort_length,
79
unsigned char* key, uint32_t sort_length,
82
82
my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, unsigned char *bufs);
99
99
uint32_t sortbuff_size)
101
101
int error,maxbuffer,skr;
102
uint memavl,old_memavl,keys,sort_length;
102
uint32_t memavl,old_memavl,keys,sort_length;
103
103
DYNAMIC_ARRAY buffpek;
105
105
unsigned char **sort_keys;
213
213
if (my_b_inited(&tempfile_for_exceptions))
215
215
MI_INFO *idx=info->sort_info->info;
216
uint keyno=info->key;
217
uint key_length, ref_length=idx->s->rec_reflength;
216
uint32_t keyno=info->key;
217
uint32_t key_length, ref_length=idx->s->rec_reflength;
219
219
if (!no_messages)
220
220
printf(" - Adding exceptions\n"); /* purecov: tested */
248
248
/* Search after all keys and place them in a temp. file */
250
static ha_rows find_all_keys(MI_SORT_PARAM *info, uint keys,
250
static ha_rows find_all_keys(MI_SORT_PARAM *info, uint32_t keys,
251
251
unsigned char **sort_keys, DYNAMIC_ARRAY *buffpek,
252
252
int *maxbuffer, IO_CACHE *tempfile,
253
253
IO_CACHE *tempfile_for_exceptions)
259
259
sort_keys[0]=(unsigned char*) (sort_keys+keys);
302
302
MI_SORT_PARAM *sort_param= (MI_SORT_PARAM*) arg;
304
uint memavl,old_memavl,keys,sort_length;
304
uint32_t memavl,old_memavl,keys,sort_length;
305
uint32_t idx, maxbuffer;
306
306
unsigned char **sort_keys=0;
472
472
uint32_t length= 0, keys;
473
473
ulong *rec_per_key_part= param->rec_per_key_part;
474
474
int got_error=sort_info->got_error;
476
476
MI_INFO *info=sort_info->info;
477
477
MYISAM_SHARE *share=info->s;
478
478
MI_SORT_PARAM *sinfo;
621
621
/* Write all keys in memory to file for later merge */
623
623
static int write_keys(MI_SORT_PARAM *info, register unsigned char **sort_keys,
624
uint count, BUFFPEK *buffpek, IO_CACHE *tempfile)
624
uint32_t count, BUFFPEK *buffpek, IO_CACHE *tempfile)
626
626
unsigned char **end;
627
uint sort_length=info->key_length;
627
uint32_t sort_length=info->key_length;
629
629
my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
663
663
static int write_keys_varlen(MI_SORT_PARAM *info,
664
664
register unsigned char **sort_keys,
665
uint count, BUFFPEK *buffpek,
665
uint32_t count, BUFFPEK *buffpek,
666
666
IO_CACHE *tempfile)
668
668
unsigned char **end;
689
689
static int write_key(MI_SORT_PARAM *info, unsigned char *key,
690
690
IO_CACHE *tempfile)
692
uint key_length=info->real_key_length;
692
uint32_t key_length=info->real_key_length;
694
694
if (!my_b_inited(tempfile) &&
695
695
open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST",
706
706
/* Write index */
708
708
static int write_index(MI_SORT_PARAM *info, register unsigned char **sort_keys,
709
register uint32_t count)
711
711
my_qsort2((unsigned char*) sort_keys,(size_t) count,sizeof(unsigned char*),
712
712
(qsort2_cmp) info->key_cmp,info);
722
722
/* Merge buffers to make < MERGEBUFF2 buffers */
724
static int merge_many_buff(MI_SORT_PARAM *info, uint keys,
724
static int merge_many_buff(MI_SORT_PARAM *info, uint32_t keys,
725
725
unsigned char **sort_keys, BUFFPEK *buffpek,
726
726
int *maxbuffer, IO_CACHE *t_file)
781
static uint read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
781
static uint32_t read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
782
uint32_t sort_length)
784
register uint32_t count;
787
787
if ((count=(uint) cmin((ha_rows) buffpek->max_keys,buffpek->count)))
797
797
return (count*sort_length);
798
798
} /* read_to_buffer */
800
static uint read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek,
800
static uint32_t read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek,
801
uint32_t sort_length)
803
register uint32_t count;
804
804
uint16_t length_of_key = 0;
806
806
unsigned char *buffp;
808
808
if ((count=(uint) cmin((ha_rows) buffpek->max_keys,buffpek->count)))
832
832
static int write_merge_key_varlen(MI_SORT_PARAM *info,
833
833
IO_CACHE *to_file, unsigned char* key,
834
uint sort_length, uint count)
834
uint32_t sort_length, uint32_t count)
837
837
unsigned char *bufs = key;
839
839
for (idx=1;idx<=count;idx++)
850
850
static int write_merge_key(MI_SORT_PARAM *info __attribute__((unused)),
851
851
IO_CACHE *to_file, unsigned char *key,
852
uint sort_length, uint count)
852
uint32_t sort_length, uint32_t count)
854
854
return my_b_write(to_file, key, (size_t) sort_length*count);
863
merge_buffers(MI_SORT_PARAM *info, uint keys, IO_CACHE *from_file,
863
merge_buffers(MI_SORT_PARAM *info, uint32_t keys, IO_CACHE *from_file,
864
864
IO_CACHE *to_file, unsigned char **sort_keys, BUFFPEK *lastbuff,
865
865
BUFFPEK *Fb, BUFFPEK *Tb)
868
uint sort_length,maxcount;
868
uint32_t sort_length,maxcount;
870
870
my_off_t to_start_filepos= 0;
871
871
unsigned char *strpos;
928
928
if (!(error=(int) info->read_to_buffer(from_file,buffpek,sort_length)))
930
930
unsigned char *base=buffpek->base;
931
uint max_keys=buffpek->max_keys;
931
uint32_t max_keys=buffpek->max_keys;
933
933
queue_remove(&queue,0);
1001
1001
/* Do a merge to output-file (save only positions) */
1004
merge_index(MI_SORT_PARAM *info, uint keys, unsigned char **sort_keys,
1004
merge_index(MI_SORT_PARAM *info, uint32_t keys, unsigned char **sort_keys,
1005
1005
BUFFPEK *buffpek, int maxbuffer, IO_CACHE *tempfile)
1007
1007
if (merge_buffers(info,keys,tempfile,(IO_CACHE*) 0,sort_keys,buffpek,buffpek,