List:Internals« Previous MessageNext Message »
From:mikael Date:March 16 2005 12:33pm
Subject:bk commit into 5.0 tree (mronstrom:1.1794)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of mikron. When mikron does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1794 05/03/16 13:33:29 mronstrom@stripped +2 -0
  WL 1354 Partition:
  Fixed up code to handle read_range_* as well as normal
  index scans with order
  Moved index_init and index_end to loop in those methods.
  Some code reorg
  Removed some unneeded routines

  sql/ha_partition.h
    1.26 05/03/16 13:33:21 mronstrom@stripped +1 -4
    WL 1354 Partition:
    Fixed up code to handle read_range_* as well as normal
    index scans with order
    Moved index_init and index_end to loop in those methods.
    Some code reorg
    Removed some unneeded routines

  sql/ha_partition.cc
    1.27 05/03/16 13:33:21 mronstrom@stripped +146 -87
    WL 1354 Partition:
    Fixed up code to handle read_range_* as well as normal
    index scans with order
    Moved index_init and index_end to loop in those methods.
    Some code reorg
    Removed some unneeded routines

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	mronstrom
# Host:	mikael-ronstr-ms-dator.local
# Root:	/Users/mikron/wl1354_new

--- 1.26/sql/ha_partition.cc	Tue Mar 15 22:36:02 2005
+++ 1.27/sql/ha_partition.cc	Wed Mar 16 13:33:21 2005
@@ -1306,12 +1306,43 @@
 */
 int ha_partition::index_init(uint inx)
 {
+  uint i;
+  int error;
   DBUG_ENTER("ha_partition::index_init");
   active_index= inx;
   m_curr_scan_part= NO_CURRENT_PART_ID;
   m_start_key_len= 0;
+  m_ordered= TRUE;
+  for (i= 0; i < m_tot_parts; i++)
+    if (error=m_eng_ref[i]->ha_index_init(inx))
+      DBUG_RETURN(error);
   DBUG_RETURN(FALSE);
 }
+/*
+  index_end is called at the end of an index scan to clean up any
+  things needed to clean up.
+  In our case we free the buffer keeping the key-buffer provided in the
+  index_read call and if we didn't scan to the end we need to call
+  index_end also on the last partition.
+*/
+int ha_partition::index_end()
+{
+  uint i;
+  int error;
+  DBUG_ENTER("ha_partition::index_end");
+  m_start_key_len= 0;
+  my_free((char*)m_rec_key_buf, MYF(MY_ALLOW_ZERO_PTR));
+  m_rec_key_buf= NULL;
+  m_ordered= TRUE;
+  active_index= MAX_KEY;
+  m_curr_scan_part= NO_CURRENT_PART_ID;
+  m_end_index_part= 0;
+  for (i=0; i < m_tot_parts; i++)
+    if (error= m_eng_ref[i]->ha_index_end())
+      DBUG_RETURN(error);
+  DBUG_RETURN(FALSE);
+}
+
 
 /*
   index_read starts a new index scan using a start key. The MySQL Server
@@ -1356,7 +1387,14 @@
   int error;
   DBUG_ENTER("ha_partition::index_first");
   m_index_scan_type= partition_index_first;
-  DBUG_RETURN(handle_ordered_index_scan(buf));
+  if (!m_ordered)
+  {
+    DBUG_RETURN(handle_unordered_index_scan(buf));
+  }
+  else
+  {
+    DBUG_RETURN(handle_ordered_index_scan(buf));
+  }
 }
 
 
@@ -1392,13 +1430,12 @@
 
 /*
   This is used in join_read_last_key to optimise away an ORDER BY.
-  index_init is always called immediately before so it is always the
-  only call. Thus will never be used to retrieve more than one record.
   Can only be used on indexes supporting HA_READ_ORDER
 */
 int ha_partition::index_read_last(byte *buf, const byte *key, uint keylen)
 {
   DBUG_ENTER("ha_partition::index_read_last");
+  m_ordered= TRUE; //Safety measure
   DBUG_RETURN(index_read(buf, key, keylen, HA_READ_PREFIX_LAST));
 }
 
@@ -1410,12 +1447,7 @@
   int error;
   DBUG_ENTER("ha_partition::index_next");
   DBUG_ASSERT(m_index_scan_type != partition_index_last);
-  if (m_ordered)
-     DBUG_RETURN(handle_ordered_next(buf));
-  error= m_eng_ref[m_curr_scan_part]->index_next(buf);
-  if (!error)
-    DBUG_RETURN(FALSE);
-  DBUG_RETURN(common_index_next_prev(buf, error));
+  DBUG_RETURN(handle_ordered_next(buf));
 }
 
 /*
@@ -1430,37 +1462,88 @@
 }
 
 /*
-  index_end is called at the end of an index scan to clean up any
-  things needed to clean up.
-  In our case we free the buffer keeping the key-buffer provided in the
-  index_read call and if we didn't scan to the end we need to call
-  index_end also on the last partition.
-*/
-int ha_partition::index_end()
+  We reimplement read_range_first since we don't want the compare_key
+  check at the end. This is already performed in the partition handler.
+  read_range_next is very much different due to that we need to scan
+  all underlying handlers.
+*/
+int ha_partition::read_range_first(const key_range *start_key,
+                                   const key_range *end_key,
+                                   bool eq_range_arg, bool sorted)
 {
-  int ret_val= FALSE;
-  uint i;
-  DBUG_ENTER("ha_partition::index_end");
-  m_start_key_len= 0;
-  if (m_curr_scan_part != NO_CURRENT_PART_ID)
+  int error;
+  DBUG_ENTER("ha_partition::read_range_first");
+  m_ordered= sorted;
+  eq_range= eq_range_arg;
+  end_range= 0;
+  if (end_key)
+  {
+    end_range= &save_end_range;
+    save_end_range= *end_key;
+    key_compare_result_on_equal= 
+               ((end_key->flag == HA_READ_BEFORE_KEY) ? 1 :
+                (end_key->flag == HA_READ_AFTER_KEY) ? -1 : 0);
+  }
+  range_key_part= table->key_info[active_index].key_part;
+
+  if (!start_key)			// Read first record
+  {
+    error= index_first(table->record[0]);
+  }
+  else
   {
-    DBUG_PRINT("info", ("ha_index_end on partition %d",
-                         m_curr_scan_part));
-    ret_val= m_eng_ref[m_curr_scan_part]->ha_index_end();
+    error= index_read(table->record[0],
+		       start_key->key,
+		       start_key->length,
+		       start_key->flag);
   }
+  if (error)
+    DBUG_RETURN((error == HA_ERR_KEY_NOT_FOUND) 
+		? HA_ERR_END_OF_FILE
+		: error);
+  DBUG_RETURN(FALSE);
+}
+
+int ha_partition::read_range_next()
+{
+  int error;
+  handler *file;
+  DBUG_ENTER("ha_partition::read_range_next");
   if (m_ordered)
   {
-    my_free((char*)m_rec_key_buf, MYF(MY_ALLOW_ZERO_PTR));
-    m_rec_key_buf= NULL;
-    for (i=0; i < m_tot_parts; i++)
-      (void)m_eng_ref[i]->ha_index_end();
+    error=handler::read_range_next();
   }
   else
-    m_ordered= TRUE;
-  active_index= MAX_KEY;
-  m_curr_scan_part= NO_CURRENT_PART_ID;
-  m_end_index_part= 0;
-  DBUG_RETURN(ret_val);
+  {
+    file= m_eng_ref[m_curr_scan_part];
+    if (eq_range)
+    {
+      if (!(error= file->index_next_same(table->record[0],
+                                         end_range->key,
+                                         end_range->length)))
+      {
+        DBUG_RETURN(FALSE);
+      }
+    }
+    else
+    {
+      error= file->index_next(table->record[0]);
+      if (!error)
+      {
+        if (compare_key(end_range) <= 0)
+        {
+          DBUG_RETURN(FALSE);
+        }
+        error= HA_ERR_END_OF_FILE;
+      }
+    }
+    if (error == HA_ERR_END_OF_FILE)
+    {
+      m_curr_scan_part++;
+      error= start_index_read(table->record[0], FALSE);
+    }
+  }
+  DBUG_RETURN(error);
 }
 
 /*
@@ -1475,27 +1558,11 @@
   perform any sort.
 */
 
-int ha_partition::set_up_index_scan()
-{
-  int error;
-  DBUG_ENTER("ha_partition::set_up_index_scan");
-  if (m_curr_scan_part != NO_CURRENT_PART_ID)
-  {
-    DBUG_PRINT("info", ("ha_index_end on partition %d", m_curr_scan_part));
-    if (error= m_eng_ref[m_curr_scan_part]->ha_index_end())
-      DBUG_RETURN(error);
-  }
-  m_end_index_part= m_tot_parts;
-  m_curr_scan_part= 0;
-  DBUG_RETURN(FALSE);
-}
-
 int ha_partition::handle_unordered_index_scan(byte *buf)
 {
-  int error;
   DBUG_ENTER("ha_partition::handle_unordered_index_scan");
-  if (error= set_up_index_scan())
-    DBUG_RETURN(error);
+  m_curr_scan_part= 0;
+  m_end_index_part= m_tot_parts;
   DBUG_RETURN(start_index_read(buf, TRUE));
 }
 
@@ -1509,51 +1576,47 @@
   int ret_error= (first ? HA_ERR_KEY_NOT_FOUND : HA_ERR_END_OF_FILE);
   uint i;
   handler *file;
-  DBUG_ENTER("ha_partition::start_index_read()");
+  DBUG_ENTER("ha_partition::start_index_read");
   for (i= m_curr_scan_part; i < m_end_index_part; i++)
   {
     file= m_eng_ref[i];
-    if (error= file->ha_index_init(active_index))
-      break;
     m_curr_scan_part=i;
-    DBUG_ASSERT(m_index_scan_type == partition_index_read);
-    DBUG_PRINT("info", ("index_read on partition %d", i));
-    error= file->index_read(buf, m_start_key_ref,
-              m_start_key_len, (enum ha_rkey_function)m_index_find_flag);
+    switch (m_index_scan_type)
+    {
+      case partition_index_read:
+        DBUG_PRINT("info", ("index_read on partition %d", i));
+        error= file->index_read(buf, m_start_key_ref,
+                             m_start_key_len,
+                             (enum ha_rkey_function)m_index_find_flag);
+        break;
+      case partition_index_first:
+        DBUG_PRINT("info", ("index_first on partition %d", i));
+        error= file->index_first(buf);
+        break;
+      default:
+        DBUG_ASSERT(FALSE);
+        DBUG_RETURN(TRUE);
+    }
     if (!error)
     {
-      DBUG_RETURN(FALSE);
+      if (compare_key(end_range) <= 0)
+      {
+        DBUG_RETURN(FALSE);
+      }
+      error= HA_ERR_END_OF_FILE;
     }
-    else if ((error == HA_ERR_END_OF_FILE) ||
-             (error == HA_ERR_KEY_NOT_FOUND))
+    if ((error == HA_ERR_END_OF_FILE) ||
+        (error == HA_ERR_KEY_NOT_FOUND))
     {
-      DBUG_PRINT("info", ("ha_index_end on partition %d", i));
-      if (error= file->ha_index_end())
-        goto err_handler;
-      continue;
+      DBUG_PRINT("info", ("HA_ERR_END_OF_FILE on partition %d", i));
     }
     else
-      goto err_handler;
+    {
+      DBUG_RETURN(error);
+    }
   }
   m_curr_scan_part= NO_CURRENT_PART_ID;
   DBUG_RETURN(ret_error);
-err_handler:
-  DBUG_RETURN(error);
-}
-
-int ha_partition::common_index_next_prev(byte *buf, int error)
-{
-  int loc_error;
-  DBUG_ENTER("ha_partition::common_index_next_prev");
-  if (error == HA_ERR_END_OF_FILE)
-  {
-    loc_error= m_eng_ref[m_curr_scan_part]->ha_index_end();
-    if (loc_error)
-      DBUG_RETURN(loc_error);
-    m_curr_scan_part++;
-    DBUG_RETURN(start_index_read(buf, FALSE));
-  }
-  DBUG_RETURN(error);
 }
 
 /*
@@ -1613,10 +1676,6 @@
   for (i= 0; i < m_tot_parts; i++)
   {
     file= m_eng_ref[i];
-    if (error= file->ha_index_init(active_index))
-    {
-      DBUG_RETURN(error);
-    }
     switch (m_index_scan_type)
     {
       case partition_index_read:

--- 1.25/sql/ha_partition.h	Tue Mar 15 17:19:26 2005
+++ 1.26/sql/ha_partition.h	Wed Mar 16 13:33:21 2005
@@ -340,17 +340,14 @@
   virtual int read_multi_range_next(KEY_MULTI_RANGE **found_range_p);
   */
 
-  /*
+  
   virtual int read_range_first(const key_range *start_key,
                                const key_range *end_key,
                                bool eq_range, bool sorted);
   virtual int read_range_next();
-  */
 
   private:
     int handle_unordered_index_scan(byte *buf);
-    int set_up_index_scan();
-    int common_index_next_prev(byte *buf, int error);
     int start_index_read(byte *buf, bool first);
     byte *rec_buf(uint part_id)
     {
Thread
bk commit into 5.0 tree (mronstrom:1.1794)mikael16 Mar