~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/uniques.cc

merged with latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
579
579
bool Unique::walk(tree_walk_action action, void *walk_action_arg)
580
580
{
581
581
  int res;
582
 
  unsigned char *merge_buffer;
 
582
  std::vector<unsigned char> merge_buffer;
583
583
 
584
584
  if (elements == 0)                       /* the whole tree is in memory */
585
585
    return tree_walk(&tree, action, walk_action_arg, left_root_right);
586
586
 
587
587
  /* flush current tree to the file to have some memory for merge buffer */
588
588
  if (flush())
589
 
    return 1;
 
589
    return true;
 
590
 
590
591
  if (flush_io_cache(file) || reinit_io_cache(file, internal::READ_CACHE, 0L, 0, 0))
591
 
    return 1;
592
 
  if (!(merge_buffer= (unsigned char *) malloc(max_in_memory_size)))
593
 
    return 1;
594
 
  res= merge_walk(merge_buffer, (ulong) max_in_memory_size, size,
 
592
    return true;
 
593
 
 
594
  try
 
595
  {
 
596
    merge_buffer.resize(max_in_memory_size);
 
597
  }
 
598
  catch (std::bad_alloc const&)
 
599
  {
 
600
    return true;
 
601
  }
 
602
 
 
603
  res= merge_walk(&merge_buffer[0], (ulong) max_in_memory_size, size,
595
604
                  (BUFFPEK *) file_ptrs.buffer,
596
605
                  (BUFFPEK *) file_ptrs.buffer + file_ptrs.elements,
597
606
                  action, walk_action_arg,
598
607
                  tree.compare, tree.custom_arg, file);
599
 
  free((char*) merge_buffer);
 
608
 
600
609
  return res;
601
610
}
602
611
 
634
643
 
635
644
      /* Open cached file if it isn't open */
636
645
  outfile=table->sort.io_cache= new internal::IO_CACHE;
637
 
  memset(outfile, 0, sizeof(internal::IO_CACHE));
638
646
 
639
647
  if (!outfile || (! my_b_inited(outfile) && open_cached_file(outfile, drizzle_tmpdir.c_str(),TEMP_PREFIX,READ_RECORD_BUFFER, MYF(MY_WME))))
640
648
    return 1;