~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/filesort.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  Sorts a database
22
22
*/
23
23
 
24
 
#include "config.h"
25
 
 
26
 
#include <float.h>
27
 
#include <limits.h>
 
24
#include <drizzled/server_includes.h>
 
25
#include <drizzled/sql_sort.h>
 
26
#include <drizzled/error.h>
 
27
#include <drizzled/probes.h>
 
28
#include <drizzled/session.h>
 
29
#include <drizzled/table.h>
 
30
#include <drizzled/table_list.h>
28
31
 
29
32
#include <queue>
30
33
#include <algorithm>
31
34
 
32
 
#include "drizzled/sql_sort.h"
33
 
#include "drizzled/error.h"
34
 
#include "drizzled/probes.h"
35
 
#include "drizzled/session.h"
36
 
#include "drizzled/table.h"
37
 
#include "drizzled/table_list.h"
38
 
#include "drizzled/optimizer/range.h"
39
 
#include "drizzled/records.h"
40
 
#include "drizzled/internal/iocache.h"
41
 
#include "drizzled/internal/my_sys.h"
42
 
#include "plugin/myisam/myisam.h"
43
 
#include "drizzled/plugin/transactional_storage_engine.h"
44
 
 
45
35
using namespace std;
46
36
 
47
 
namespace drizzled
48
 
{
49
 
 
50
37
/* functions defined in this file */
51
38
 
52
39
static char **make_char_array(char **old_pos, register uint32_t fields,
53
40
                              uint32_t length);
54
 
 
55
 
static unsigned char *read_buffpek_from_file(internal::IO_CACHE *buffer_file,
56
 
                                             uint32_t count,
57
 
                                             unsigned char *buf);
58
 
 
59
 
static ha_rows find_all_keys(SORTPARAM *param,
60
 
                             optimizer::SqlSelect *select,
61
 
                             unsigned char * *sort_keys, 
62
 
                             internal::IO_CACHE *buffer_file,
63
 
                             internal::IO_CACHE *tempfile,
64
 
                             internal::IO_CACHE *indexfile);
65
 
 
66
 
static int write_keys(SORTPARAM *param,
67
 
                      unsigned char * *sort_keys,
68
 
                      uint32_t count,
69
 
                      internal::IO_CACHE *buffer_file,
70
 
                      internal::IO_CACHE *tempfile);
71
 
 
72
 
static void make_sortkey(SORTPARAM *param,
73
 
                         unsigned char *to,
74
 
                         unsigned char *ref_pos);
 
41
static unsigned char *read_buffpek_from_file(IO_CACHE *buffer_file, uint32_t count,
 
42
                                     unsigned char *buf);
 
43
static ha_rows find_all_keys(SORTPARAM *param,SQL_SELECT *select,
 
44
                             unsigned char * *sort_keys, IO_CACHE *buffer_file,
 
45
                             IO_CACHE *tempfile,IO_CACHE *indexfile);
 
46
static int write_keys(SORTPARAM *param,unsigned char * *sort_keys,
 
47
                      uint32_t count, IO_CACHE *buffer_file, IO_CACHE *tempfile);
 
48
static void make_sortkey(SORTPARAM *param,unsigned char *to, unsigned char *ref_pos);
75
49
static void register_used_fields(SORTPARAM *param);
76
 
static int merge_index(SORTPARAM *param,
77
 
                       unsigned char *sort_buffer,
 
50
static int merge_index(SORTPARAM *param,unsigned char *sort_buffer,
78
51
                       BUFFPEK *buffpek,
79
 
                       uint32_t maxbuffer,
80
 
                       internal::IO_CACHE *tempfile,
81
 
                       internal::IO_CACHE *outfile);
82
 
static bool save_index(SORTPARAM *param,
83
 
                       unsigned char **sort_keys,
84
 
                       uint32_t count,
 
52
                       uint32_t maxbuffer,IO_CACHE *tempfile,
 
53
                       IO_CACHE *outfile);
 
54
static bool save_index(SORTPARAM *param,unsigned char **sort_keys, uint32_t count,
85
55
                       filesort_info_st *table_sort);
86
56
static uint32_t suffix_length(uint32_t string_length);
87
 
static uint32_t sortlength(Session *session,
88
 
                           SORT_FIELD *sortorder,
89
 
                           uint32_t s_length,
90
 
                           bool *multi_byte_charset);
91
 
static SORT_ADDON_FIELD *get_addon_fields(Session *session,
92
 
                                          Field **ptabfield,
93
 
                                          uint32_t sortlength,
94
 
                                          uint32_t *plength);
 
57
static uint32_t sortlength(Session *session, SORT_FIELD *sortorder, uint32_t s_length,
 
58
                       bool *multi_byte_charset);
 
59
static SORT_ADDON_FIELD *get_addon_fields(Session *session, Field **ptabfield,
 
60
                                          uint32_t sortlength, uint32_t *plength);
95
61
static void unpack_addon_fields(struct st_sort_addon_field *addon_field,
96
62
                                unsigned char *buff);
97
63
/**
131
97
*/
132
98
 
133
99
ha_rows filesort(Session *session, Table *table, SORT_FIELD *sortorder, uint32_t s_length,
134
 
                 optimizer::SqlSelect *select, ha_rows max_rows,
 
100
                 SQL_SELECT *select, ha_rows max_rows,
135
101
                 bool sort_positions, ha_rows *examined_rows)
136
102
{
137
103
  int error;
140
106
  BUFFPEK *buffpek;
141
107
  ha_rows records= HA_POS_ERROR;
142
108
  unsigned char **sort_keys= 0;
143
 
  internal::IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile;
 
109
  IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile;
144
110
  SORTPARAM param;
145
111
  bool multi_byte_charset;
146
112
 
148
114
  TableList *tab= table->pos_in_table_list;
149
115
  Item_subselect *subselect= tab ? tab->containing_subselect() : 0;
150
116
 
151
 
  DRIZZLE_FILESORT_START(table->s->getSchemaName(), table->s->getTableName());
 
117
  DRIZZLE_FILESORT_START();
152
118
 
153
119
  /*
154
120
   Release InnoDB's adaptive hash index latch (if holding) before
155
121
   running a sort.
156
122
  */
157
 
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
 
123
  ha_release_temporary_latches(session);
158
124
 
159
125
  /*
160
126
    Don't use table->sort in filesort as it is also used by
161
 
    QuickIndexMergeSelect. Work with a copy and put it back at the end
 
127
    QUICK_INDEX_MERGE_SELECT. Work with a copy and put it back at the end
162
128
    when index_merge select has finished with it.
163
129
  */
164
130
  memcpy(&table_sort, &table->sort, sizeof(filesort_info_st));
171
137
  error= 1;
172
138
  memset(&param, 0, sizeof(param));
173
139
  param.sort_length= sortlength(session, sortorder, s_length, &multi_byte_charset);
174
 
  param.ref_length= table->cursor->ref_length;
 
140
  param.ref_length= table->file->ref_length;
175
141
  param.addon_field= 0;
176
142
  param.addon_length= 0;
177
 
  if (!(table->cursor->getEngine()->check_flag(HTON_BIT_FAST_KEY_READ)) && !sort_positions)
 
143
  if (!(table->file->ha_table_flags() & HA_FAST_KEY_READ) && !sort_positions)
178
144
  {
179
145
    /*
180
146
      Get the descriptors of all fields whose values are appended
219
185
  if (select && select->quick && select->quick->records > 0L)
220
186
  {
221
187
    records= min((ha_rows) (select->quick->records*2+EXTRA_RECORDS*2),
222
 
                 table->cursor->stats.records)+EXTRA_RECORDS;
 
188
                 table->file->stats.records)+EXTRA_RECORDS;
223
189
    selected_records_file=0;
224
190
  }
225
191
  else
226
192
#endif
227
193
  {
228
 
    records= table->cursor->estimate_rows_upper_bound();
 
194
    records= table->file->estimate_rows_upper_bound();
229
195
    /*
230
196
      If number of records is not known, use as much of sort buffer
231
197
      as possible.
298
264
        open_cached_file(outfile,drizzle_tmpdir,TEMP_PREFIX,READ_RECORD_BUFFER,
299
265
                          MYF(MY_WME)))
300
266
      goto err;
301
 
    if (reinit_io_cache(outfile,internal::WRITE_CACHE,0L,0,0))
 
267
    if (reinit_io_cache(outfile,WRITE_CACHE,0L,0,0))
302
268
      goto err;
303
269
 
304
270
    /*
312
278
                        &tempfile))
313
279
      goto err;
314
280
    if (flush_io_cache(&tempfile) ||
315
 
        reinit_io_cache(&tempfile,internal::READ_CACHE,0L,0,0))
 
281
        reinit_io_cache(&tempfile,READ_CACHE,0L,0,0))
316
282
      goto err;
317
283
    if (merge_index(&param,(unsigned char*) sort_keys,buffpek,maxbuffer,&tempfile,
318
284
                    outfile))
343
309
    if (flush_io_cache(outfile))
344
310
      error=1;
345
311
    {
346
 
      internal::my_off_t save_pos=outfile->pos_in_file;
 
312
      my_off_t save_pos=outfile->pos_in_file;
347
313
      /* For following reads */
348
 
      if (reinit_io_cache(outfile,internal::READ_CACHE,0L,0,0))
 
314
      if (reinit_io_cache(outfile,READ_CACHE,0L,0,0))
349
315
        error=1;
350
316
      outfile->end_of_file=save_pos;
351
317
    }
358
324
                  (uint32_t) records, &LOCK_status);
359
325
  *examined_rows= param.examined_rows;
360
326
  memcpy(&table->sort, &table_sort, sizeof(filesort_info_st));
361
 
  DRIZZLE_FILESORT_DONE(error, records);
362
 
  return (error ? HA_POS_ERROR : records);
 
327
  DRIZZLE_FILESORT_END();
 
328
  return(error ? HA_POS_ERROR : records);
363
329
} /* filesort */
364
330
 
365
331
 
416
382
 
417
383
/** Read 'count' number of buffer pointers into memory. */
418
384
 
419
 
static unsigned char *read_buffpek_from_file(internal::IO_CACHE *buffpek_pointers, uint32_t count,
 
385
static unsigned char *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint32_t count,
420
386
                                     unsigned char *buf)
421
387
{
422
388
  uint32_t length= sizeof(BUFFPEK)*count;
427
393
    tmp= (unsigned char *)malloc(length);
428
394
  if (tmp)
429
395
  {
430
 
    if (reinit_io_cache(buffpek_pointers,internal::READ_CACHE,0L,0,0) ||
 
396
    if (reinit_io_cache(buffpek_pointers,READ_CACHE,0L,0,0) ||
431
397
        my_b_read(buffpek_pointers, (unsigned char*) tmp, length))
432
398
    {
433
399
      free((char*) tmp);
475
441
    HA_POS_ERROR on error.
476
442
*/
477
443
 
478
 
static ha_rows find_all_keys(SORTPARAM *param, 
479
 
                             optimizer::SqlSelect *select,
 
444
static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
480
445
                             unsigned char **sort_keys,
481
 
                             internal::IO_CACHE *buffpek_pointers,
482
 
                             internal::IO_CACHE *tempfile, internal::IO_CACHE *indexfile)
 
446
                             IO_CACHE *buffpek_pointers,
 
447
                             IO_CACHE *tempfile, IO_CACHE *indexfile)
483
448
{
484
449
  int error,flag,quick_select;
485
450
  uint32_t idx,indexpos,ref_length;
486
451
  unsigned char *ref_pos,*next_pos,ref_buff[MAX_REFLENGTH];
487
 
  internal::my_off_t record;
 
452
  my_off_t record;
488
453
  Table *sort_form;
489
454
  Session *session= current_session;
490
455
  volatile Session::killed_state *killed= &session->killed;
491
 
  Cursor *file;
 
456
  handler *file;
492
457
  MyBitmap *save_read_set, *save_write_set;
493
458
 
494
459
  idx=indexpos=0;
495
460
  error=quick_select=0;
496
461
  sort_form=param->sort_form;
497
 
  file= sort_form->cursor;
 
462
  file=sort_form->file;
498
463
  ref_length=param->ref_length;
499
464
  ref_pos= ref_buff;
500
465
  quick_select=select && select->quick;
501
466
  record=0;
502
 
  flag= ((!indexfile && ! file->isOrdered())
 
467
  flag= ((!indexfile && file->ha_table_flags() & HA_REC_NOT_IN_SEQ)
503
468
         || quick_select);
504
469
  if (indexfile || flag)
505
470
    ref_pos= &file->ref[0];
549
514
    {
550
515
      if (indexfile)
551
516
      {
552
 
        if (my_b_read(indexfile,(unsigned char*) ref_pos,ref_length))
 
517
        if (my_b_read(indexfile,(unsigned char*) ref_pos,ref_length)) /* purecov: deadcode */
553
518
        {
554
 
          error= errno ? errno : -1;            /* Abort */
 
519
          error= my_errno ? my_errno : -1;              /* Abort */
555
520
          break;
556
521
        }
557
522
        error=file->rnd_pos(sort_form->record[0],next_pos);
562
527
 
563
528
        if (!flag)
564
529
        {
565
 
          internal::my_store_ptr(ref_pos,ref_length,record); // Position to row
 
530
          my_store_ptr(ref_pos,ref_length,record); // Position to row
566
531
          record+= sort_form->s->db_record_offset;
567
532
        }
568
533
        else if (!error)
579
544
        (void) file->extra(HA_EXTRA_NO_CACHE);
580
545
        file->ha_rnd_end();
581
546
      }
582
 
      return(HA_POS_ERROR);
 
547
      return(HA_POS_ERROR);             /* purecov: inspected */
583
548
    }
584
549
    if (error == 0)
585
550
      param->examined_rows++;
623
588
 
624
589
  if (error != HA_ERR_END_OF_FILE)
625
590
  {
626
 
    sort_form->print_error(error,MYF(ME_ERROR | ME_WAITTANG));
627
 
    return(HA_POS_ERROR);
 
591
    file->print_error(error,MYF(ME_ERROR | ME_WAITTANG)); /* purecov: inspected */
 
592
    return(HA_POS_ERROR);                       /* purecov: inspected */
628
593
  }
629
594
  if (indexpos && idx &&
630
595
      write_keys(param,sort_keys,idx,buffpek_pointers,tempfile))
631
 
    return(HA_POS_ERROR);
 
596
    return(HA_POS_ERROR);                       /* purecov: inspected */
632
597
  return(my_b_inited(tempfile) ?
633
598
              (ha_rows) (my_b_tell(tempfile)/param->rec_length) :
634
599
              idx);
659
624
 
660
625
static int
661
626
write_keys(SORTPARAM *param, register unsigned char **sort_keys, uint32_t count,
662
 
           internal::IO_CACHE *buffpek_pointers, internal::IO_CACHE *tempfile)
 
627
           IO_CACHE *buffpek_pointers, IO_CACHE *tempfile)
663
628
{
664
629
  size_t sort_length, rec_length;
665
630
  unsigned char **end;
667
632
 
668
633
  sort_length= param->sort_length;
669
634
  rec_length= param->rec_length;
670
 
  internal::my_string_ptr_sort((unsigned char*) sort_keys, (uint32_t) count, sort_length);
 
635
  my_string_ptr_sort((unsigned char*) sort_keys, (uint32_t) count, sort_length);
671
636
  if (!my_b_inited(tempfile) &&
672
637
      open_cached_file(tempfile, drizzle_tmpdir, TEMP_PREFIX, DISK_BUFFER_SIZE,
673
638
                       MYF(MY_WME)))
674
 
    goto err;
 
639
    goto err;                                   /* purecov: inspected */
675
640
  /* check we won't have more buffpeks than we can possibly keep in memory */
676
641
  if (my_b_tell(buffpek_pointers) + sizeof(BUFFPEK) > (uint64_t)UINT_MAX)
677
642
    goto err;
678
643
  buffpek.file_pos= my_b_tell(tempfile);
679
644
  if ((ha_rows) count > param->max_rows)
680
 
    count=(uint32_t) param->max_rows;
 
645
    count=(uint32_t) param->max_rows;               /* purecov: inspected */
681
646
  buffpek.count=(ha_rows) count;
682
647
  for (end=sort_keys+count ; sort_keys != end ; sort_keys++)
683
648
    if (my_b_write(tempfile, (unsigned char*) *sort_keys, (uint32_t) rec_length))
769
734
            memset(to-1, 0, sort_field->length+1);
770
735
          else
771
736
          {
 
737
            /* purecov: begin deadcode */
772
738
            /*
773
739
              This should only happen during extreme conditions if we run out
774
740
              of memory or have an item marked not null when it can be null.
776
742
            */
777
743
            assert(0);
778
744
            memset(to, 0, sort_field->length);  // Avoid crash
 
745
            /* purecov: end */
779
746
          }
780
747
          break;
781
748
        }
819
786
          int64_t value= item->val_int_result();
820
787
          if (maybe_null)
821
788
          {
822
 
            *to++=1;
 
789
            *to++=1;                            /* purecov: inspected */
823
790
            if (item->null_value)
824
791
            {
825
792
              if (maybe_null)
993
960
  uint32_t offset,res_length;
994
961
  unsigned char *to;
995
962
 
996
 
  internal::my_string_ptr_sort((unsigned char*) sort_keys, (uint32_t) count, param->sort_length);
 
963
  my_string_ptr_sort((unsigned char*) sort_keys, (uint32_t) count, param->sort_length);
997
964
  res_length= param->res_length;
998
965
  offset= param->rec_length-res_length;
999
966
  if ((ha_rows) count > param->max_rows)
1000
967
    count=(uint32_t) param->max_rows;
1001
968
  if (!(to= table_sort->record_pointers=
1002
969
        (unsigned char*) malloc(res_length*count)))
1003
 
    return(1);
 
970
    return(1);                 /* purecov: inspected */
1004
971
  for (unsigned char **end= sort_keys+count ; sort_keys != end ; sort_keys++)
1005
972
  {
1006
973
    memcpy(to, *sort_keys+offset, res_length);
1013
980
/** Merge buffers to make < MERGEBUFF2 buffers. */
1014
981
 
1015
982
int merge_many_buff(SORTPARAM *param, unsigned char *sort_buffer,
1016
 
                    BUFFPEK *buffpek, uint32_t *maxbuffer, internal::IO_CACHE *t_file)
 
983
                    BUFFPEK *buffpek, uint32_t *maxbuffer, IO_CACHE *t_file)
1017
984
{
1018
985
  register uint32_t i;
1019
 
  internal::IO_CACHE t_file2,*from_file,*to_file,*temp;
 
986
  IO_CACHE t_file2,*from_file,*to_file,*temp;
1020
987
  BUFFPEK *lastbuff;
1021
988
 
1022
989
  if (*maxbuffer < MERGEBUFF2)
1023
 
    return(0);
 
990
    return(0);                          /* purecov: inspected */
1024
991
  if (flush_io_cache(t_file) ||
1025
992
      open_cached_file(&t_file2,drizzle_tmpdir,TEMP_PREFIX,DISK_BUFFER_SIZE,
1026
993
                        MYF(MY_WME)))
1027
 
    return(1);
 
994
    return(1);                          /* purecov: inspected */
1028
995
 
1029
996
  from_file= t_file ; to_file= &t_file2;
1030
997
  while (*maxbuffer >= MERGEBUFF2)
1031
998
  {
1032
 
    if (reinit_io_cache(from_file,internal::READ_CACHE,0L,0,0))
 
999
    if (reinit_io_cache(from_file,READ_CACHE,0L,0,0))
1033
1000
      goto cleanup;
1034
 
    if (reinit_io_cache(to_file,internal::WRITE_CACHE,0L,0,0))
 
1001
    if (reinit_io_cache(to_file,WRITE_CACHE,0L,0,0))
1035
1002
      goto cleanup;
1036
1003
    lastbuff=buffpek;
1037
1004
    for (i=0 ; i <= *maxbuffer-MERGEBUFF*3/2 ; i+=MERGEBUFF)
1042
1009
    }
1043
1010
    if (merge_buffers(param,from_file,to_file,sort_buffer,lastbuff++,
1044
1011
                      buffpek+i,buffpek+ *maxbuffer,0))
1045
 
      break;
 
1012
      break;                                    /* purecov: inspected */
1046
1013
    if (flush_io_cache(to_file))
1047
 
      break;
 
1014
      break;                                    /* purecov: inspected */
1048
1015
    temp=from_file; from_file=to_file; to_file=temp;
1049
1016
    setup_io_cache(from_file);
1050
1017
    setup_io_cache(to_file);
1069
1036
    (uint32_t)-1 if something goes wrong
1070
1037
*/
1071
1038
 
1072
 
uint32_t read_to_buffer(internal::IO_CACHE *fromfile, BUFFPEK *buffpek,
 
1039
uint32_t read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
1073
1040
                        uint32_t rec_length)
1074
1041
{
1075
1042
  register uint32_t count;
1078
1045
  if ((count= (uint32_t) min((ha_rows) buffpek->max_keys,buffpek->count)))
1079
1046
  {
1080
1047
    if (pread(fromfile->file,(unsigned char*) buffpek->base, (length= rec_length*count),buffpek->file_pos) == 0)
1081
 
      return((uint32_t) -1);
 
1048
      return((uint32_t) -1);                    /* purecov: inspected */
1082
1049
 
1083
1050
    buffpek->key= buffpek->base;
1084
1051
    buffpek->file_pos+= length;                 /* New filepos */
1123
1090
    other  error
1124
1091
*/
1125
1092
 
1126
 
int merge_buffers(SORTPARAM *param, internal::IO_CACHE *from_file,
1127
 
                  internal::IO_CACHE *to_file, unsigned char *sort_buffer,
 
1093
int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
 
1094
                  IO_CACHE *to_file, unsigned char *sort_buffer,
1128
1095
                  BUFFPEK *lastbuff, BUFFPEK *Fb, BUFFPEK *Tb,
1129
1096
                  int flag)
1130
1097
{
1133
1100
  size_t sort_length;
1134
1101
  uint32_t maxcount;
1135
1102
  ha_rows max_rows,org_max_rows;
1136
 
  internal::my_off_t to_start_filepos;
 
1103
  my_off_t to_start_filepos;
1137
1104
  unsigned char *strpos;
1138
1105
  BUFFPEK *buffpek;
1139
1106
  qsort2_cmp cmp;
1168
1135
  }
1169
1136
  else
1170
1137
  {
1171
 
    cmp= internal::get_ptr_compare(sort_length);
 
1138
    cmp= get_ptr_compare(sort_length);
1172
1139
    first_cmp_arg= (void*) &sort_length;
1173
1140
  }
1174
1141
  priority_queue<BUFFPEK *, vector<BUFFPEK *>, compare_functor > 
1180
1147
    strpos+= (uint32_t) (error= (int) read_to_buffer(from_file, buffpek,
1181
1148
                                                                         rec_length));
1182
1149
    if (error == -1)
1183
 
      goto err;
 
1150
      goto err;                                 /* purecov: inspected */
1184
1151
    buffpek->max_keys= buffpek->mem_count;      // If less data in buffers than expected
1185
1152
    queue.push(buffpek);
1186
1153
  }
1199
1166
    memcpy(param->unique_buff, buffpek->key, rec_length);
1200
1167
    if (my_b_write(to_file, (unsigned char*) buffpek->key, rec_length))
1201
1168
    {
1202
 
      error=1; goto err;
 
1169
      error=1; goto err;                        /* purecov: inspected */
1203
1170
    }
1204
1171
    buffpek->key+= rec_length;
1205
1172
    buffpek->mem_count--;
1206
1173
    if (!--max_rows)
1207
1174
    {
1208
 
      error= 0;
1209
 
      goto end;
 
1175
      error= 0;                                       /* purecov: inspected */
 
1176
      goto end;                                       /* purecov: inspected */
1210
1177
    }
1211
1178
    /* Top element has been used */
1212
1179
    queue.pop();
1219
1186
  {
1220
1187
    if (*killed)
1221
1188
    {
1222
 
      error= 1; goto err;
 
1189
      error= 1; goto err;                        /* purecov: inspected */
1223
1190
    }
1224
1191
    for (;;)
1225
1192
    {
1235
1202
      {
1236
1203
        if (my_b_write(to_file,(unsigned char*) buffpek->key, rec_length))
1237
1204
        {
1238
 
          error=1; goto err;
 
1205
          error=1; goto err;                        /* purecov: inspected */
1239
1206
        }
1240
1207
      }
1241
1208
      else
1242
1209
      {
1243
1210
        if (my_b_write(to_file, (unsigned char*) buffpek->key+offset, res_length))
1244
1211
        {
1245
 
          error=1; goto err;
 
1212
          error=1; goto err;                        /* purecov: inspected */
1246
1213
        }
1247
1214
      }
1248
1215
      if (!--max_rows)
1249
1216
      {
1250
 
        error= 0;
1251
 
        goto end;
 
1217
        error= 0;                               /* purecov: inspected */
 
1218
        goto end;                               /* purecov: inspected */
1252
1219
      }
1253
1220
 
1254
1221
    skip_duplicate:
1262
1229
          break;                        /* One buffer have been removed */
1263
1230
        }
1264
1231
        else if (error == -1)
1265
 
          goto err;
 
1232
          goto err;                        /* purecov: inspected */
1266
1233
      }
1267
1234
      /* Top element has been replaced */
1268
1235
      queue.pop();
1299
1266
      if (my_b_write(to_file,(unsigned char*) buffpek->key,
1300
1267
                     (rec_length*buffpek->mem_count)))
1301
1268
      {
1302
 
        error= 1; goto err;
 
1269
        error= 1; goto err;                        /* purecov: inspected */
1303
1270
      }
1304
1271
    }
1305
1272
    else
1332
1299
 
1333
1300
static int merge_index(SORTPARAM *param, unsigned char *sort_buffer,
1334
1301
                       BUFFPEK *buffpek, uint32_t maxbuffer,
1335
 
                       internal::IO_CACHE *tempfile, internal::IO_CACHE *outfile)
 
1302
                       IO_CACHE *tempfile, IO_CACHE *outfile)
1336
1303
{
1337
1304
  if (merge_buffers(param,tempfile,outfile,sort_buffer,buffpek,buffpek,
1338
1305
                    buffpek+maxbuffer,1))
1339
 
    return(1);
 
1306
    return(1);                          /* purecov: inspected */
1340
1307
  return(0);
1341
1308
} /* merge_index */
1342
1309
 
1357
1324
/**
1358
1325
  Calculate length of sort key.
1359
1326
 
1360
 
  @param session                          Thread Cursor
 
1327
  @param session                          Thread handler
1361
1328
  @param sortorder                Order of items to sort
1362
1329
  @param s_length                 Number of items to sort
1363
1330
  @param[out] multi_byte_charset Set to 1 if we are using multi-byte charset
1630
1597
    }
1631
1598
  }
1632
1599
}
1633
 
 
1634
 
} /* namespace drizzled */