~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/*
17
  Creates a index for a database by reading keys, sorting them and outputing
18
  them in sorted order through SORT_INFO functions.
19
*/
20
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
21
#include "myisam_priv.h"
1 by brian
clean slate
22
#include <stddef.h>
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
23
#include <queue>
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
24
#include <algorithm>
1 by brian
clean slate
25
26
/* static variables */
27
28
#undef MIN_SORT_MEMORY
29
#undef MYF_RW
30
#undef DISK_BUFFER_SIZE
31
32
#define MERGEBUFF 15
33
#define MERGEBUFF2 31
34
#define MIN_SORT_MEMORY (4096-MALLOC_OVERHEAD)
35
#define MYF_RW  MYF(MY_NABP | MY_WME | MY_WAIT_IF_FULL)
36
#define DISK_BUFFER_SIZE (IO_SIZE*16)
37
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
38
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
39
using namespace drizzled;
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
40
1 by brian
clean slate
41
42
/*
43
 Pointers of functions for store and read keys from temp file
44
*/
45
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
46
extern void print_error(const char *fmt,...);
1 by brian
clean slate
47
48
/* Functions defined in this file */
49
1165.1.64 by Stewart Smith
find_all_keys() static to myisam/sort.cc (luckily the filesort one was static, otherwise....)
50
static ha_rows  find_all_keys(MI_SORT_PARAM *info,uint32_t keys,
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
51
			      unsigned char **sort_keys,
52
			      DYNAMIC_ARRAY *buffpek,
53
			      size_t *maxbuffer,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
54
			      internal::IO_CACHE *tempfile,
55
			      internal::IO_CACHE *tempfile_for_exceptions);
1165.1.72 by Stewart Smith
make write_keys() static to myisam/sort.cc
56
static int  write_keys(MI_SORT_PARAM *info,unsigned char **sort_keys,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
57
                             uint32_t count, BUFFPEK *buffpek,internal::IO_CACHE *tempfile);
1165.1.71 by Stewart Smith
make write_key() static to myisam/sort.cc
58
static int  write_key(MI_SORT_PARAM *info, unsigned char *key,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
59
			    internal::IO_CACHE *tempfile);
1165.1.70 by Stewart Smith
make write_index() static to myisam/sort.cc
60
static int  write_index(MI_SORT_PARAM *info,unsigned char * *sort_keys,
482 by Brian Aker
Remove uint.
61
                              uint32_t count);
1165.1.67 by Stewart Smith
make merge_many_buff() static to myisam/sort.cc
62
static int  merge_many_buff(MI_SORT_PARAM *info,uint32_t keys,
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
63
			    unsigned char * *sort_keys,
64
			    BUFFPEK *buffpek,size_t *maxbuffer,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
65
			    internal::IO_CACHE *t_file);
66
static uint32_t  read_to_buffer(internal::IO_CACHE *fromfile,BUFFPEK *buffpek,
482 by Brian Aker
Remove uint.
67
                                  uint32_t sort_length);
1165.1.65 by Stewart Smith
make merge_buffers() static to myisam/sort.cc
68
static int  merge_buffers(MI_SORT_PARAM *info,uint32_t keys,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
69
                                internal::IO_CACHE *from_file, internal::IO_CACHE *to_file,
481 by Brian Aker
Remove all of uchar.
70
                                unsigned char * *sort_keys, BUFFPEK *lastbuff,
1 by brian
clean slate
71
                                BUFFPEK *Fb, BUFFPEK *Tb);
1165.1.66 by Stewart Smith
make merge_index() static to myisam/sort.cc
72
static int  merge_index(MI_SORT_PARAM *,uint,unsigned char **,BUFFPEK *, int,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
73
                              internal::IO_CACHE *);
1165.1.73 by Stewart Smith
make write_keys_varlen() static to myisam/sort.cc
74
static int  write_keys_varlen(MI_SORT_PARAM *info,unsigned char **sort_keys,
960.3.1 by Monty Taylor
Fixed linkage issues on solaris.
75
                       uint32_t count, BUFFPEK *buffpek,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
76
                       internal::IO_CACHE *tempfile);
77
static uint32_t  read_to_buffer_varlen(internal::IO_CACHE *fromfile,BUFFPEK *buffpek,
960.3.1 by Monty Taylor
Fixed linkage issues on solaris.
78
                                uint32_t sort_length);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
79
static int  write_merge_key(MI_SORT_PARAM *info, internal::IO_CACHE *to_file,
960.3.1 by Monty Taylor
Fixed linkage issues on solaris.
80
                     unsigned char *key, uint32_t sort_length, uint32_t count);
1165.1.75 by Stewart Smith
make write_merge_key_varlen() static to myisam/sort.cc
81
static int  write_merge_key_varlen(MI_SORT_PARAM *info,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
82
                            internal::IO_CACHE *to_file,
960.3.1 by Monty Taylor
Fixed linkage issues on solaris.
83
                            unsigned char* key, uint32_t sort_length,
84
                            uint32_t count);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
85
960.3.1 by Monty Taylor
Fixed linkage issues on solaris.
86
inline int
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
87
my_var_write(MI_SORT_PARAM *info, internal::IO_CACHE *to_file, unsigned char *bufs);
1 by brian
clean slate
88
89
/*
90
  Creates a index of sorted keys
91
92
  SYNOPSIS
93
    _create_index_by_sort()
94
    info		Sort parameters
95
    no_messages		Set to 1 if no output
96
    sortbuff_size	Size if sortbuffer to allocate
97
98
  RESULT
99
    0	ok
100
   <> 0 Error
101
*/
102
281 by Brian Aker
Converted myisam away from my_bool
103
int _create_index_by_sort(MI_SORT_PARAM *info,bool no_messages,
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
104
			  size_t sortbuff_size)
1 by brian
clean slate
105
{
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
106
  int error;
107
  size_t maxbuffer, skr;
482 by Brian Aker
Remove uint.
108
  uint32_t memavl,old_memavl,keys,sort_length;
1 by brian
clean slate
109
  DYNAMIC_ARRAY buffpek;
110
  ha_rows records;
481 by Brian Aker
Remove all of uchar.
111
  unsigned char **sort_keys;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
112
  internal::IO_CACHE tempfile, tempfile_for_exceptions;
1 by brian
clean slate
113
114
  if (info->keyinfo->flag & HA_VAR_LENGTH_KEY)
115
  {
116
    info->write_keys=write_keys_varlen;
117
    info->read_to_buffer=read_to_buffer_varlen;
118
    info->write_key= write_merge_key_varlen;
119
  }
120
  else
121
  {
122
    info->write_keys=write_keys;
123
    info->read_to_buffer=read_to_buffer;
124
    info->write_key=write_merge_key;
125
  }
126
127
  my_b_clear(&tempfile);
128
  my_b_clear(&tempfile_for_exceptions);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
129
  memset(&buffpek, 0, sizeof(buffpek));
481 by Brian Aker
Remove all of uchar.
130
  sort_keys= (unsigned char **) NULL; error= 1;
1 by brian
clean slate
131
  maxbuffer=1;
132
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
133
  memavl=max(sortbuff_size,(size_t)MIN_SORT_MEMORY);
1 by brian
clean slate
134
  records=	info->sort_info->max_records;
135
  sort_length=	info->key_length;
136
137
  while (memavl >= MIN_SORT_MEMORY)
138
  {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
139
    if ((records < UINT32_MAX) &&
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
140
       ((internal::my_off_t) (records + 1) *
141
        (sort_length + sizeof(char*)) <= (internal::my_off_t) memavl))
1 by brian
clean slate
142
      keys= (uint)records+1;
143
    else
144
      do
145
      {
146
	skr=maxbuffer;
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
147
	if (memavl < sizeof(BUFFPEK)* maxbuffer ||
148
	    (keys=(memavl-sizeof(BUFFPEK)* maxbuffer)/
1 by brian
clean slate
149
             (sort_length+sizeof(char*))) <= 1 ||
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
150
            keys < maxbuffer)
1 by brian
clean slate
151
	{
152
	  mi_check_print_error(info->sort_info->param,
153
			       "myisam_sort_buffer_size is too small");
154
	  goto err;
155
	}
156
      }
988.2.2 by Trond Norbye
size_t and uint64_t is not the same in 32 bit builds. Add explicit casting
157
      while ((maxbuffer= (size_t)(records/(keys-1)+1)) != skr);
1 by brian
clean slate
158
656.1.25 by Monty Taylor
Removed my_malloc stuff from storage/
159
    if ((sort_keys=(unsigned char **)malloc(keys*(sort_length+sizeof(char*)))))
1 by brian
clean slate
160
    {
161
      if (my_init_dynamic_array(&buffpek, sizeof(BUFFPEK), maxbuffer,
162
			     maxbuffer/2))
163
      {
481 by Brian Aker
Remove all of uchar.
164
	free((unsigned char*) sort_keys);
1 by brian
clean slate
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;
173
  }
174
  if (memavl < MIN_SORT_MEMORY)
175
  {
971.6.11 by Eric Day
Removed purecov messages.
176
    mi_check_print_error(info->sort_info->param,"MyISAM sort buffer too small");
177
    goto err;
1 by brian
clean slate
178
  }
179
  (*info->lock_in_memory)(info->sort_info->param);/* Everything is allocated */
180
181
  if (!no_messages)
182
    printf("  - Searching for keys, allocating buffer for %d keys\n",keys);
183
184
  if ((records=find_all_keys(info,keys,sort_keys,&buffpek,&maxbuffer,
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
185
			     &tempfile,&tempfile_for_exceptions))
1 by brian
clean slate
186
      == HA_POS_ERROR)
971.6.11 by Eric Day
Removed purecov messages.
187
    goto err;
1 by brian
clean slate
188
  if (maxbuffer == 0)
189
  {
190
    if (!no_messages)
305 by Brian Aker
Another pass of ulong removal.
191
      printf("  - Dumping %u keys\n", (uint32_t) records);
1 by brian
clean slate
192
    if (write_index(info,sort_keys, (uint) records))
971.6.11 by Eric Day
Removed purecov messages.
193
      goto err;
1 by brian
clean slate
194
  }
195
  else
196
  {
197
    keys=(keys*(sort_length+sizeof(char*)))/sort_length;
198
    if (maxbuffer >= MERGEBUFF2)
199
    {
200
      if (!no_messages)
971.6.11 by Eric Day
Removed purecov messages.
201
	printf("  - Merging %u keys\n", (uint32_t) records);
1 by brian
clean slate
202
      if (merge_many_buff(info,keys,sort_keys,
203
                  dynamic_element(&buffpek,0,BUFFPEK *),&maxbuffer,&tempfile))
971.6.11 by Eric Day
Removed purecov messages.
204
	goto err;
1 by brian
clean slate
205
    }
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
206
    if (internal::flush_io_cache(&tempfile) ||
207
	internal::reinit_io_cache(&tempfile,internal::READ_CACHE,0L,0,0))
971.6.11 by Eric Day
Removed purecov messages.
208
      goto err;
1 by brian
clean slate
209
    if (!no_messages)
971.6.11 by Eric Day
Removed purecov messages.
210
      printf("  - Last merge and dumping keys\n");
1 by brian
clean slate
211
    if (merge_index(info,keys,sort_keys,dynamic_element(&buffpek,0,BUFFPEK *),
212
                    maxbuffer,&tempfile))
971.6.11 by Eric Day
Removed purecov messages.
213
      goto err;
1 by brian
clean slate
214
  }
215
76.1.1 by Brian Aker
Final removal of fulltext core from myisam.
216
  if (flush_pending_blocks(info))
1 by brian
clean slate
217
    goto err;
218
219
  if (my_b_inited(&tempfile_for_exceptions))
220
  {
221
    MI_INFO *idx=info->sort_info->info;
482 by Brian Aker
Remove uint.
222
    uint32_t     keyno=info->key;
223
    uint32_t     key_length, ref_length=idx->s->rec_reflength;
1 by brian
clean slate
224
225
    if (!no_messages)
971.6.11 by Eric Day
Removed purecov messages.
226
      printf("  - Adding exceptions\n");
1 by brian
clean slate
227
    if (flush_io_cache(&tempfile_for_exceptions) ||
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
228
	reinit_io_cache(&tempfile_for_exceptions,internal::READ_CACHE,0L,0,0))
1 by brian
clean slate
229
      goto err;
230
481 by Brian Aker
Remove all of uchar.
231
    while (!my_b_read(&tempfile_for_exceptions,(unsigned char*)&key_length,
1 by brian
clean slate
232
		      sizeof(key_length))
481 by Brian Aker
Remove all of uchar.
233
        && !my_b_read(&tempfile_for_exceptions,(unsigned char*)sort_keys,
1 by brian
clean slate
234
		      (uint) key_length))
235
    {
481 by Brian Aker
Remove all of uchar.
236
	if (_mi_ck_write(idx,keyno,(unsigned char*) sort_keys,key_length-ref_length))
1 by brian
clean slate
237
	  goto err;
238
    }
239
  }
240
241
  error =0;
242
243
err:
244
  if (sort_keys)
481 by Brian Aker
Remove all of uchar.
245
    free((unsigned char*) sort_keys);
1 by brian
clean slate
246
  delete_dynamic(&buffpek);
247
  close_cached_file(&tempfile);
248
  close_cached_file(&tempfile_for_exceptions);
249
51.1.119 by Jay Pipes
DBUG symbol removal
250
  return(error ? -1 : 0);
1 by brian
clean slate
251
} /* _create_index_by_sort */
252
253
254
/* Search after all keys and place them in a temp. file */
255
1165.1.64 by Stewart Smith
find_all_keys() static to myisam/sort.cc (luckily the filesort one was static, otherwise....)
256
static ha_rows  find_all_keys(MI_SORT_PARAM *info, uint32_t keys,
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
257
			      unsigned char **sort_keys,
258
			      DYNAMIC_ARRAY *buffpek,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
259
			      size_t *maxbuffer, internal::IO_CACHE *tempfile,
260
			      internal::IO_CACHE *tempfile_for_exceptions)
1 by brian
clean slate
261
{
262
  int error;
482 by Brian Aker
Remove uint.
263
  uint32_t idx;
1 by brian
clean slate
264
265
  idx=error=0;
481 by Brian Aker
Remove all of uchar.
266
  sort_keys[0]=(unsigned char*) (sort_keys+keys);
1 by brian
clean slate
267
268
  while (!(error=(*info->key_read)(info,sort_keys[idx])))
269
  {
270
    if (info->real_key_length > info->key_length)
271
    {
272
      if (write_key(info,sort_keys[idx],tempfile_for_exceptions))
971.6.11 by Eric Day
Removed purecov messages.
273
        return(HA_POS_ERROR);
1 by brian
clean slate
274
      continue;
275
    }
276
277
    if (++idx == keys)
278
    {
279
      if (info->write_keys(info,sort_keys,idx-1,(BUFFPEK *)alloc_dynamic(buffpek),
280
		     tempfile))
971.6.11 by Eric Day
Removed purecov messages.
281
      return(HA_POS_ERROR);
1 by brian
clean slate
282
481 by Brian Aker
Remove all of uchar.
283
      sort_keys[0]=(unsigned char*) (sort_keys+keys);
1 by brian
clean slate
284
      memcpy(sort_keys[0],sort_keys[idx-1],(size_t) info->key_length);
285
      idx=1;
286
    }
287
    sort_keys[idx]=sort_keys[idx-1]+info->key_length;
288
  }
289
  if (error > 0)
971.6.11 by Eric Day
Removed purecov messages.
290
    return(HA_POS_ERROR);
1 by brian
clean slate
291
  if (buffpek->elements)
292
  {
293
    if (info->write_keys(info,sort_keys,idx,(BUFFPEK *)alloc_dynamic(buffpek),
294
		   tempfile))
971.6.11 by Eric Day
Removed purecov messages.
295
      return(HA_POS_ERROR);
1 by brian
clean slate
296
    *maxbuffer=buffpek->elements-1;
297
  }
298
  else
299
    *maxbuffer=0;
300
51.1.119 by Jay Pipes
DBUG symbol removal
301
  return((*maxbuffer)*(keys-1)+idx);
1 by brian
clean slate
302
} /* find_all_keys */
303
304
305
int thr_write_keys(MI_SORT_PARAM *sort_param)
306
{
307
  SORT_INFO *sort_info= sort_param->sort_info;
308
  MI_CHECK *param= sort_info->param;
305 by Brian Aker
Another pass of ulong removal.
309
  uint32_t length= 0, keys;
310
  ulong *rec_per_key_part= param->rec_per_key_part;
1 by brian
clean slate
311
  int got_error=sort_info->got_error;
482 by Brian Aker
Remove uint.
312
  uint32_t i;
1 by brian
clean slate
313
  MI_INFO *info=sort_info->info;
314
  MYISAM_SHARE *share=info->s;
315
  MI_SORT_PARAM *sinfo;
481 by Brian Aker
Remove all of uchar.
316
  unsigned char *mergebuf=0;
1 by brian
clean slate
317
318
  for (i= 0, sinfo= sort_param ;
319
       i < sort_info->total_keys ;
320
       i++, rec_per_key_part+=sinfo->keyinfo->keysegs, sinfo++)
321
  {
322
    if (!sinfo->sort_keys)
323
    {
324
      got_error=1;
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
325
      void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sinfo->rec_buff);
326
      if (rec_buff_ptr != NULL)
327
        free(rec_buff_ptr);
1 by brian
clean slate
328
      continue;
329
    }
330
    if (!got_error)
331
    {
332
      mi_set_key_active(share->state.key_map, sinfo->key);
333
      if (!sinfo->buffpek.elements)
334
      {
335
        if (param->testflag & T_VERBOSE)
336
        {
337
          printf("Key %d  - Dumping %u keys\n",sinfo->key+1, sinfo->keys);
338
          fflush(stdout);
339
        }
76.1.1 by Brian Aker
Final removal of fulltext core from myisam.
340
        if (write_index(sinfo, sinfo->sort_keys, sinfo->keys) || flush_pending_blocks(sinfo))
1 by brian
clean slate
341
          got_error=1;
342
      }
343
      if (!got_error && param->testflag & T_STATISTICS)
344
        update_key_parts(sinfo->keyinfo, rec_per_key_part, sinfo->unique,
345
                         param->stats_method == MI_STATS_METHOD_IGNORE_NULLS?
346
                         sinfo->notnull: NULL,
151 by Brian Aker
Ulonglong to uint64_t
347
                         (uint64_t) info->state->records);
1 by brian
clean slate
348
    }
481 by Brian Aker
Remove all of uchar.
349
    free((unsigned char*) sinfo->sort_keys);
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
350
    void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sinfo->rec_buff);
351
    if (rec_buff_ptr != NULL)
352
      free(rec_buff_ptr);
1 by brian
clean slate
353
    sinfo->sort_keys=0;
354
  }
355
356
  for (i= 0, sinfo= sort_param ;
357
       i < sort_info->total_keys ;
358
       i++,
359
	 delete_dynamic(&sinfo->buffpek),
360
	 close_cached_file(&sinfo->tempfile),
361
	 close_cached_file(&sinfo->tempfile_for_exceptions),
362
	 sinfo++)
363
  {
364
    if (got_error)
365
      continue;
366
    if (sinfo->keyinfo->flag & HA_VAR_LENGTH_KEY)
367
    {
368
      sinfo->write_keys=write_keys_varlen;
369
      sinfo->read_to_buffer=read_to_buffer_varlen;
370
      sinfo->write_key=write_merge_key_varlen;
371
    }
372
    else
373
    {
374
      sinfo->write_keys=write_keys;
375
      sinfo->read_to_buffer=read_to_buffer;
376
      sinfo->write_key=write_merge_key;
377
    }
378
    if (sinfo->buffpek.elements)
379
    {
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
380
      size_t maxbuffer=sinfo->buffpek.elements-1;
1 by brian
clean slate
381
      if (!mergebuf)
382
      {
383
        length=param->sort_buffer_length;
384
        while (length >= MIN_SORT_MEMORY)
385
        {
960.2.2 by Monty Taylor
Moved MyISAM files to C++ so we can continue to consolidate code.
386
          if ((mergebuf= (unsigned char *)malloc(length)))
1 by brian
clean slate
387
              break;
388
          length=length*3/4;
389
        }
390
        if (!mergebuf)
391
        {
392
          got_error=1;
393
          continue;
394
        }
395
      }
396
      keys=length/sinfo->key_length;
397
      if (maxbuffer >= MERGEBUFF2)
398
      {
399
        if (param->testflag & T_VERBOSE)
400
          printf("Key %d  - Merging %u keys\n",sinfo->key+1, sinfo->keys);
481 by Brian Aker
Remove all of uchar.
401
        if (merge_many_buff(sinfo, keys, (unsigned char **)mergebuf,
1 by brian
clean slate
402
			    dynamic_element(&sinfo->buffpek, 0, BUFFPEK *),
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
403
			    &maxbuffer, &sinfo->tempfile))
1 by brian
clean slate
404
        {
405
          got_error=1;
406
          continue;
407
        }
408
      }
409
      if (flush_io_cache(&sinfo->tempfile) ||
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
410
          reinit_io_cache(&sinfo->tempfile,internal::READ_CACHE,0L,0,0))
1 by brian
clean slate
411
      {
412
        got_error=1;
413
        continue;
414
      }
415
      if (param->testflag & T_VERBOSE)
416
        printf("Key %d  - Last merge and dumping keys\n", sinfo->key+1);
481 by Brian Aker
Remove all of uchar.
417
      if (merge_index(sinfo, keys, (unsigned char **)mergebuf,
1 by brian
clean slate
418
                      dynamic_element(&sinfo->buffpek,0,BUFFPEK *),
419
                      maxbuffer,&sinfo->tempfile) ||
420
	  flush_pending_blocks(sinfo))
421
      {
422
        got_error=1;
423
        continue;
424
      }
425
    }
426
    if (my_b_inited(&sinfo->tempfile_for_exceptions))
427
    {
482 by Brian Aker
Remove uint.
428
      uint32_t key_length;
1 by brian
clean slate
429
430
      if (param->testflag & T_VERBOSE)
431
        printf("Key %d  - Dumping 'long' keys\n", sinfo->key+1);
432
433
      if (flush_io_cache(&sinfo->tempfile_for_exceptions) ||
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
434
          reinit_io_cache(&sinfo->tempfile_for_exceptions,internal::READ_CACHE,0L,0,0))
1 by brian
clean slate
435
      {
436
        got_error=1;
437
        continue;
438
      }
439
440
      while (!got_error &&
481 by Brian Aker
Remove all of uchar.
441
	     !my_b_read(&sinfo->tempfile_for_exceptions,(unsigned char*)&key_length,
1 by brian
clean slate
442
			sizeof(key_length)))
443
      {
481 by Brian Aker
Remove all of uchar.
444
        unsigned char ft_buf[10];
1 by brian
clean slate
445
        if (key_length > sizeof(ft_buf) ||
481 by Brian Aker
Remove all of uchar.
446
            my_b_read(&sinfo->tempfile_for_exceptions, (unsigned char*)ft_buf,
1 by brian
clean slate
447
                      (uint)key_length) ||
481 by Brian Aker
Remove all of uchar.
448
            _mi_ck_write(info, sinfo->key, (unsigned char*)ft_buf,
1 by brian
clean slate
449
                         key_length - info->s->rec_reflength))
450
          got_error=1;
451
      }
452
    }
453
  }
481 by Brian Aker
Remove all of uchar.
454
  free((unsigned char*) mergebuf);
51.1.119 by Jay Pipes
DBUG symbol removal
455
  return(got_error);
1 by brian
clean slate
456
}
457
458
        /* Write all keys in memory to file for later merge */
459
1165.1.72 by Stewart Smith
make write_keys() static to myisam/sort.cc
460
static int  write_keys(MI_SORT_PARAM *info, register unsigned char **sort_keys,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
461
                             uint32_t count, BUFFPEK *buffpek, internal::IO_CACHE *tempfile)
1 by brian
clean slate
462
{
481 by Brian Aker
Remove all of uchar.
463
  unsigned char **end;
482 by Brian Aker
Remove uint.
464
  uint32_t sort_length=info->key_length;
1 by brian
clean slate
465
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
466
  internal::my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
1 by brian
clean slate
467
            info);
468
  if (!my_b_inited(tempfile) &&
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
469
      open_cached_file(tempfile, P_tmpdir, "ST",
1 by brian
clean slate
470
                       DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
971.6.11 by Eric Day
Removed purecov messages.
471
    return(1);
1 by brian
clean slate
472
473
  buffpek->file_pos=my_b_tell(tempfile);
474
  buffpek->count=count;
475
476
  for (end=sort_keys+count ; sort_keys != end ; sort_keys++)
477
  {
481 by Brian Aker
Remove all of uchar.
478
    if (my_b_write(tempfile,(unsigned char*) *sort_keys,(uint) sort_length))
971.6.11 by Eric Day
Removed purecov messages.
479
      return(1);
1 by brian
clean slate
480
  }
51.1.119 by Jay Pipes
DBUG symbol removal
481
  return(0);
1 by brian
clean slate
482
} /* write_keys */
483
484
960.3.1 by Monty Taylor
Fixed linkage issues on solaris.
485
inline int
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
486
my_var_write(MI_SORT_PARAM *info, internal::IO_CACHE *to_file, unsigned char *bufs)
1 by brian
clean slate
487
{
488
  int err;
481 by Brian Aker
Remove all of uchar.
489
  uint16_t len = _mi_keylength(info->keyinfo, (unsigned char*) bufs);
1 by brian
clean slate
490
491
  /* The following is safe as this is a local file */
481 by Brian Aker
Remove all of uchar.
492
  if ((err= my_b_write(to_file, (unsigned char*)&len, sizeof(len))))
1 by brian
clean slate
493
    return (err);
494
  if ((err= my_b_write(to_file,bufs, (uint) len)))
495
    return (err);
496
  return (0);
497
}
498
499
1165.1.73 by Stewart Smith
make write_keys_varlen() static to myisam/sort.cc
500
static int  write_keys_varlen(MI_SORT_PARAM *info,
481 by Brian Aker
Remove all of uchar.
501
				    register unsigned char **sort_keys,
482 by Brian Aker
Remove uint.
502
                                    uint32_t count, BUFFPEK *buffpek,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
503
				    internal::IO_CACHE *tempfile)
1 by brian
clean slate
504
{
481 by Brian Aker
Remove all of uchar.
505
  unsigned char **end;
1 by brian
clean slate
506
  int err;
507
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
508
  internal::my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
1 by brian
clean slate
509
            info);
510
  if (!my_b_inited(tempfile) &&
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
511
      open_cached_file(tempfile, P_tmpdir, "ST",
1 by brian
clean slate
512
                       DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
971.6.11 by Eric Day
Removed purecov messages.
513
    return(1);
1 by brian
clean slate
514
515
  buffpek->file_pos=my_b_tell(tempfile);
516
  buffpek->count=count;
517
  for (end=sort_keys+count ; sort_keys != end ; sort_keys++)
518
  {
481 by Brian Aker
Remove all of uchar.
519
    if ((err= my_var_write(info,tempfile, (unsigned char*) *sort_keys)))
51.1.119 by Jay Pipes
DBUG symbol removal
520
      return(err);
1 by brian
clean slate
521
  }
51.1.119 by Jay Pipes
DBUG symbol removal
522
  return(0);
1 by brian
clean slate
523
} /* write_keys_varlen */
524
525
1165.1.71 by Stewart Smith
make write_key() static to myisam/sort.cc
526
static int  write_key(MI_SORT_PARAM *info, unsigned char *key,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
527
			    internal::IO_CACHE *tempfile)
1 by brian
clean slate
528
{
482 by Brian Aker
Remove uint.
529
  uint32_t key_length=info->real_key_length;
1 by brian
clean slate
530
531
  if (!my_b_inited(tempfile) &&
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
532
      open_cached_file(tempfile, P_tmpdir, "ST",
1 by brian
clean slate
533
                       DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
51.1.119 by Jay Pipes
DBUG symbol removal
534
    return(1);
1 by brian
clean slate
535
481 by Brian Aker
Remove all of uchar.
536
  if (my_b_write(tempfile,(unsigned char*)&key_length,sizeof(key_length)) ||
537
      my_b_write(tempfile,(unsigned char*)key,(uint) key_length))
51.1.119 by Jay Pipes
DBUG symbol removal
538
    return(1);
539
  return(0);
1 by brian
clean slate
540
} /* write_key */
541
542
543
/* Write index */
544
1165.1.70 by Stewart Smith
make write_index() static to myisam/sort.cc
545
static int  write_index(MI_SORT_PARAM *info, register unsigned char **sort_keys,
482 by Brian Aker
Remove uint.
546
                              register uint32_t count)
1 by brian
clean slate
547
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
548
  internal::my_qsort2((unsigned char*) sort_keys,(size_t) count,sizeof(unsigned char*),
1 by brian
clean slate
549
           (qsort2_cmp) info->key_cmp,info);
550
  while (count--)
551
  {
552
    if ((*info->key_write)(info,*sort_keys++))
971.6.11 by Eric Day
Removed purecov messages.
553
      return(-1);
1 by brian
clean slate
554
  }
51.1.119 by Jay Pipes
DBUG symbol removal
555
  return(0);
1 by brian
clean slate
556
} /* write_index */
557
558
559
        /* Merge buffers to make < MERGEBUFF2 buffers */
560
1165.1.67 by Stewart Smith
make merge_many_buff() static to myisam/sort.cc
561
static int  merge_many_buff(MI_SORT_PARAM *info, uint32_t keys,
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
562
			    unsigned char **sort_keys, BUFFPEK *buffpek,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
563
			    size_t *maxbuffer, internal::IO_CACHE *t_file)
1 by brian
clean slate
564
{
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
565
  uint32_t i;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
566
  internal::IO_CACHE t_file2, *from_file, *to_file, *temp;
1 by brian
clean slate
567
  BUFFPEK *lastbuff;
568
569
  if (*maxbuffer < MERGEBUFF2)
971.6.11 by Eric Day
Removed purecov messages.
570
    return(0);
1 by brian
clean slate
571
  if (flush_io_cache(t_file) ||
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
572
      open_cached_file(&t_file2, P_tmpdir, "ST",
1 by brian
clean slate
573
                       DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
971.6.11 by Eric Day
Removed purecov messages.
574
    return(1);
1 by brian
clean slate
575
576
  from_file= t_file ; to_file= &t_file2;
577
  while (*maxbuffer >= MERGEBUFF2)
578
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
579
    reinit_io_cache(from_file,internal::READ_CACHE,0L,0,0);
580
    reinit_io_cache(to_file,internal::WRITE_CACHE,0L,0,0);
1 by brian
clean slate
581
    lastbuff=buffpek;
582
    for (i=0 ; i <= *maxbuffer-MERGEBUFF*3/2 ; i+=MERGEBUFF)
583
    {
584
      if (merge_buffers(info,keys,from_file,to_file,sort_keys,lastbuff++,
585
                        buffpek+i,buffpek+i+MERGEBUFF-1))
586
        goto cleanup;
587
    }
588
    if (merge_buffers(info,keys,from_file,to_file,sort_keys,lastbuff++,
589
                      buffpek+i,buffpek+ *maxbuffer))
971.6.11 by Eric Day
Removed purecov messages.
590
      break;
1 by brian
clean slate
591
    if (flush_io_cache(to_file))
971.6.11 by Eric Day
Removed purecov messages.
592
      break;
1 by brian
clean slate
593
    temp=from_file; from_file=to_file; to_file=temp;
594
    *maxbuffer= (int) (lastbuff-buffpek)-1;
595
  }
596
cleanup:
597
  close_cached_file(to_file);                   /* This holds old result */
598
  if (to_file == t_file)
599
    *t_file=t_file2;                            /* Copy result file */
600
51.1.119 by Jay Pipes
DBUG symbol removal
601
  return(*maxbuffer >= MERGEBUFF2);        /* Return 1 if interrupted */
1 by brian
clean slate
602
} /* merge_many_buff */
603
604
605
/*
606
   Read data to buffer
607
608
  SYNOPSIS
609
    read_to_buffer()
610
    fromfile		File to read from
611
    buffpek		Where to read from
612
    sort_length		max length to read
613
  RESULT
614
    > 0	Ammount of bytes read
615
    -1	Error
616
*/
617
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
618
static uint32_t  read_to_buffer(internal::IO_CACHE *fromfile, BUFFPEK *buffpek,
482 by Brian Aker
Remove uint.
619
                                  uint32_t sort_length)
1 by brian
clean slate
620
{
482 by Brian Aker
Remove uint.
621
  register uint32_t count;
622
  uint32_t length;
1 by brian
clean slate
623
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
624
  if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
1 by brian
clean slate
625
  {
481 by Brian Aker
Remove all of uchar.
626
    if (my_pread(fromfile->file,(unsigned char*) buffpek->base,
1 by brian
clean slate
627
                 (length= sort_length*count),buffpek->file_pos,MYF_RW))
971.6.11 by Eric Day
Removed purecov messages.
628
      return((uint) -1);
1 by brian
clean slate
629
    buffpek->key=buffpek->base;
630
    buffpek->file_pos+= length;                 /* New filepos */
631
    buffpek->count-=    count;
632
    buffpek->mem_count= count;
633
  }
634
  return (count*sort_length);
635
} /* read_to_buffer */
636
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
637
static uint32_t  read_to_buffer_varlen(internal::IO_CACHE *fromfile, BUFFPEK *buffpek,
482 by Brian Aker
Remove uint.
638
                                         uint32_t sort_length)
1 by brian
clean slate
639
{
482 by Brian Aker
Remove uint.
640
  register uint32_t count;
206 by Brian Aker
Removed final uint dead types.
641
  uint16_t length_of_key = 0;
482 by Brian Aker
Remove uint.
642
  uint32_t idx;
481 by Brian Aker
Remove all of uchar.
643
  unsigned char *buffp;
1 by brian
clean slate
644
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
645
  if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
1 by brian
clean slate
646
  {
647
    buffp = buffpek->base;
648
649
    for (idx=1;idx<=count;idx++)
650
    {
481 by Brian Aker
Remove all of uchar.
651
      if (my_pread(fromfile->file,(unsigned char*)&length_of_key,sizeof(length_of_key),
1 by brian
clean slate
652
                   buffpek->file_pos,MYF_RW))
653
        return((uint) -1);
654
      buffpek->file_pos+=sizeof(length_of_key);
481 by Brian Aker
Remove all of uchar.
655
      if (my_pread(fromfile->file,(unsigned char*) buffp,length_of_key,
1 by brian
clean slate
656
                   buffpek->file_pos,MYF_RW))
657
        return((uint) -1);
658
      buffpek->file_pos+=length_of_key;
659
      buffp = buffp + sort_length;
660
    }
661
    buffpek->key=buffpek->base;
662
    buffpek->count-=    count;
663
    buffpek->mem_count= count;
664
  }
665
  return (count*sort_length);
666
} /* read_to_buffer_varlen */
667
668
1165.1.75 by Stewart Smith
make write_merge_key_varlen() static to myisam/sort.cc
669
static int  write_merge_key_varlen(MI_SORT_PARAM *info,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
670
					 internal::IO_CACHE *to_file, unsigned char* key,
482 by Brian Aker
Remove uint.
671
                                         uint32_t sort_length, uint32_t count)
1 by brian
clean slate
672
{
482 by Brian Aker
Remove uint.
673
  uint32_t idx;
481 by Brian Aker
Remove all of uchar.
674
  unsigned char *bufs = key;
1 by brian
clean slate
675
676
  for (idx=1;idx<=count;idx++)
677
  {
678
    int err;
679
    if ((err= my_var_write(info, to_file, bufs)))
680
      return (err);
681
    bufs=bufs+sort_length;
682
  }
683
  return(0);
684
}
685
686
1165.1.74 by Stewart Smith
make write_merge_key() static to myisam/sort.cc
687
static int  write_merge_key(MI_SORT_PARAM *info,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
688
				  internal::IO_CACHE *to_file, unsigned char *key,
482 by Brian Aker
Remove uint.
689
				  uint32_t sort_length, uint32_t count)
1 by brian
clean slate
690
{
779.3.1 by Monty Taylor
More cleanup.
691
  (void)info;
1 by brian
clean slate
692
  return my_b_write(to_file, key, (size_t) sort_length*count);
693
}
694
960.2.16 by Padraig O'Sullivan
Adding comments to the function object that is used as the comparison
695
/*
696
 * Function object to be used as the comparison function
697
 * for the priority queue in the merge_buffers method.
698
 */
960.2.8 by Padraig O'Sullivan
Adding a function object to be used as the comparison parameter for the
699
class compare_functor
700
{
960.2.12 by Padraig O'Sullivan
Making the class members of my function object have the correct type.
701
  qsort2_cmp key_compare;
960.2.8 by Padraig O'Sullivan
Adding a function object to be used as the comparison parameter for the
702
  void *key_compare_arg;
703
  public:
960.2.12 by Padraig O'Sullivan
Making the class members of my function object have the correct type.
704
  compare_functor(qsort2_cmp in_key_compare, void *in_compare_arg)
960.2.8 by Padraig O'Sullivan
Adding a function object to be used as the comparison parameter for the
705
    : key_compare(in_key_compare), key_compare_arg(in_compare_arg) { }
706
  inline bool operator()(const BUFFPEK *i, const BUFFPEK *j) const
707
  {
708
    int val= key_compare(key_compare_arg,
709
                      &i->key, &j->key);
710
    return (val >= 0);
711
  }
712
};
713
1 by brian
clean slate
714
/*
715
  Merge buffers to one buffer
716
  If to_file == 0 then use info->key_write
717
*/
718
1165.1.65 by Stewart Smith
make merge_buffers() static to myisam/sort.cc
719
static int
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
720
merge_buffers(MI_SORT_PARAM *info, uint32_t keys, internal::IO_CACHE *from_file,
721
              internal::IO_CACHE *to_file, unsigned char **sort_keys, BUFFPEK *lastbuff,
1 by brian
clean slate
722
              BUFFPEK *Fb, BUFFPEK *Tb)
723
{
724
  int error;
482 by Brian Aker
Remove uint.
725
  uint32_t sort_length,maxcount;
1 by brian
clean slate
726
  ha_rows count;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
727
  internal::my_off_t to_start_filepos= 0;
481 by Brian Aker
Remove all of uchar.
728
  unsigned char *strpos;
960.2.11 by Padraig O'Sullivan
Removing unused variables.
729
  BUFFPEK *buffpek;
960.2.8 by Padraig O'Sullivan
Adding a function object to be used as the comparison parameter for the
730
  priority_queue<BUFFPEK *, vector<BUFFPEK *>, compare_functor > 
960.2.16 by Padraig O'Sullivan
Adding comments to the function object that is used as the comparison
731
    queue(compare_functor((qsort2_cmp) info->key_cmp, static_cast<void *>(info)));
1 by brian
clean slate
732
  volatile int *killed= killed_ptr(info->sort_info->param);
733
734
  count=error=0;
735
  maxcount=keys/((uint) (Tb-Fb) +1);
51.1.119 by Jay Pipes
DBUG symbol removal
736
  assert(maxcount > 0);
1 by brian
clean slate
737
  if (to_file)
738
    to_start_filepos=my_b_tell(to_file);
481 by Brian Aker
Remove all of uchar.
739
  strpos=(unsigned char*) sort_keys;
1 by brian
clean slate
740
  sort_length=info->key_length;
741
742
  for (buffpek= Fb ; buffpek <= Tb ; buffpek++)
743
  {
744
    count+= buffpek->count;
745
    buffpek->base= strpos;
746
    buffpek->max_keys=maxcount;
747
    strpos+= (uint) (error=(int) info->read_to_buffer(from_file,buffpek,
748
                                                      sort_length));
749
    if (error == -1)
971.6.11 by Eric Day
Removed purecov messages.
750
      goto err;
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
751
    queue.push(buffpek);
1 by brian
clean slate
752
  }
753
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
754
  while (queue.size() > 1)
1 by brian
clean slate
755
  {
756
    for (;;)
757
    {
758
      if (*killed)
759
      {
760
        error=1; goto err;
761
      }
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
762
      buffpek= queue.top();
1 by brian
clean slate
763
      if (to_file)
764
      {
481 by Brian Aker
Remove all of uchar.
765
        if (info->write_key(info,to_file,(unsigned char*) buffpek->key,
1 by brian
clean slate
766
                            (uint) sort_length,1))
767
        {
971.6.11 by Eric Day
Removed purecov messages.
768
          error=1; goto err;
1 by brian
clean slate
769
        }
770
      }
771
      else
772
      {
773
        if ((*info->key_write)(info,(void*) buffpek->key))
774
        {
971.6.11 by Eric Day
Removed purecov messages.
775
          error=1; goto err;
1 by brian
clean slate
776
        }
777
      }
778
      buffpek->key+=sort_length;
779
      if (! --buffpek->mem_count)
780
      {
781
        if (!(error=(int) info->read_to_buffer(from_file,buffpek,sort_length)))
782
        {
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
783
          queue.pop();
1 by brian
clean slate
784
          break;                /* One buffer have been removed */
785
        }
786
      }
787
      else if (error == -1)
971.6.11 by Eric Day
Removed purecov messages.
788
        goto err;
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
789
      /* Top element has been replaced */
790
      queue.pop();
791
      queue.push(buffpek);
1 by brian
clean slate
792
    }
793
  }
960.2.7 by Padraig O'Sullivan
Removed all traces of QUEUE from the codebase. We are using
794
  buffpek= queue.top();
481 by Brian Aker
Remove all of uchar.
795
  buffpek->base=(unsigned char *) sort_keys;
1 by brian
clean slate
796
  buffpek->max_keys=keys;
797
  do
798
  {
799
    if (to_file)
800
    {
481 by Brian Aker
Remove all of uchar.
801
      if (info->write_key(info,to_file,(unsigned char*) buffpek->key,
1 by brian
clean slate
802
                         sort_length,buffpek->mem_count))
803
      {
971.6.11 by Eric Day
Removed purecov messages.
804
        error=1; goto err;
1 by brian
clean slate
805
      }
806
    }
807
    else
808
    {
481 by Brian Aker
Remove all of uchar.
809
      register unsigned char *end;
1 by brian
clean slate
810
      strpos= buffpek->key;
811
      for (end=strpos+buffpek->mem_count*sort_length;
812
           strpos != end ;
813
           strpos+=sort_length)
814
      {
815
        if ((*info->key_write)(info,(void*) strpos))
816
        {
971.6.11 by Eric Day
Removed purecov messages.
817
          error=1; goto err;
1 by brian
clean slate
818
        }
819
      }
820
    }
821
  }
822
  while ((error=(int) info->read_to_buffer(from_file,buffpek,sort_length)) != -1 &&
823
         error != 0);
824
825
  lastbuff->count=count;
826
  if (to_file)
827
    lastbuff->file_pos=to_start_filepos;
828
err:
51.1.119 by Jay Pipes
DBUG symbol removal
829
  return(error);
1 by brian
clean slate
830
} /* merge_buffers */
831
832
833
        /* Do a merge to output-file (save only positions) */
834
1165.1.66 by Stewart Smith
make merge_index() static to myisam/sort.cc
835
static int
482 by Brian Aker
Remove uint.
836
merge_index(MI_SORT_PARAM *info, uint32_t keys, unsigned char **sort_keys,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
837
            BUFFPEK *buffpek, int maxbuffer, internal::IO_CACHE *tempfile)
1 by brian
clean slate
838
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
839
  if (merge_buffers(info,keys,tempfile,(internal::IO_CACHE*) 0,sort_keys,buffpek,buffpek,
1 by brian
clean slate
840
                    buffpek+maxbuffer))
971.6.11 by Eric Day
Removed purecov messages.
841
    return(1);
51.1.119 by Jay Pipes
DBUG symbol removal
842
  return(0);
1 by brian
clean slate
843
} /* merge_index */
844