47
48
/* Functions defined in this file */
51
50
static ha_rows find_all_keys(MI_SORT_PARAM *info,uint32_t keys,
52
51
unsigned char **sort_keys,
53
52
DYNAMIC_ARRAY *buffpek,
56
IO_CACHE *tempfile_for_exceptions);
54
internal::IO_CACHE *tempfile,
55
internal::IO_CACHE *tempfile_for_exceptions);
57
56
static int write_keys(MI_SORT_PARAM *info,unsigned char **sort_keys,
58
uint32_t count, BUFFPEK *buffpek,IO_CACHE *tempfile);
57
uint32_t count, BUFFPEK *buffpek,internal::IO_CACHE *tempfile);
59
58
static int write_key(MI_SORT_PARAM *info, unsigned char *key,
59
internal::IO_CACHE *tempfile);
61
60
static int write_index(MI_SORT_PARAM *info,unsigned char * *sort_keys,
63
62
static int merge_many_buff(MI_SORT_PARAM *info,uint32_t keys,
64
63
unsigned char * *sort_keys,
65
64
BUFFPEK *buffpek,size_t *maxbuffer,
67
static uint32_t read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
65
internal::IO_CACHE *t_file);
66
static uint32_t read_to_buffer(internal::IO_CACHE *fromfile,BUFFPEK *buffpek,
68
67
uint32_t sort_length);
69
68
static int merge_buffers(MI_SORT_PARAM *info,uint32_t keys,
70
IO_CACHE *from_file, IO_CACHE *to_file,
69
internal::IO_CACHE *from_file, internal::IO_CACHE *to_file,
71
70
unsigned char * *sort_keys, BUFFPEK *lastbuff,
72
71
BUFFPEK *Fb, BUFFPEK *Tb);
73
72
static int merge_index(MI_SORT_PARAM *,uint,unsigned char **,BUFFPEK *, int,
73
internal::IO_CACHE *);
75
74
static int write_keys_varlen(MI_SORT_PARAM *info,unsigned char **sort_keys,
76
75
uint32_t count, BUFFPEK *buffpek,
78
static uint32_t read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek,
76
internal::IO_CACHE *tempfile);
77
static uint32_t read_to_buffer_varlen(internal::IO_CACHE *fromfile,BUFFPEK *buffpek,
79
78
uint32_t sort_length);
80
static int write_merge_key(MI_SORT_PARAM *info, IO_CACHE *to_file,
79
static int write_merge_key(MI_SORT_PARAM *info, internal::IO_CACHE *to_file,
81
80
unsigned char *key, uint32_t sort_length, uint32_t count);
82
81
static int write_merge_key_varlen(MI_SORT_PARAM *info,
82
internal::IO_CACHE *to_file,
84
83
unsigned char* key, uint32_t sort_length,
88
my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, unsigned char *bufs);
87
my_var_write(MI_SORT_PARAM *info, internal::IO_CACHE *to_file, unsigned char *bufs);
91
90
Creates a index of sorted keys
204
203
dynamic_element(&buffpek,0,BUFFPEK *),&maxbuffer,&tempfile))
207
if (flush_io_cache(&tempfile) ||
208
reinit_io_cache(&tempfile,READ_CACHE,0L,0,0))
206
if (internal::flush_io_cache(&tempfile) ||
207
internal::reinit_io_cache(&tempfile,internal::READ_CACHE,0L,0,0))
210
209
if (!no_messages)
211
210
printf(" - Last merge and dumping keys\n");
630
629
/* Write all keys in memory to file for later merge */
632
631
static int write_keys(MI_SORT_PARAM *info, register unsigned char **sort_keys,
633
uint32_t count, BUFFPEK *buffpek, IO_CACHE *tempfile)
632
uint32_t count, BUFFPEK *buffpek, internal::IO_CACHE *tempfile)
635
634
unsigned char **end;
636
635
uint32_t sort_length=info->key_length;
638
my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
637
internal::my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
640
639
if (!my_b_inited(tempfile) &&
641
640
open_cached_file(tempfile, P_tmpdir, "ST",
672
671
static int write_keys_varlen(MI_SORT_PARAM *info,
673
672
register unsigned char **sort_keys,
674
673
uint32_t count, BUFFPEK *buffpek,
674
internal::IO_CACHE *tempfile)
677
676
unsigned char **end;
680
my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
679
internal::my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
682
681
if (!my_b_inited(tempfile) &&
683
682
open_cached_file(tempfile, P_tmpdir, "ST",
733
732
static int merge_many_buff(MI_SORT_PARAM *info, uint32_t keys,
734
733
unsigned char **sort_keys, BUFFPEK *buffpek,
735
size_t *maxbuffer, IO_CACHE *t_file)
734
size_t *maxbuffer, internal::IO_CACHE *t_file)
738
IO_CACHE t_file2, *from_file, *to_file, *temp;
737
internal::IO_CACHE t_file2, *from_file, *to_file, *temp;
739
738
BUFFPEK *lastbuff;
741
740
if (*maxbuffer < MERGEBUFF2)
748
747
from_file= t_file ; to_file= &t_file2;
749
748
while (*maxbuffer >= MERGEBUFF2)
751
reinit_io_cache(from_file,READ_CACHE,0L,0,0);
752
reinit_io_cache(to_file,WRITE_CACHE,0L,0,0);
750
reinit_io_cache(from_file,internal::READ_CACHE,0L,0,0);
751
reinit_io_cache(to_file,internal::WRITE_CACHE,0L,0,0);
753
752
lastbuff=buffpek;
754
753
for (i=0 ; i <= *maxbuffer-MERGEBUFF*3/2 ; i+=MERGEBUFF)
892
merge_buffers(MI_SORT_PARAM *info, uint32_t keys, IO_CACHE *from_file,
893
IO_CACHE *to_file, unsigned char **sort_keys, BUFFPEK *lastbuff,
891
merge_buffers(MI_SORT_PARAM *info, uint32_t keys, internal::IO_CACHE *from_file,
892
internal::IO_CACHE *to_file, unsigned char **sort_keys, BUFFPEK *lastbuff,
894
893
BUFFPEK *Fb, BUFFPEK *Tb)
897
896
uint32_t sort_length,maxcount;
899
my_off_t to_start_filepos= 0;
898
internal::my_off_t to_start_filepos= 0;
900
899
unsigned char *strpos;
901
900
BUFFPEK *buffpek;
902
901
priority_queue<BUFFPEK *, vector<BUFFPEK *>, compare_functor >
1008
1007
merge_index(MI_SORT_PARAM *info, uint32_t keys, unsigned char **sort_keys,
1009
BUFFPEK *buffpek, int maxbuffer, IO_CACHE *tempfile)
1008
BUFFPEK *buffpek, int maxbuffer, internal::IO_CACHE *tempfile)
1011
if (merge_buffers(info,keys,tempfile,(IO_CACHE*) 0,sort_keys,buffpek,buffpek,
1010
if (merge_buffers(info,keys,tempfile,(internal::IO_CACHE*) 0,sort_keys,buffpek,buffpek,
1012
1011
buffpek+maxbuffer))