~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/filesort.cc

  • Committer: Brian Aker
  • Date: 2009-09-23 21:40:36 UTC
  • mfrom: (971.6.13 eday-purecov)
  • Revision ID: brian@gaz-20090923214036-bustj80ei8ysbayf
Old message removal by Eric (no actual code has been harmed in the production of
this patch...)

Show diffs side-by-side

added added

removed removed

Lines of Context:
514
514
    {
515
515
      if (indexfile)
516
516
      {
517
 
        if (my_b_read(indexfile,(unsigned char*) ref_pos,ref_length)) /* purecov: deadcode */
 
517
        if (my_b_read(indexfile,(unsigned char*) ref_pos,ref_length))
518
518
        {
519
519
          error= my_errno ? my_errno : -1;              /* Abort */
520
520
          break;
544
544
        (void) file->extra(HA_EXTRA_NO_CACHE);
545
545
        file->ha_rnd_end();
546
546
      }
547
 
      return(HA_POS_ERROR);             /* purecov: inspected */
 
547
      return(HA_POS_ERROR);
548
548
    }
549
549
    if (error == 0)
550
550
      param->examined_rows++;
588
588
 
589
589
  if (error != HA_ERR_END_OF_FILE)
590
590
  {
591
 
    file->print_error(error,MYF(ME_ERROR | ME_WAITTANG)); /* purecov: inspected */
592
 
    return(HA_POS_ERROR);                       /* purecov: inspected */
 
591
    file->print_error(error,MYF(ME_ERROR | ME_WAITTANG));
 
592
    return(HA_POS_ERROR);
593
593
  }
594
594
  if (indexpos && idx &&
595
595
      write_keys(param,sort_keys,idx,buffpek_pointers,tempfile))
596
 
    return(HA_POS_ERROR);                       /* purecov: inspected */
 
596
    return(HA_POS_ERROR);
597
597
  return(my_b_inited(tempfile) ?
598
598
              (ha_rows) (my_b_tell(tempfile)/param->rec_length) :
599
599
              idx);
636
636
  if (!my_b_inited(tempfile) &&
637
637
      open_cached_file(tempfile, drizzle_tmpdir, TEMP_PREFIX, DISK_BUFFER_SIZE,
638
638
                       MYF(MY_WME)))
639
 
    goto err;                                   /* purecov: inspected */
 
639
    goto err;
640
640
  /* check we won't have more buffpeks than we can possibly keep in memory */
641
641
  if (my_b_tell(buffpek_pointers) + sizeof(BUFFPEK) > (uint64_t)UINT_MAX)
642
642
    goto err;
643
643
  buffpek.file_pos= my_b_tell(tempfile);
644
644
  if ((ha_rows) count > param->max_rows)
645
 
    count=(uint32_t) param->max_rows;               /* purecov: inspected */
 
645
    count=(uint32_t) param->max_rows;
646
646
  buffpek.count=(ha_rows) count;
647
647
  for (end=sort_keys+count ; sort_keys != end ; sort_keys++)
648
648
    if (my_b_write(tempfile, (unsigned char*) *sort_keys, (uint32_t) rec_length))
734
734
            memset(to-1, 0, sort_field->length+1);
735
735
          else
736
736
          {
737
 
            /* purecov: begin deadcode */
738
737
            /*
739
738
              This should only happen during extreme conditions if we run out
740
739
              of memory or have an item marked not null when it can be null.
742
741
            */
743
742
            assert(0);
744
743
            memset(to, 0, sort_field->length);  // Avoid crash
745
 
            /* purecov: end */
746
744
          }
747
745
          break;
748
746
        }
786
784
          int64_t value= item->val_int_result();
787
785
          if (maybe_null)
788
786
          {
789
 
            *to++=1;                            /* purecov: inspected */
 
787
            *to++=1;
790
788
            if (item->null_value)
791
789
            {
792
790
              if (maybe_null)
967
965
    count=(uint32_t) param->max_rows;
968
966
  if (!(to= table_sort->record_pointers=
969
967
        (unsigned char*) malloc(res_length*count)))
970
 
    return(1);                 /* purecov: inspected */
 
968
    return(1);
971
969
  for (unsigned char **end= sort_keys+count ; sort_keys != end ; sort_keys++)
972
970
  {
973
971
    memcpy(to, *sort_keys+offset, res_length);
987
985
  BUFFPEK *lastbuff;
988
986
 
989
987
  if (*maxbuffer < MERGEBUFF2)
990
 
    return(0);                          /* purecov: inspected */
 
988
    return(0);
991
989
  if (flush_io_cache(t_file) ||
992
990
      open_cached_file(&t_file2,drizzle_tmpdir,TEMP_PREFIX,DISK_BUFFER_SIZE,
993
991
                        MYF(MY_WME)))
994
 
    return(1);                          /* purecov: inspected */
 
992
    return(1);
995
993
 
996
994
  from_file= t_file ; to_file= &t_file2;
997
995
  while (*maxbuffer >= MERGEBUFF2)
1009
1007
    }
1010
1008
    if (merge_buffers(param,from_file,to_file,sort_buffer,lastbuff++,
1011
1009
                      buffpek+i,buffpek+ *maxbuffer,0))
1012
 
      break;                                    /* purecov: inspected */
 
1010
      break;
1013
1011
    if (flush_io_cache(to_file))
1014
 
      break;                                    /* purecov: inspected */
 
1012
      break;
1015
1013
    temp=from_file; from_file=to_file; to_file=temp;
1016
1014
    setup_io_cache(from_file);
1017
1015
    setup_io_cache(to_file);
1045
1043
  if ((count= (uint32_t) min((ha_rows) buffpek->max_keys,buffpek->count)))
1046
1044
  {
1047
1045
    if (pread(fromfile->file,(unsigned char*) buffpek->base, (length= rec_length*count),buffpek->file_pos) == 0)
1048
 
      return((uint32_t) -1);                    /* purecov: inspected */
 
1046
      return((uint32_t) -1);
1049
1047
 
1050
1048
    buffpek->key= buffpek->base;
1051
1049
    buffpek->file_pos+= length;                 /* New filepos */
1147
1145
    strpos+= (uint32_t) (error= (int) read_to_buffer(from_file, buffpek,
1148
1146
                                                                         rec_length));
1149
1147
    if (error == -1)
1150
 
      goto err;                                 /* purecov: inspected */
 
1148
      goto err;
1151
1149
    buffpek->max_keys= buffpek->mem_count;      // If less data in buffers than expected
1152
1150
    queue.push(buffpek);
1153
1151
  }
1166
1164
    memcpy(param->unique_buff, buffpek->key, rec_length);
1167
1165
    if (my_b_write(to_file, (unsigned char*) buffpek->key, rec_length))
1168
1166
    {
1169
 
      error=1; goto err;                        /* purecov: inspected */
 
1167
      error=1; goto err;
1170
1168
    }
1171
1169
    buffpek->key+= rec_length;
1172
1170
    buffpek->mem_count--;
1173
1171
    if (!--max_rows)
1174
1172
    {
1175
 
      error= 0;                                       /* purecov: inspected */
1176
 
      goto end;                                       /* purecov: inspected */
 
1173
      error= 0;
 
1174
      goto end;
1177
1175
    }
1178
1176
    /* Top element has been used */
1179
1177
    queue.pop();
1186
1184
  {
1187
1185
    if (*killed)
1188
1186
    {
1189
 
      error= 1; goto err;                        /* purecov: inspected */
 
1187
      error= 1; goto err;
1190
1188
    }
1191
1189
    for (;;)
1192
1190
    {
1202
1200
      {
1203
1201
        if (my_b_write(to_file,(unsigned char*) buffpek->key, rec_length))
1204
1202
        {
1205
 
          error=1; goto err;                        /* purecov: inspected */
 
1203
          error=1; goto err;
1206
1204
        }
1207
1205
      }
1208
1206
      else
1209
1207
      {
1210
1208
        if (my_b_write(to_file, (unsigned char*) buffpek->key+offset, res_length))
1211
1209
        {
1212
 
          error=1; goto err;                        /* purecov: inspected */
 
1210
          error=1; goto err;
1213
1211
        }
1214
1212
      }
1215
1213
      if (!--max_rows)
1216
1214
      {
1217
 
        error= 0;                               /* purecov: inspected */
1218
 
        goto end;                               /* purecov: inspected */
 
1215
        error= 0;
 
1216
        goto end;
1219
1217
      }
1220
1218
 
1221
1219
    skip_duplicate:
1229
1227
          break;                        /* One buffer have been removed */
1230
1228
        }
1231
1229
        else if (error == -1)
1232
 
          goto err;                        /* purecov: inspected */
 
1230
          goto err;
1233
1231
      }
1234
1232
      /* Top element has been replaced */
1235
1233
      queue.pop();
1266
1264
      if (my_b_write(to_file,(unsigned char*) buffpek->key,
1267
1265
                     (rec_length*buffpek->mem_count)))
1268
1266
      {
1269
 
        error= 1; goto err;                        /* purecov: inspected */
 
1267
        error= 1; goto err;
1270
1268
      }
1271
1269
    }
1272
1270
    else
1303
1301
{
1304
1302
  if (merge_buffers(param,tempfile,outfile,sort_buffer,buffpek,buffpek,
1305
1303
                    buffpek+maxbuffer,1))
1306
 
    return(1);                          /* purecov: inspected */
 
1304
    return(1);
1307
1305
  return(0);
1308
1306
} /* merge_index */
1309
1307