~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/uniques.cc

  • Committer: Stewart Smith
  • Date: 2010-07-27 00:49:32 UTC
  • mto: (1720.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1721.
  • Revision ID: stewart@flamingspork.com-20100727004932-basq3vx9szmmbswm
fix storing and manipulating foreign keys in the proto around ALTER TABLE, CREATE TABLE and ALTER TABLE ADD/DROP FOREIGN KEY. We also (mostly) emulate the naming of innodb foreign keys in the upper layer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
  */
88
88
  max_elements= (ulong) (max_in_memory_size /
89
89
                         ALIGN_SIZE(sizeof(TREE_ELEMENT)+size));
90
 
  open_cached_file(file, drizzle_tmpdir,TEMP_PREFIX, DISK_BUFFER_SIZE,
 
90
  open_cached_file(file, drizzle_tmpdir.c_str(), TEMP_PREFIX, DISK_BUFFER_SIZE,
91
91
                   MYF(MY_WME));
92
92
}
93
93
 
384
384
  BUFFPEK.
385
385
*/
386
386
 
387
 
#ifdef __cplusplus
388
 
extern "C" {
389
 
#endif
390
 
 
391
387
static int buffpek_compare(void *arg, unsigned char *key_ptr1, unsigned char *key_ptr2)
392
388
{
393
389
  BUFFPEK_COMPARE_CONTEXT *ctx= (BUFFPEK_COMPARE_CONTEXT *) arg;
395
391
                          *((unsigned char **) key_ptr1), *((unsigned char **)key_ptr2));
396
392
}
397
393
 
398
 
#ifdef __cplusplus
399
 
}
400
 
#endif
401
 
 
402
394
/*
403
395
 The comparison function object, passed to a priority_queue in merge_walk()
404
396
 as its sort function parameter.
587
579
bool Unique::walk(tree_walk_action action, void *walk_action_arg)
588
580
{
589
581
  int res;
590
 
  unsigned char *merge_buffer;
 
582
  std::vector<unsigned char> merge_buffer;
591
583
 
592
584
  if (elements == 0)                       /* the whole tree is in memory */
593
585
    return tree_walk(&tree, action, walk_action_arg, left_root_right);
594
586
 
595
587
  /* flush current tree to the file to have some memory for merge buffer */
596
588
  if (flush())
597
 
    return 1;
 
589
    return true;
 
590
 
598
591
  if (flush_io_cache(file) || reinit_io_cache(file, internal::READ_CACHE, 0L, 0, 0))
599
 
    return 1;
600
 
  if (!(merge_buffer= (unsigned char *) malloc(max_in_memory_size)))
601
 
    return 1;
602
 
  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,
603
604
                  (BUFFPEK *) file_ptrs.buffer,
604
605
                  (BUFFPEK *) file_ptrs.buffer + file_ptrs.elements,
605
606
                  action, walk_action_arg,
606
607
                  tree.compare, tree.custom_arg, file);
607
 
  free((char*) merge_buffer);
 
608
 
608
609
  return res;
609
610
}
610
611
 
642
643
 
643
644
      /* Open cached file if it isn't open */
644
645
  outfile=table->sort.io_cache= new internal::IO_CACHE;
645
 
  memset(outfile, 0, sizeof(internal::IO_CACHE));
646
646
 
647
 
  if (!outfile || (! my_b_inited(outfile) && open_cached_file(outfile,drizzle_tmpdir,TEMP_PREFIX,READ_RECORD_BUFFER, MYF(MY_WME))))
 
647
  if (!outfile || (! my_b_inited(outfile) && open_cached_file(outfile, drizzle_tmpdir.c_str(),TEMP_PREFIX,READ_RECORD_BUFFER, MYF(MY_WME))))
648
648
    return 1;
649
649
  reinit_io_cache(outfile, internal::WRITE_CACHE, 0L, 0, 0);
650
650