~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/sort.c

  • Committer: Monty Taylor
  • Date: 2008-12-01 00:45:49 UTC
  • mfrom: (629.4.1 fix-sizet-problem)
  • mto: This revision was merged to the branch mainline in revision 634.
  • Revision ID: mordred@solanthus.local-20081201004549-frpjlf6zrbe77crv
MergedĀ fromĀ me.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
/* Functions defined in this file */
45
45
 
46
46
static ha_rows  find_all_keys(MI_SORT_PARAM *info,uint32_t keys,
47
 
                                    unsigned char **sort_keys,
48
 
                                    DYNAMIC_ARRAY *buffpek,int *maxbuffer,
49
 
                                    IO_CACHE *tempfile,
50
 
                                    IO_CACHE *tempfile_for_exceptions);
 
47
                              unsigned char **sort_keys,
 
48
                              DYNAMIC_ARRAY *buffpek,
 
49
                              size_t *maxbuffer,
 
50
                              IO_CACHE *tempfile,
 
51
                              IO_CACHE *tempfile_for_exceptions);
51
52
static int  write_keys(MI_SORT_PARAM *info,unsigned char **sort_keys,
52
53
                             uint32_t count, BUFFPEK *buffpek,IO_CACHE *tempfile);
53
54
static int  write_key(MI_SORT_PARAM *info, unsigned char *key,
55
56
static int  write_index(MI_SORT_PARAM *info,unsigned char * *sort_keys,
56
57
                              uint32_t count);
57
58
static int  merge_many_buff(MI_SORT_PARAM *info,uint32_t keys,
58
 
                                  unsigned char * *sort_keys,
59
 
                                  BUFFPEK *buffpek,int *maxbuffer,
60
 
                                  IO_CACHE *t_file);
 
59
                            unsigned char * *sort_keys,
 
60
                            BUFFPEK *buffpek,size_t *maxbuffer,
 
61
                            IO_CACHE *t_file);
61
62
static uint32_t  read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
62
63
                                  uint32_t sort_length);
63
64
static int  merge_buffers(MI_SORT_PARAM *info,uint32_t keys,
96
97
*/
97
98
 
98
99
int _create_index_by_sort(MI_SORT_PARAM *info,bool no_messages,
99
 
                          uint32_t sortbuff_size)
 
100
                          size_t sortbuff_size)
100
101
{
101
 
  int error,maxbuffer,skr;
 
102
  int error;
 
103
  size_t maxbuffer, skr;
102
104
  uint32_t memavl,old_memavl,keys,sort_length;
103
105
  DYNAMIC_ARRAY buffpek;
104
106
  ha_rows records;
138
140
      do
139
141
      {
140
142
        skr=maxbuffer;
141
 
        if (memavl < sizeof(BUFFPEK)*(uint) maxbuffer ||
142
 
            (keys=(memavl-sizeof(BUFFPEK)*(uint) maxbuffer)/
 
143
        if (memavl < sizeof(BUFFPEK)* maxbuffer ||
 
144
            (keys=(memavl-sizeof(BUFFPEK)* maxbuffer)/
143
145
             (sort_length+sizeof(char*))) <= 1 ||
144
 
            keys < (uint) maxbuffer)
 
146
            keys < maxbuffer)
145
147
        {
146
148
          mi_check_print_error(info->sort_info->param,
147
149
                               "myisam_sort_buffer_size is too small");
148
150
          goto err;
149
151
        }
150
152
      }
151
 
      while ((maxbuffer= (int) (records/(keys-1)+1)) != skr);
 
153
      while ((maxbuffer= (records/(keys-1)+1)) != skr);
152
154
 
153
155
    if ((sort_keys=(unsigned char **)my_malloc(keys*(sort_length+sizeof(char*)), MYF(0))))
154
156
    {
176
178
    printf("  - Searching for keys, allocating buffer for %d keys\n",keys);
177
179
 
178
180
  if ((records=find_all_keys(info,keys,sort_keys,&buffpek,&maxbuffer,
179
 
                                  &tempfile,&tempfile_for_exceptions))
 
181
                             &tempfile,&tempfile_for_exceptions))
180
182
      == HA_POS_ERROR)
181
183
    goto err; /* purecov: tested */
182
184
  if (maxbuffer == 0)
248
250
/* Search after all keys and place them in a temp. file */
249
251
 
250
252
static ha_rows  find_all_keys(MI_SORT_PARAM *info, uint32_t keys,
251
 
                                    unsigned char **sort_keys, DYNAMIC_ARRAY *buffpek,
252
 
                                    int *maxbuffer, IO_CACHE *tempfile,
253
 
                                    IO_CACHE *tempfile_for_exceptions)
 
253
                              unsigned char **sort_keys,
 
254
                              DYNAMIC_ARRAY *buffpek,
 
255
                              size_t *maxbuffer, IO_CACHE *tempfile,
 
256
                              IO_CACHE *tempfile_for_exceptions)
254
257
{
255
258
  int error;
256
259
  uint32_t idx;
302
305
  MI_SORT_PARAM *sort_param= (MI_SORT_PARAM*) arg;
303
306
  int error;
304
307
  uint32_t memavl,old_memavl,keys,sort_length;
305
 
  uint32_t idx, maxbuffer;
 
308
  uint32_t idx;
 
309
  size_t maxbuffer;
306
310
  unsigned char **sort_keys=0;
307
311
 
308
312
  error=1;
352
356
          if (memavl < sizeof(BUFFPEK)*maxbuffer ||
353
357
              (keys=(memavl-sizeof(BUFFPEK)*maxbuffer)/
354
358
               (sort_length+sizeof(char*))) <= 1 ||
355
 
              keys < (uint) maxbuffer)
 
359
              keys < maxbuffer)
356
360
          {
357
361
            mi_check_print_error(sort_param->sort_info->param,
358
362
                                 "myisam_sort_buffer_size is too small");
359
363
            goto err;
360
364
          }
361
365
        }
362
 
        while ((maxbuffer= (int) (idx/(keys-1)+1)) != skr);
 
366
        while ((maxbuffer= (idx/(keys-1)+1)) != skr);
363
367
      }
364
368
      if ((sort_keys= (unsigned char**)
365
369
           my_malloc(keys*(sort_length+sizeof(char*)), MYF(0))))
540
544
    }
541
545
    if (sinfo->buffpek.elements)
542
546
    {
543
 
      uint32_t maxbuffer=sinfo->buffpek.elements-1;
 
547
      size_t maxbuffer=sinfo->buffpek.elements-1;
544
548
      if (!mergebuf)
545
549
      {
546
550
        length=param->sort_buffer_length;
563
567
          printf("Key %d  - Merging %u keys\n",sinfo->key+1, sinfo->keys);
564
568
        if (merge_many_buff(sinfo, keys, (unsigned char **)mergebuf,
565
569
                            dynamic_element(&sinfo->buffpek, 0, BUFFPEK *),
566
 
                            (int*) &maxbuffer, &sinfo->tempfile))
 
570
                            &maxbuffer, &sinfo->tempfile))
567
571
        {
568
572
          got_error=1;
569
573
          continue;
722
726
        /* Merge buffers to make < MERGEBUFF2 buffers */
723
727
 
724
728
static int  merge_many_buff(MI_SORT_PARAM *info, uint32_t keys,
725
 
                                  unsigned char **sort_keys, BUFFPEK *buffpek,
726
 
                                  int *maxbuffer, IO_CACHE *t_file)
 
729
                            unsigned char **sort_keys, BUFFPEK *buffpek,
 
730
                            size_t *maxbuffer, IO_CACHE *t_file)
727
731
{
728
 
  register int i;
 
732
  uint32_t i;
729
733
  IO_CACHE t_file2, *from_file, *to_file, *temp;
730
734
  BUFFPEK *lastbuff;
731
735