~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/sort.c

  • Committer: Stewart Smith
  • Date: 2008-07-07 02:19:59 UTC
  • mfrom: (80 drizzle)
  • mto: This revision was merged to the branch mainline in revision 111.
  • Revision ID: stewart@flamingspork.com-20080707021959-1e3eykadgdj0i2v2
mergeĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
  them in sorted order through SORT_INFO functions.
19
19
*/
20
20
 
21
 
#include "fulltext.h"
 
21
#include "myisamdef.h"
22
22
#if defined(MSDOS) || defined(__WIN__)
23
23
#include <fcntl.h>
24
24
#else
70
70
                                BUFFPEK *Fb, BUFFPEK *Tb);
71
71
static int  merge_index(MI_SORT_PARAM *,uint,uchar **,BUFFPEK *, int,
72
72
                              IO_CACHE *);
73
 
static int flush_ft_buf(MI_SORT_PARAM *info);
74
73
 
75
74
static int  write_keys_varlen(MI_SORT_PARAM *info,uchar **sort_keys,
76
75
                                    uint count, BUFFPEK *buffpek,
157
156
      }
158
157
      while ((maxbuffer= (int) (records/(keys-1)+1)) != skr);
159
158
 
160
 
    if ((sort_keys=(uchar **)my_malloc(keys*(sort_length+sizeof(char*))+
161
 
                                       HA_FT_MAXBYTELEN, MYF(0))))
 
159
    if ((sort_keys=(uchar **)my_malloc(keys*(sort_length+sizeof(char*)), MYF(0))))
162
160
    {
163
161
      if (my_init_dynamic_array(&buffpek, sizeof(BUFFPEK), maxbuffer,
164
162
                             maxbuffer/2))
215
213
      goto err;                                 /* purecov: inspected */
216
214
  }
217
215
 
218
 
  if (flush_ft_buf(info) || flush_pending_blocks(info))
 
216
  if (flush_pending_blocks(info))
219
217
    goto err;
220
218
 
221
219
  if (my_b_inited(&tempfile_for_exceptions))
373
371
        while ((maxbuffer= (int) (idx/(keys-1)+1)) != skr);
374
372
      }
375
373
      if ((sort_keys= (uchar**)
376
 
           my_malloc(keys*(sort_length+sizeof(char*))+
377
 
                     ((sort_param->keyinfo->flag & HA_FULLTEXT) ?
378
 
                      HA_FT_MAXBYTELEN : 0), MYF(0))))
 
374
           my_malloc(keys*(sort_length+sizeof(char*)), MYF(0))))
379
375
      {
380
376
        if (my_init_dynamic_array(&sort_param->buffpek, sizeof(BUFFPEK),
381
377
                                  maxbuffer, maxbuffer/2))
516
512
          printf("Key %d  - Dumping %u keys\n",sinfo->key+1, sinfo->keys);
517
513
          fflush(stdout);
518
514
        }
519
 
        if (write_index(sinfo, sinfo->sort_keys, sinfo->keys) ||
520
 
            flush_ft_buf(sinfo) || flush_pending_blocks(sinfo))
 
515
        if (write_index(sinfo, sinfo->sort_keys, sinfo->keys) || flush_pending_blocks(sinfo))
521
516
          got_error=1;
522
517
      }
523
518
      if (!got_error && param->testflag & T_STATISTICS)
596
591
      if (merge_index(sinfo, keys, (uchar **)mergebuf,
597
592
                      dynamic_element(&sinfo->buffpek,0,BUFFPEK *),
598
593
                      maxbuffer,&sinfo->tempfile) ||
599
 
          flush_ft_buf(sinfo) ||
600
594
          flush_pending_blocks(sinfo))
601
595
      {
602
596
        got_error=1;
621
615
             !my_b_read(&sinfo->tempfile_for_exceptions,(uchar*)&key_length,
622
616
                        sizeof(key_length)))
623
617
      {
624
 
        uchar ft_buf[HA_FT_MAXBYTELEN + HA_FT_WLEN + 10];
 
618
        uchar ft_buf[10];
625
619
        if (key_length > sizeof(ft_buf) ||
626
620
            my_b_read(&sinfo->tempfile_for_exceptions, (uchar*)ft_buf,
627
621
                      (uint)key_length) ||
1035
1029
  DBUG_RETURN(0);
1036
1030
} /* merge_index */
1037
1031
 
1038
 
static int
1039
 
flush_ft_buf(MI_SORT_PARAM *info)
1040
 
{
1041
 
  int err=0;
1042
 
  if (info->sort_info->ft_buf)
1043
 
  {
1044
 
    err=sort_ft_buf_flush(info);
1045
 
    my_free((uchar*)info->sort_info->ft_buf, MYF(0));
1046
 
    info->sort_info->ft_buf=0;
1047
 
  }
1048
 
  return err;
1049
 
}
1050