~kalebral-deactivatedaccount/drizzle/change-error_num_to_enum-2

« back to all changes in this revision

Viewing changes to drizzled/uniques.cc

  • Committer: Patrick Crews
  • Date: 2010-08-17 17:42:29 UTC
  • mfrom: (1711.1.24 build)
  • Revision ID: gleebix@gmail.com-20100817174229-e28p5025ndgkkxif
Rollup patch - optimizer fixes, mutex removal, client cleanup, translations update

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
  init_tree(&tree, (ulong) (max_in_memory_size / 16), 0, size, comp_func, false,
82
82
            NULL, comp_func_fixed_arg);
83
83
  /* If the following fail's the next add will also fail */
84
 
  my_init_dynamic_array(&file_ptrs, sizeof(BUFFPEK), 16, 16);
 
84
  my_init_dynamic_array(&file_ptrs, sizeof(buffpek_st), 16, 16);
85
85
  /*
86
86
    If you change the following, change it in get_max_elements function, too.
87
87
  */
340
340
    /* Write tree to disk; clear tree */
341
341
bool Unique::flush()
342
342
{
343
 
  BUFFPEK file_ptr;
 
343
  buffpek_st file_ptr;
344
344
  elements+= tree.elements_in_tree;
345
345
  file_ptr.count=tree.elements_in_tree;
346
346
  file_ptr.file_pos=my_b_tell(file);
381
381
  The comparison function, passed to queue_init() in merge_walk() and in
382
382
  merge_buffers() when the latter is called from Uniques::get() must
383
383
  use comparison function of Uniques::tree, but compare members of struct
384
 
  BUFFPEK.
 
384
  buffpek_st.
385
385
*/
386
386
 
387
387
static int buffpek_compare(void *arg, unsigned char *key_ptr1, unsigned char *key_ptr2)
403
403
  public:
404
404
  buffpek_compare_functor(qsort_cmp2 in_key_compare, void *in_compare_arg)
405
405
    : key_compare(in_key_compare), key_compare_arg(in_compare_arg) { }
406
 
  inline bool operator()(const BUFFPEK *i, const BUFFPEK *j)
 
406
  inline bool operator()(const buffpek_st *i, const buffpek_st *j)
407
407
  {
408
408
    return key_compare(key_compare_arg,
409
409
                    i->key, j->key);
426
426
                       key_length
427
427
    key_length         size of tree element; key_length * (end - begin)
428
428
                       must be less or equal than merge_buffer_size.
429
 
    begin              pointer to BUFFPEK struct for the first tree.
430
 
    end                pointer to BUFFPEK struct for the last tree;
 
429
    begin              pointer to buffpek_st struct for the first tree.
 
430
    end                pointer to buffpek_st struct for the last tree;
431
431
                       end > begin and [begin, end) form a consecutive
432
 
                       range. BUFFPEKs structs in that range are used and
 
432
                       range. buffpek_sts structs in that range are used and
433
433
                       overwritten in merge_walk().
434
434
    walk_action        element visitor. Action is called for each unique
435
435
                       key.
445
445
*/
446
446
 
447
447
static bool merge_walk(unsigned char *merge_buffer, ulong merge_buffer_size,
448
 
                       uint32_t key_length, BUFFPEK *begin, BUFFPEK *end,
 
448
                       uint32_t key_length, buffpek_st *begin, buffpek_st *end,
449
449
                       tree_walk_action walk_action, void *walk_action_arg,
450
450
                       qsort_cmp2 compare, void *compare_arg,
451
451
                       internal::IO_CACHE *file)
453
453
  if (end <= begin ||
454
454
      merge_buffer_size < (ulong) (key_length * (end - begin + 1))) 
455
455
    return 1;
456
 
  priority_queue<BUFFPEK *, vector<BUFFPEK *>, buffpek_compare_functor >
 
456
  priority_queue<buffpek_st *, vector<buffpek_st *>, buffpek_compare_functor >
457
457
    queue(buffpek_compare_functor(compare, compare_arg));
458
458
  /* we need space for one key when a piece of merge buffer is re-read */
459
459
  merge_buffer_size-= key_length;
463
463
  /* if piece_size is aligned reuse_freed_buffer will always hit */
464
464
  uint32_t piece_size= max_key_count_per_piece * key_length;
465
465
  uint32_t bytes_read;               /* to hold return value of read_to_buffer */
466
 
  BUFFPEK *top;
 
466
  buffpek_st *top;
467
467
  int res= 1;
468
468
  /*
469
469
    Invariant: queue must contain top element from each tree, until a tree
601
601
  }
602
602
 
603
603
  res= merge_walk(&merge_buffer[0], (ulong) max_in_memory_size, size,
604
 
                  (BUFFPEK *) file_ptrs.buffer,
605
 
                  (BUFFPEK *) file_ptrs.buffer + file_ptrs.elements,
 
604
                  (buffpek_st *) file_ptrs.buffer,
 
605
                  (buffpek_st *) file_ptrs.buffer + file_ptrs.elements,
606
606
                  action, walk_action_arg,
607
607
                  tree.compare, tree.custom_arg, file);
608
608
 
635
635
    return 1;
636
636
 
637
637
  internal::IO_CACHE *outfile=table->sort.io_cache;
638
 
  BUFFPEK *file_ptr= (BUFFPEK*) file_ptrs.buffer;
 
638
  buffpek_st *file_ptr= (buffpek_st*) file_ptrs.buffer;
639
639
  uint32_t maxbuffer= file_ptrs.elements - 1;
640
640
  unsigned char *sort_buffer;
641
641
  internal::my_off_t save_pos;