~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to sql/ha_partition.cc

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen, Otto Kekäläinen, James Page
  • Date: 2014-03-02 01:38:26 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140302013826-z3afnfteqo86pccd
Tags: 5.5.36-1
[ Otto Kekäläinen ]
* New upstream release.
* Updated Danish debconf translation (Closes: #739750).
* d/control: Added explicit Conflicts/Replaces for mysql-5.6 packages
  (Closes: #739841).
* d/control: Update for use of virtual-* packages for switching to/from
  MySQL alternatives.

[ James Page ]
* d/control: Drop Nicholas from Uploaders, MIA (Closes: #739360).
* d/control: Add libjemalloc-dev to BD's.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
static uint partition_flags();
81
81
static uint alter_table_flags(uint flags);
82
82
 
 
83
extern "C" int cmp_key_then_part_id(void *key_p, uchar *ref1, uchar *ref2);
83
84
 
84
85
static int partition_initialize(void *p)
85
86
{
4540
4541
    } while (++i < m_tot_parts);
4541
4542
    m_start_key.key= (const uchar*)ptr;
4542
4543
    /* Initialize priority queue, initialized to reading forward. */
4543
 
    if (init_queue(&m_queue, used_parts, (uint) PARTITION_BYTES_IN_POS,
4544
 
                   0, key_rec_cmp, (void*)m_curr_key_info, 0, 0))
 
4544
    if (init_queue(&m_queue, used_parts, 0,
 
4545
                   0, cmp_key_then_part_id, (void*)m_curr_key_info, 0, 0))
4545
4546
    {
4546
4547
      my_free(m_ordered_rec_buffer);
4547
4548
      m_ordered_rec_buffer= NULL;
4737
4738
}
4738
4739
 
4739
4740
 
 
4741
/*
 
4742
  @brief
 
4743
  Provide ordering by (key_value, partition_id). 
 
4744
  
 
4745
  @detail
 
4746
  Ordering by partition id is required so that key scans on key=const
 
4747
  return rows in rowid order (this is required for some variants of 
 
4748
  index_merge to work).  
 
4749
  
 
4750
  In ha_partition, rowid is a (partition_id, underlying_table_rowid). 
 
4751
  handle_ordered_index_scan must return rows ordered by (key, rowid).
 
4752
 
 
4753
  If two rows have the same key value and come from different partitions, 
 
4754
  it is sufficient to return them in the order of their partition_id.
 
4755
*/
 
4756
 
 
4757
extern "C" int cmp_key_then_part_id(void *key_p, uchar *ref1, uchar *ref2)
 
4758
{
 
4759
  my_ptrdiff_t diff1, diff2;
 
4760
  int res;
 
4761
 
 
4762
  if ((res= key_rec_cmp(key_p, ref1 + PARTITION_BYTES_IN_POS, 
 
4763
                        ref2 + PARTITION_BYTES_IN_POS)))
 
4764
  {
 
4765
    return res;
 
4766
  }
 
4767
  
 
4768
  /* The following was taken from ha_partition::cmp_ref */
 
4769
  diff1= ref2[1] - ref1[1];
 
4770
  diff2= ref2[0] - ref1[0];
 
4771
  if (!diff1 && !diff2)
 
4772
    return 0;
 
4773
 
 
4774
  if (diff1 > 0)
 
4775
    return(-1);
 
4776
 
 
4777
  if (diff1 < 0)
 
4778
    return(+1);
 
4779
 
 
4780
  if (diff2 > 0)
 
4781
    return(-1);
 
4782
 
 
4783
  return(+1);
 
4784
}
 
4785
 
 
4786
 
4740
4787
/**
4741
4788
  Common routine for a number of index_read variants
4742
4789
 
5564
5611
int ha_partition::handle_ordered_index_scan_key_not_found()
5565
5612
{
5566
5613
  int error;
5567
 
  uint i;
 
5614
  uint i, old_elements= m_queue.elements;
5568
5615
  uchar *part_buf= m_ordered_rec_buffer;
5569
5616
  uchar *curr_rec_buf= NULL;
5570
5617
  DBUG_ENTER("ha_partition::handle_ordered_index_scan_key_not_found");
5599
5646
  bitmap_clear_all(&m_key_not_found_partitions);
5600
5647
  m_key_not_found= false;
5601
5648
 
5602
 
  /* Update m_top_entry, which may have changed. */
5603
 
  uchar *key_buffer= queue_top(&m_queue);
5604
 
  m_top_entry= uint2korr(key_buffer);
 
5649
  if (m_queue.elements > old_elements)
 
5650
  {
 
5651
    /* Update m_top_entry, which may have changed. */
 
5652
    uchar *key_buffer= queue_top(&m_queue);
 
5653
    m_top_entry= uint2korr(key_buffer);
 
5654
  }
5605
5655
  DBUG_RETURN(0);
5606
5656
}
5607
5657
 
7647
7697
    If they belong to different partitions we decide that they are not
7648
7698
    the same record. Otherwise we use the particular handler to decide if
7649
7699
    they are the same. Sort in partition id order if not equal.
 
7700
 
 
7701
  MariaDB note: 
 
7702
    Please don't merge the code from MySQL that does this:
 
7703
 
 
7704
    We get two references and need to check if those records are the same.
 
7705
    If they belong to different partitions we decide that they are not
 
7706
    the same record. Otherwise we use the particular handler to decide if
 
7707
    they are the same. Sort in partition id order if not equal.
 
7708
 
 
7709
    It is incorrect, MariaDB has an alternative fix.
7650
7710
*/
7651
7711
 
7652
7712
int ha_partition::cmp_ref(const uchar *ref1, const uchar *ref2)