672
672
if (!my_b_inited(tempfile) &&
673
673
open_cached_file(tempfile, drizzle_tmpdir.c_str(), TEMP_PREFIX, DISK_BUFFER_SIZE,
676
678
/* check we won't have more buffpeks than we can possibly keep in memory */
677
679
if (my_b_tell(buffpek_pointers) + sizeof(buffpek) > (uint64_t)UINT_MAX)
679
684
buffpek.file_pos= my_b_tell(tempfile);
680
685
if ((ha_rows) count > param->max_rows)
681
686
count=(uint32_t) param->max_rows;
682
687
buffpek.count=(ha_rows) count;
683
688
for (end=sort_keys+count ; sort_keys != end ; sort_keys++)
684
690
if (my_b_write(tempfile, (unsigned char*) *sort_keys, (uint32_t) rec_length))
686
696
if (my_b_write(buffpek_pointers, (unsigned char*) &buffpek, sizeof(buffpek)))
692
702
} /* write_keys */
1016
1026
int merge_many_buff(SORTPARAM *param, unsigned char *sort_buffer,
1017
1027
buffpek *buffpek_inst, uint32_t *maxbuffer, internal::IO_CACHE *t_file)
1019
register uint32_t i;
1020
1029
internal::IO_CACHE t_file2,*from_file,*to_file,*temp;
1021
1030
buffpek *lastbuff;
1023
1032
if (*maxbuffer < MERGEBUFF2)
1025
1034
if (flush_io_cache(t_file) ||
1026
open_cached_file(&t_file2,drizzle_tmpdir.c_str(),TEMP_PREFIX,DISK_BUFFER_SIZE,
1035
open_cached_file(&t_file2,drizzle_tmpdir.c_str(),TEMP_PREFIX,DISK_BUFFER_SIZE, MYF(MY_WME)))
1030
1040
from_file= t_file ; to_file= &t_file2;
1031
1041
while (*maxbuffer >= MERGEBUFF2)
1043
register uint32_t i;
1033
1045
if (reinit_io_cache(from_file,internal::READ_CACHE,0L,0,0))
1035
1050
if (reinit_io_cache(to_file,internal::WRITE_CACHE,0L,0,0))
1037
1055
lastbuff=buffpek_inst;
1038
1056
for (i=0 ; i <= *maxbuffer-MERGEBUFF*3/2 ; i+=MERGEBUFF)
1040
1058
if (merge_buffers(param,from_file,to_file,sort_buffer,lastbuff++,
1041
1059
buffpek_inst+i,buffpek_inst+i+MERGEBUFF-1,0))
1044
1065
if (merge_buffers(param,from_file,to_file,sort_buffer,lastbuff++,
1045
1066
buffpek_inst+i,buffpek_inst+ *maxbuffer,0))
1047
1071
if (flush_io_cache(to_file))
1049
1076
temp=from_file; from_file=to_file; to_file=temp;
1050
1077
setup_io_cache(from_file);
1051
1078
setup_io_cache(to_file);
1052
1079
*maxbuffer= (uint32_t) (lastbuff-buffpek_inst)-1;
1055
1083
close_cached_file(to_file); // This holds old result
1056
1084
if (to_file == t_file)
1200
1229
memcpy(param->unique_buff, buffpek_inst->key, rec_length);
1201
1230
if (my_b_write(to_file, (unsigned char*) buffpek_inst->key, rec_length))
1205
1234
buffpek_inst->key+= rec_length;
1206
1235
buffpek_inst->mem_count--;
1314
1347
if (my_b_write(to_file, (unsigned char *) strpos, res_length))
1321
1355
while ((error=(int) read_to_buffer(from_file,buffpek_inst, rec_length))
1322
1356
!= -1 && error != 0);
1325
1359
lastbuff->count= min(org_max_rows-max_rows, param->max_rows);
1326
1360
lastbuff->file_pos= to_start_filepos;
1329
1363
} /* merge_buffers */