~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/myisam/sort.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
                              unsigned char **sort_keys,
52
52
                              DYNAMIC_ARRAY *buffpek,
53
53
                              size_t *maxbuffer,
54
 
                              internal::IO_CACHE *tempfile,
55
 
                              internal::IO_CACHE *tempfile_for_exceptions);
 
54
                              internal::io_cache_st *tempfile,
 
55
                              internal::io_cache_st *tempfile_for_exceptions);
56
56
static int  write_keys(MI_SORT_PARAM *info,unsigned char **sort_keys,
57
 
                             uint32_t count, BUFFPEK *buffpek,internal::IO_CACHE *tempfile);
 
57
                             uint32_t count, BUFFPEK *buffpek,internal::io_cache_st *tempfile);
58
58
static int  write_key(MI_SORT_PARAM *info, unsigned char *key,
59
 
                            internal::IO_CACHE *tempfile);
 
59
                            internal::io_cache_st *tempfile);
60
60
static int  write_index(MI_SORT_PARAM *info,unsigned char * *sort_keys,
61
61
                              uint32_t count);
62
62
static int  merge_many_buff(MI_SORT_PARAM *info,uint32_t keys,
63
63
                            unsigned char * *sort_keys,
64
64
                            BUFFPEK *buffpek,size_t *maxbuffer,
65
 
                            internal::IO_CACHE *t_file);
66
 
static uint32_t  read_to_buffer(internal::IO_CACHE *fromfile,BUFFPEK *buffpek,
 
65
                            internal::io_cache_st *t_file);
 
66
static uint32_t  read_to_buffer(internal::io_cache_st *fromfile,BUFFPEK *buffpek,
67
67
                                  uint32_t sort_length);
68
68
static int  merge_buffers(MI_SORT_PARAM *info,uint32_t keys,
69
 
                                internal::IO_CACHE *from_file, internal::IO_CACHE *to_file,
 
69
                                internal::io_cache_st *from_file, internal::io_cache_st *to_file,
70
70
                                unsigned char * *sort_keys, BUFFPEK *lastbuff,
71
71
                                BUFFPEK *Fb, BUFFPEK *Tb);
72
72
static int  merge_index(MI_SORT_PARAM *,uint,unsigned char **,BUFFPEK *, int,
73
 
                              internal::IO_CACHE *);
 
73
                              internal::io_cache_st *);
74
74
static int  write_keys_varlen(MI_SORT_PARAM *info,unsigned char **sort_keys,
75
75
                       uint32_t count, BUFFPEK *buffpek,
76
 
                       internal::IO_CACHE *tempfile);
77
 
static uint32_t  read_to_buffer_varlen(internal::IO_CACHE *fromfile,BUFFPEK *buffpek,
 
76
                       internal::io_cache_st *tempfile);
 
77
static uint32_t  read_to_buffer_varlen(internal::io_cache_st *fromfile,BUFFPEK *buffpek,
78
78
                                uint32_t sort_length);
79
 
static int  write_merge_key(MI_SORT_PARAM *info, internal::IO_CACHE *to_file,
 
79
static int  write_merge_key(MI_SORT_PARAM *info, internal::io_cache_st *to_file,
80
80
                     unsigned char *key, uint32_t sort_length, uint32_t count);
81
81
static int  write_merge_key_varlen(MI_SORT_PARAM *info,
82
 
                            internal::IO_CACHE *to_file,
 
82
                            internal::io_cache_st *to_file,
83
83
                            unsigned char* key, uint32_t sort_length,
84
84
                            uint32_t count);
85
85
 
86
86
inline int
87
 
my_var_write(MI_SORT_PARAM *info, internal::IO_CACHE *to_file, unsigned char *bufs);
 
87
my_var_write(MI_SORT_PARAM *info, internal::io_cache_st *to_file, unsigned char *bufs);
88
88
 
89
89
/*
90
90
  Creates a index of sorted keys
103
103
int _create_index_by_sort(MI_SORT_PARAM *info,bool no_messages,
104
104
                          size_t sortbuff_size)
105
105
{
106
 
  int error;
107
 
  size_t maxbuffer, skr;
108
 
  uint32_t memavl,old_memavl,keys,sort_length;
 
106
  size_t skr;
 
107
  uint32_t memavl,keys;
109
108
  DYNAMIC_ARRAY buffpek;
110
 
  ha_rows records;
111
 
  unsigned char **sort_keys;
112
 
  internal::IO_CACHE tempfile, tempfile_for_exceptions;
 
109
  internal::io_cache_st tempfile, tempfile_for_exceptions;
113
110
 
114
111
  if (info->keyinfo->flag & HA_VAR_LENGTH_KEY)
115
112
  {
124
121
    info->write_key=write_merge_key;
125
122
  }
126
123
 
127
 
  my_b_clear(&tempfile);
128
 
  my_b_clear(&tempfile_for_exceptions);
 
124
  tempfile.clear();
 
125
  tempfile_for_exceptions.clear();
129
126
  memset(&buffpek, 0, sizeof(buffpek));
130
 
  sort_keys= (unsigned char **) NULL; error= 1;
131
 
  maxbuffer=1;
 
127
  unsigned char** sort_keys= (unsigned char **) NULL; 
 
128
  int error= 1;
 
129
  size_t maxbuffer=1;
132
130
 
133
131
  memavl=max(sortbuff_size,(size_t)MIN_SORT_MEMORY);
134
 
  records=      info->sort_info->max_records;
135
 
  sort_length=  info->key_length;
 
132
  ha_rows records= info->sort_info->max_records;
 
133
  uint32_t sort_length= info->key_length;
136
134
 
137
135
  while (memavl >= MIN_SORT_MEMORY)
138
136
  {
143
141
    else
144
142
      do
145
143
      {
146
 
        skr=maxbuffer;
147
 
        if (memavl < sizeof(BUFFPEK)* maxbuffer ||
148
 
            (keys=(memavl-sizeof(BUFFPEK)* maxbuffer)/
149
 
             (sort_length+sizeof(char*))) <= 1 ||
150
 
            keys < maxbuffer)
151
 
        {
152
 
          mi_check_print_error(info->sort_info->param,
153
 
                               "myisam_sort_buffer_size is too small");
154
 
          goto err;
155
 
        }
 
144
        skr=maxbuffer;
 
145
        if (memavl < sizeof(BUFFPEK)* maxbuffer ||
 
146
          (keys=(memavl-sizeof(BUFFPEK)* maxbuffer) / (sort_length+sizeof(char*))) <= 1 ||
 
147
          keys < maxbuffer)
 
148
        {
 
149
          mi_check_print_error(info->sort_info->param,
 
150
            "myisam_sort_buffer_size is too small");
 
151
          goto err;
 
152
        }
156
153
      }
157
154
      while ((maxbuffer= (size_t)(records/(keys-1)+1)) != skr);
158
155
 
159
 
    if ((sort_keys=(unsigned char **)malloc(keys*(sort_length+sizeof(char*)))))
160
 
    {
161
 
      if (my_init_dynamic_array(&buffpek, sizeof(BUFFPEK), maxbuffer,
162
 
                             maxbuffer/2))
163
 
      {
164
 
        free((unsigned char*) sort_keys);
165
 
        sort_keys= 0;
166
 
      }
167
 
      else
168
 
        break;
169
 
    }
170
 
    old_memavl=memavl;
171
 
    if ((memavl=memavl/4*3) < MIN_SORT_MEMORY && old_memavl > MIN_SORT_MEMORY)
172
 
      memavl=MIN_SORT_MEMORY;
 
156
    sort_keys=(unsigned char **)malloc(keys*(sort_length+sizeof(char*)));
 
157
    buffpek.init(sizeof(BUFFPEK), maxbuffer, maxbuffer/2);
 
158
    break;
173
159
  }
174
160
  if (memavl < MIN_SORT_MEMORY)
175
161
  {
202
188
      if (merge_many_buff(info,keys,sort_keys, (BUFFPEK*)buffpek.buffer, &maxbuffer, &tempfile))
203
189
        goto err;
204
190
    }
205
 
    if (internal::flush_io_cache(&tempfile) ||
 
191
    if (tempfile.flush() ||
206
192
        tempfile.reinit_io_cache(internal::READ_CACHE,0L,0,0))
207
193
      goto err;
208
194
    if (!no_messages)
214
200
  if (flush_pending_blocks(info))
215
201
    goto err;
216
202
 
217
 
  if (my_b_inited(&tempfile_for_exceptions))
 
203
  if (tempfile_for_exceptions.inited())
218
204
  {
219
205
    MI_INFO *idx=info->sort_info->info;
220
206
    uint32_t     keyno=info->key;
223
209
    if (not no_messages)
224
210
      printf("  - Adding exceptions\n");
225
211
 
226
 
    if (flush_io_cache(&tempfile_for_exceptions) || tempfile_for_exceptions.reinit_io_cache(internal::READ_CACHE,0L,0,0))
 
212
    if (tempfile_for_exceptions.flush() || tempfile_for_exceptions.reinit_io_cache(internal::READ_CACHE,0L,0,0))
227
213
    {
228
214
      goto err;
229
215
    }
230
216
 
231
 
    while (!my_b_read(&tempfile_for_exceptions,(unsigned char*)&key_length,
232
 
                      sizeof(key_length))
233
 
        && !my_b_read(&tempfile_for_exceptions,(unsigned char*)sort_keys,
234
 
                      (uint) key_length))
 
217
    while (not tempfile_for_exceptions.read(&key_length, sizeof(key_length))
 
218
        && not tempfile_for_exceptions.read(sort_keys, key_length))
235
219
    {
236
 
        if (_mi_ck_write(idx,keyno,(unsigned char*) sort_keys,key_length-ref_length))
237
 
          goto err;
 
220
      if (_mi_ck_write(idx,keyno,(unsigned char*) sort_keys,key_length-ref_length))
 
221
        goto err;
238
222
    }
239
223
  }
240
224
 
241
225
  error =0;
242
226
 
243
227
err:
244
 
  if (sort_keys)
245
 
    free((unsigned char*) sort_keys);
246
 
  delete_dynamic(&buffpek);
 
228
  free(sort_keys);
 
229
  buffpek.free();
247
230
  tempfile.close_cached_file();
248
231
  tempfile_for_exceptions.close_cached_file();
249
232
 
250
 
  return(error ? -1 : 0);
 
233
  return error ? -1 : 0;
251
234
} /* _create_index_by_sort */
252
235
 
253
236
 
256
239
static ha_rows  find_all_keys(MI_SORT_PARAM *info, uint32_t keys,
257
240
                              unsigned char **sort_keys,
258
241
                              DYNAMIC_ARRAY *buffpek,
259
 
                              size_t *maxbuffer, internal::IO_CACHE *tempfile,
260
 
                              internal::IO_CACHE *tempfile_for_exceptions)
 
242
                              size_t *maxbuffer, internal::io_cache_st *tempfile,
 
243
                              internal::io_cache_st *tempfile_for_exceptions)
261
244
{
262
245
  int error;
263
246
  uint32_t idx;
276
259
 
277
260
    if (++idx == keys)
278
261
    {
279
 
      if (info->write_keys(info,sort_keys,idx-1,(BUFFPEK *)alloc_dynamic(buffpek),
280
 
                     tempfile))
281
 
      return(HA_POS_ERROR);
 
262
      if (info->write_keys(info,sort_keys,idx-1,(BUFFPEK *)buffpek->alloc(), tempfile))
 
263
        return HA_POS_ERROR;
282
264
 
283
265
      sort_keys[0]=(unsigned char*) (sort_keys+keys);
284
266
      memcpy(sort_keys[0],sort_keys[idx-1],(size_t) info->key_length);
290
272
    return(HA_POS_ERROR);
291
273
  if (buffpek->size())
292
274
  {
293
 
    if (info->write_keys(info,sort_keys,idx,(BUFFPEK *)alloc_dynamic(buffpek),
294
 
                   tempfile))
295
 
      return(HA_POS_ERROR);
 
275
    if (info->write_keys(info,sort_keys,idx,(BUFFPEK *)buffpek->alloc(), tempfile))
 
276
      return HA_POS_ERROR;
296
277
    *maxbuffer=buffpek->size() - 1;
297
278
  }
298
279
  else
323
304
    {
324
305
      got_error=1;
325
306
      void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sinfo->rec_buff);
326
 
      if (rec_buff_ptr != NULL)
327
 
        free(rec_buff_ptr);
 
307
      free(rec_buff_ptr);
328
308
      continue;
329
309
    }
330
310
    if (!got_error)
348
328
    }
349
329
    free((unsigned char*) sinfo->sort_keys);
350
330
    void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sinfo->rec_buff);
351
 
    if (rec_buff_ptr != NULL)
352
 
      free(rec_buff_ptr);
 
331
    free(rec_buff_ptr);
353
332
    sinfo->sort_keys=0;
354
333
  }
355
334
 
356
 
  for (i= 0, sinfo= sort_param ;
357
 
       i < sort_info->total_keys ;
358
 
       i++,
359
 
         delete_dynamic(&sinfo->buffpek),
 
335
  for (i= 0, sinfo= sort_param; i < sort_info->total_keys; i++,
 
336
         sinfo->buffpek.free(),
360
337
         sinfo->tempfile.close_cached_file(),
361
338
         sinfo->tempfile_for_exceptions.close_cached_file(),
362
339
         sinfo++)
405
382
          continue;
406
383
        }
407
384
      }
408
 
      if (flush_io_cache(&sinfo->tempfile) || sinfo->tempfile.reinit_io_cache(internal::READ_CACHE,0L,0,0))
 
385
      if (sinfo->tempfile.flush() || sinfo->tempfile.reinit_io_cache(internal::READ_CACHE,0L,0,0))
409
386
      {
410
387
        got_error=1;
411
388
        continue;
420
397
        continue;
421
398
      }
422
399
    }
423
 
    if (my_b_inited(&sinfo->tempfile_for_exceptions))
 
400
    if (sinfo->tempfile_for_exceptions.inited())
424
401
    {
425
402
      uint32_t key_length;
426
403
 
427
404
      if (param->testflag & T_VERBOSE)
428
405
        printf("Key %d  - Dumping 'long' keys\n", sinfo->key+1);
429
406
 
430
 
      if (flush_io_cache(&sinfo->tempfile_for_exceptions) || sinfo->tempfile_for_exceptions.reinit_io_cache(internal::READ_CACHE,0L,0,0))
 
407
      if (sinfo->tempfile_for_exceptions.flush() || sinfo->tempfile_for_exceptions.reinit_io_cache(internal::READ_CACHE,0L,0,0))
431
408
      {
432
409
        got_error=1;
433
410
        continue;
434
411
      }
435
412
 
436
 
      while (!got_error &&
437
 
             !my_b_read(&sinfo->tempfile_for_exceptions,(unsigned char*)&key_length,
438
 
                        sizeof(key_length)))
 
413
      while (!got_error && not sinfo->tempfile_for_exceptions.read(&key_length, sizeof(key_length)))
439
414
      {
440
415
        unsigned char ft_buf[10];
441
 
        if (key_length > sizeof(ft_buf) ||
442
 
            my_b_read(&sinfo->tempfile_for_exceptions, (unsigned char*)ft_buf,
443
 
                      (uint)key_length) ||
444
 
            _mi_ck_write(info, sinfo->key, (unsigned char*)ft_buf,
445
 
                         key_length - info->s->rec_reflength))
446
 
          got_error=1;
 
416
        if (key_length > sizeof(ft_buf) || sinfo->tempfile_for_exceptions.read(ft_buf, (uint)key_length) 
 
417
          || _mi_ck_write(info, sinfo->key, (unsigned char*)ft_buf, key_length - info->s->rec_reflength))
 
418
          got_error= 1;
447
419
      }
448
420
    }
449
421
  }
454
426
        /* Write all keys in memory to file for later merge */
455
427
 
456
428
static int  write_keys(MI_SORT_PARAM *info, register unsigned char **sort_keys,
457
 
                             uint32_t count, BUFFPEK *buffpek, internal::IO_CACHE *tempfile)
 
429
                             uint32_t count, BUFFPEK *buffpek, internal::io_cache_st *tempfile)
458
430
{
459
431
  unsigned char **end;
460
432
  uint32_t sort_length=info->key_length;
461
433
 
462
 
  internal::my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
463
 
            info);
464
 
  if (!my_b_inited(tempfile) && tempfile->open_cached_file(P_tmpdir, "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
 
434
  internal::my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp, info);
 
435
  if (not tempfile->inited() && tempfile->open_cached_file(P_tmpdir, "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
465
436
    return(1);
466
437
 
467
 
  buffpek->file_pos=my_b_tell(tempfile);
 
438
  buffpek->file_pos= tempfile->tell();
468
439
  buffpek->count=count;
469
440
 
470
441
  for (end=sort_keys+count ; sort_keys != end ; sort_keys++)
471
442
  {
472
 
    if (my_b_write(tempfile,(unsigned char*) *sort_keys,(uint) sort_length))
 
443
    if (tempfile->write(*sort_keys, sort_length))
473
444
      return(1);
474
445
  }
475
446
  return(0);
477
448
 
478
449
 
479
450
inline int
480
 
my_var_write(MI_SORT_PARAM *info, internal::IO_CACHE *to_file, unsigned char *bufs)
 
451
my_var_write(MI_SORT_PARAM *info, internal::io_cache_st *to_file, unsigned char *bufs)
481
452
{
482
453
  int err;
483
454
  uint16_t len = _mi_keylength(info->keyinfo, (unsigned char*) bufs);
484
455
 
485
456
  /* The following is safe as this is a local file */
486
 
  if ((err= my_b_write(to_file, (unsigned char*)&len, sizeof(len))))
 
457
  if ((err= to_file->write(&len, sizeof(len))))
487
458
    return (err);
488
 
  if ((err= my_b_write(to_file,bufs, (uint) len)))
 
459
  if ((err= to_file->write(bufs, len)))
489
460
    return (err);
490
461
  return (0);
491
462
}
494
465
static int  write_keys_varlen(MI_SORT_PARAM *info,
495
466
                                    register unsigned char **sort_keys,
496
467
                                    uint32_t count, BUFFPEK *buffpek,
497
 
                                    internal::IO_CACHE *tempfile)
 
468
                                    internal::io_cache_st *tempfile)
498
469
{
499
470
  unsigned char **end;
500
471
  int err;
501
472
 
502
 
  internal::my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
503
 
            info);
504
 
  if (!my_b_inited(tempfile) && tempfile->open_cached_file(P_tmpdir, "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
 
473
  internal::my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp, info);
 
474
  if (not tempfile->inited() && tempfile->open_cached_file(P_tmpdir, "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
505
475
    return(1);
506
476
 
507
 
  buffpek->file_pos=my_b_tell(tempfile);
 
477
  buffpek->file_pos= tempfile->tell();
508
478
  buffpek->count=count;
509
479
  for (end=sort_keys+count ; sort_keys != end ; sort_keys++)
510
480
  {
516
486
 
517
487
 
518
488
static int  write_key(MI_SORT_PARAM *info, unsigned char *key,
519
 
                            internal::IO_CACHE *tempfile)
 
489
                            internal::io_cache_st *tempfile)
520
490
{
521
491
  uint32_t key_length=info->real_key_length;
522
492
 
523
 
  if (!my_b_inited(tempfile) && tempfile->open_cached_file(P_tmpdir, "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
 
493
  if (not tempfile->inited() && tempfile->open_cached_file(P_tmpdir, "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
524
494
    return(1);
525
495
 
526
 
  if (my_b_write(tempfile,(unsigned char*)&key_length,sizeof(key_length)) ||
527
 
      my_b_write(tempfile,(unsigned char*)key,(uint) key_length))
 
496
  if (tempfile->write(&key_length, sizeof(key_length)) ||
 
497
      tempfile->write(key, key_length))
528
498
    return(1);
529
499
  return(0);
530
500
} /* write_key */
550
520
 
551
521
static int  merge_many_buff(MI_SORT_PARAM *info, uint32_t keys,
552
522
                            unsigned char **sort_keys, BUFFPEK *buffpek,
553
 
                            size_t *maxbuffer, internal::IO_CACHE *t_file)
 
523
                            size_t *maxbuffer, internal::io_cache_st *t_file)
554
524
{
555
525
  uint32_t i;
556
 
  internal::IO_CACHE t_file2, *from_file, *to_file, *temp;
 
526
  internal::io_cache_st t_file2, *from_file, *to_file, *temp;
557
527
  BUFFPEK *lastbuff;
558
528
 
559
529
  if (*maxbuffer < MERGEBUFF2)
560
530
    return(0);
561
 
  if (flush_io_cache(t_file) || t_file2.open_cached_file(P_tmpdir, "ST",
562
 
                       DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
 
531
  if (t_file->flush() || t_file2.open_cached_file(P_tmpdir, "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
563
532
    return(1);
564
533
 
565
534
  from_file= t_file ; to_file= &t_file2;
577
546
    if (merge_buffers(info,keys,from_file,to_file,sort_keys,lastbuff++,
578
547
                      buffpek+i,buffpek+ *maxbuffer))
579
548
      break;
580
 
    if (flush_io_cache(to_file))
 
549
    if (to_file->flush())
581
550
      break;
582
551
    temp=from_file; from_file=to_file; to_file=temp;
583
552
    *maxbuffer= (int) (lastbuff-buffpek)-1;
604
573
    -1  Error
605
574
*/
606
575
 
607
 
static uint32_t  read_to_buffer(internal::IO_CACHE *fromfile, BUFFPEK *buffpek,
 
576
static uint32_t  read_to_buffer(internal::io_cache_st *fromfile, BUFFPEK *buffpek,
608
577
                                  uint32_t sort_length)
609
578
{
610
579
  register uint32_t count;
623
592
  return (count*sort_length);
624
593
} /* read_to_buffer */
625
594
 
626
 
static uint32_t  read_to_buffer_varlen(internal::IO_CACHE *fromfile, BUFFPEK *buffpek,
 
595
static uint32_t  read_to_buffer_varlen(internal::io_cache_st *fromfile, BUFFPEK *buffpek,
627
596
                                         uint32_t sort_length)
628
597
{
629
598
  register uint32_t count;
656
625
 
657
626
 
658
627
static int  write_merge_key_varlen(MI_SORT_PARAM *info,
659
 
                                         internal::IO_CACHE *to_file, unsigned char* key,
 
628
                                         internal::io_cache_st *to_file, unsigned char* key,
660
629
                                         uint32_t sort_length, uint32_t count)
661
630
{
662
631
  uint32_t idx;
673
642
}
674
643
 
675
644
 
676
 
static int  write_merge_key(MI_SORT_PARAM *info,
677
 
                                  internal::IO_CACHE *to_file, unsigned char *key,
 
645
static int  write_merge_key(MI_SORT_PARAM*,
 
646
                                  internal::io_cache_st *to_file, unsigned char *key,
678
647
                                  uint32_t sort_length, uint32_t count)
679
648
{
680
 
  (void)info;
681
 
  return my_b_write(to_file, key, (size_t) sort_length*count);
 
649
  return to_file->write(key, sort_length*count);
682
650
}
683
651
 
684
652
/*
706
674
*/
707
675
 
708
676
static int
709
 
merge_buffers(MI_SORT_PARAM *info, uint32_t keys, internal::IO_CACHE *from_file,
710
 
              internal::IO_CACHE *to_file, unsigned char **sort_keys, BUFFPEK *lastbuff,
 
677
merge_buffers(MI_SORT_PARAM *info, uint32_t keys, internal::io_cache_st *from_file,
 
678
              internal::io_cache_st *to_file, unsigned char **sort_keys, BUFFPEK *lastbuff,
711
679
              BUFFPEK *Fb, BUFFPEK *Tb)
712
680
{
713
681
  int error;
724
692
  maxcount=keys/((uint) (Tb-Fb) +1);
725
693
  assert(maxcount > 0);
726
694
  if (to_file)
727
 
    to_start_filepos=my_b_tell(to_file);
 
695
    to_start_filepos= to_file->tell();
728
696
  strpos=(unsigned char*) sort_keys;
729
697
  sort_length=info->key_length;
730
698
 
823
791
 
824
792
static int
825
793
merge_index(MI_SORT_PARAM *info, uint32_t keys, unsigned char **sort_keys,
826
 
            BUFFPEK *buffpek, int maxbuffer, internal::IO_CACHE *tempfile)
 
794
            BUFFPEK *buffpek, int maxbuffer, internal::io_cache_st *tempfile)
827
795
{
828
 
  if (merge_buffers(info,keys,tempfile,(internal::IO_CACHE*) 0,sort_keys,buffpek,buffpek,
 
796
  if (merge_buffers(info,keys,tempfile,(internal::io_cache_st*) 0,sort_keys,buffpek,buffpek,
829
797
                    buffpek+maxbuffer))
830
798
    return(1);
831
799
  return(0);