44
46
/* Functions defined in this file */
46
static ha_rows find_all_keys(MI_SORT_PARAM *info,uint32_t keys,
50
ha_rows find_all_keys(MI_SORT_PARAM *info,uint32_t keys,
47
51
unsigned char **sort_keys,
48
52
DYNAMIC_ARRAY *buffpek,
50
54
IO_CACHE *tempfile,
51
55
IO_CACHE *tempfile_for_exceptions);
52
static int write_keys(MI_SORT_PARAM *info,unsigned char **sort_keys,
56
int write_keys(MI_SORT_PARAM *info,unsigned char **sort_keys,
53
57
uint32_t count, BUFFPEK *buffpek,IO_CACHE *tempfile);
54
static int write_key(MI_SORT_PARAM *info, unsigned char *key,
58
int write_key(MI_SORT_PARAM *info, unsigned char *key,
55
59
IO_CACHE *tempfile);
56
static int write_index(MI_SORT_PARAM *info,unsigned char * *sort_keys,
60
int write_index(MI_SORT_PARAM *info,unsigned char * *sort_keys,
58
static int merge_many_buff(MI_SORT_PARAM *info,uint32_t keys,
62
int merge_many_buff(MI_SORT_PARAM *info,uint32_t keys,
59
63
unsigned char * *sort_keys,
60
64
BUFFPEK *buffpek,size_t *maxbuffer,
62
static uint32_t read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
66
uint32_t read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
63
67
uint32_t sort_length);
64
static int merge_buffers(MI_SORT_PARAM *info,uint32_t keys,
68
int merge_buffers(MI_SORT_PARAM *info,uint32_t keys,
65
69
IO_CACHE *from_file, IO_CACHE *to_file,
66
70
unsigned char * *sort_keys, BUFFPEK *lastbuff,
67
71
BUFFPEK *Fb, BUFFPEK *Tb);
68
static int merge_index(MI_SORT_PARAM *,uint,unsigned char **,BUFFPEK *, int,
72
int merge_index(MI_SORT_PARAM *,uint,unsigned char **,BUFFPEK *, int,
71
static int write_keys_varlen(MI_SORT_PARAM *info,unsigned char **sort_keys,
72
uint32_t count, BUFFPEK *buffpek,
74
static uint32_t read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek,
75
uint32_t sort_length);
76
static int write_merge_key(MI_SORT_PARAM *info, IO_CACHE *to_file,
77
unsigned char *key, uint32_t sort_length, uint32_t count);
78
static int write_merge_key_varlen(MI_SORT_PARAM *info,
80
unsigned char* key, uint32_t sort_length,
74
int write_keys_varlen(MI_SORT_PARAM *info,unsigned char **sort_keys,
75
uint32_t count, BUFFPEK *buffpek,
77
uint32_t read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek,
78
uint32_t sort_length);
79
int write_merge_key(MI_SORT_PARAM *info, IO_CACHE *to_file,
80
unsigned char *key, uint32_t sort_length, uint32_t count);
81
int write_merge_key_varlen(MI_SORT_PARAM *info,
83
unsigned char* key, uint32_t sort_length,
83
87
my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, unsigned char *bufs);
867
* Function object to be used as the comparison function
868
* for the priority queue in the merge_buffers method.
870
class compare_functor
872
qsort2_cmp key_compare;
873
void *key_compare_arg;
875
compare_functor(qsort2_cmp in_key_compare, void *in_compare_arg)
876
: key_compare(in_key_compare), key_compare_arg(in_compare_arg) { }
877
inline bool operator()(const BUFFPEK *i, const BUFFPEK *j) const
879
int val= key_compare(key_compare_arg,
863
886
Merge buffers to one buffer
864
887
If to_file == 0 then use info->key_write
868
891
merge_buffers(MI_SORT_PARAM *info, uint32_t keys, IO_CACHE *from_file,
869
892
IO_CACHE *to_file, unsigned char **sort_keys, BUFFPEK *lastbuff,
870
893
BUFFPEK *Fb, BUFFPEK *Tb)
935
952
if (!(error=(int) info->read_to_buffer(from_file,buffpek,sort_length)))
937
unsigned char *base=buffpek->base;
938
uint32_t max_keys=buffpek->max_keys;
940
queue_remove(&queue,0);
942
/* Put room used by buffer to use in other buffer */
943
for (refpek= (BUFFPEK**) &queue_top(&queue);
944
refpek <= (BUFFPEK**) &queue_end(&queue);
948
if (buffpek->base+buffpek->max_keys*sort_length == base)
950
buffpek->max_keys+=max_keys;
953
else if (base+max_keys*sort_length == buffpek->base)
956
buffpek->max_keys+=max_keys;
960
955
break; /* One buffer have been removed */
963
958
else if (error == -1)
964
959
goto err; /* purecov: inspected */
965
queue_replaced(&queue); /* Top element has been replaced */
960
/* Top element has been replaced */
968
buffpek=(BUFFPEK*) queue_top(&queue);
965
buffpek= queue.top();
969
966
buffpek->base=(unsigned char *) sort_keys;
970
967
buffpek->max_keys=keys;