List:Commits« Previous MessageNext Message »
From:Patrick Galbraith Date:January 17 2006 1:18am
Subject:bk commit into 5.1 tree (patg:1.2020)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of patg. When patg 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.2020 06/01/16 17:18:30 patg@stripped +7 -0
  WL# 2682
  
  Mikael's requested review changes. These changes are to a private tree, and 
  eventually will create one complete patch against main 5.1 tree.

  sql/sql_partition.cc
    1.19 06/01/16 16:50:32 patg@stripped +140 -0
    WL# 2682
    
    Moved functions from ha_partition to sql_partition

  sql/opt_range.cc
    1.195 06/01/16 16:50:32 patg@stripped +1 -2
    WL# 2682
    
    Removed bitmap init

  sql/handler.h
    1.178 06/01/16 16:50:32 patg@stripped +8 -0
    WL# 2682
    
    Declarations of functions moved to sql_partitions

  sql/ha_partition.h
    1.12 06/01/16 16:50:32 patg@stripped +1 -4
    WL# 2682
    
    moved functions to sql_partitions

  sql/ha_partition.cc
    1.29 06/01/16 16:50:32 patg@stripped +31 -129
    WL# 2682
    
    Moved methods to sql_partitions.cc per Mikael's request. Added bitmap checking
    loops to external_lock and start_stmt. Also, cleanups.

  mysys/my_bitmap.c
    1.37 06/01/16 16:50:32 patg@stripped +7 -0
    WL# 2682
    
    Added bitmap_copy (with ASSERT) per Mikael's request in review

  include/my_bitmap.h
    1.22 06/01/16 16:50:32 patg@stripped +1 -0
    WL# 2682
    
    Added 'bitmap_copy' per Mikael's review request

# 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:	patg
# Host:	govinda.patg.net
# Root:	/home/patg/mysql-build/mysql-5.1-wl2682

--- 1.177/sql/handler.h	2006-01-10 07:19:47 -08:00
+++ 1.178/sql/handler.h	2006-01-16 16:50:32 -08:00
@@ -599,6 +599,7 @@
       to be unused.
   */
   MY_BITMAP used_partitions;
+  MY_BITMAP used_partitions_copy;
 
   union {
     longlong *range_int_array;
@@ -807,6 +808,13 @@
 uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
                                            bool left_endpoint,
                                            bool include_endpoint);
+
+int populate_partition_name_hash(partition_info *m_part_info);
+int set_specific_partition(partition_info *m_part_info,
+                                         const char *partition_name);
+int get_partition_index(partition_info *m_part_info,
+                        const char* partition_name);
+
 #endif
 
 

--- 1.194/sql/opt_range.cc	2006-01-10 07:19:47 -08:00
+++ 1.195/sql/opt_range.cc	2006-01-16 16:50:32 -08:00
@@ -4249,8 +4249,7 @@
 
   uint32 int_buf[MAX_KEY/32+1];
   MY_BITMAP covered_fields;
-  if (bitmap_init(&covered_fields, int_buf, nbits, FALSE))
-    DBUG_RETURN(0);
+
   bitmap_clear_all(&covered_fields);
 
   double total_cost= 0.0f;

--- 1.21/include/my_bitmap.h	2006-01-01 13:17:59 -08:00
+++ 1.22/include/my_bitmap.h	2006-01-16 16:50:32 -08:00
@@ -57,6 +57,7 @@
 extern void bitmap_free(MY_BITMAP *map);
 extern void bitmap_set_above(MY_BITMAP *map, uint from_byte, uint use_bit);
 extern void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size);
+extern void bitmap_copy(MY_BITMAP *to, const MY_BITMAP *from);
 extern void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2);
 extern void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2);
 extern void bitmap_union(MY_BITMAP *map, const MY_BITMAP *map2);

--- 1.36/mysys/my_bitmap.c	2005-07-19 15:40:08 -07:00
+++ 1.37/mysys/my_bitmap.c	2006-01-16 16:50:32 -08:00
@@ -304,6 +304,13 @@
   return 1;
 }
 
+void bitmap_copy(MY_BITMAP *to, const MY_BITMAP *from)
+{
+  DBUG_ASSERT(sizeof(to) ==  sizeof(from));
+  DBUG_ENTER("bitmap_copy");
+  memcpy(to, from, sizeof(MY_BITMAP));
+  DBUG_VOID_RETURN;
+}
 
 void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2)
 {

--- 1.28/sql/ha_partition.cc	2006-01-10 07:31:29 -08:00
+++ 1.29/sql/ha_partition.cc	2006-01-16 16:50:32 -08:00
@@ -62,32 +62,6 @@
 static PARTITION_SHARE *get_share(const char *table_name, TABLE * table);
 #endif
 
-//static byte *partition_names_get_key(PARTITION_NAME *partition_name, uint *length,
-//			       my_bool not_used __attribute__ ((unused)))
-//{
-//  *length= partition_name->partition_name_length;
-//  return (byte *) partition_name->partition_name;
-//}
-
-static byte *partition_names_get_key(partition_element *partition_element, uint *length,
-			       my_bool not_used __attribute__ ((unused)))
-{
-  *length= strlen(partition_element->partition_name);
-  return (byte *) partition_element->partition_name;
-}
-
-int ha_partition::get_partition_index(const char* partition_name)
-{
-  partition_element *el= (partition_element*)hash_search(
-	                                 &(m_part_info->partition_names), 
-	                                 (byte*)partition_name, 
-									 strlen(partition_name));
-  if (el == NULL)
-    return -1;
-  return el->index;
-}
-
-
 /****************************************************************************
                 MODULE create/delete handler object
 ****************************************************************************/
@@ -426,7 +400,6 @@
   DBUG_ENTER("ha_partition::create");
 
   strmov(t_name, name);
-//  *fn_ext(t_name)= 0;
   DBUG_ASSERT(*fn_rext((char*)name) == '\0');
   if (del_ren_cre_table(t_name, NULL, table_arg, create_info))
   {
@@ -782,7 +755,7 @@
     Don't know the size of the underlying storage engine, invent a number of
     bytes allocated for error message if allocation fails
   */
-  alloc_len= 128; 
+  alloc_len= 128;
   do
   {
     part_elem= part_it++;
@@ -855,7 +828,7 @@
   if (!(engine_array= (handlerton **) my_malloc(m_tot_parts * sizeof(handlerton*),MYF(0))))
     goto err2;
   for (i= 0; i < m_tot_parts; i++)
-    engine_array[i]= ha_resolve_by_legacy_type(current_thd, 
+    engine_array[i]= ha_resolve_by_legacy_type(current_thd,
                 (enum legacy_db_type) *(uchar *) ((file_buffer) + 12 + i));
   address_tot_name_len= file_buffer + 12 + 4 * tot_partition_words;
   tot_name_words= (uint4korr(address_tot_name_len) + 3) / 4;
@@ -880,45 +853,6 @@
   DBUG_RETURN(TRUE);
 }
 
-/*
- * populate_partition_name_hash
- * This function will iterate over the list of partition elements and insert them
- * into a hash based on partition name.  This hash sits on the partition info object
- * but is used by the handler for determining if a partition specified in a query
- * actually exists.
- * RETURNS:  1 on error, 0 if successful
-*/
-int ha_partition::populate_partition_name_hash()
-{
-  List_iterator_fast <partition_element> part_it(m_part_info->partitions);
-
-  (void) hash_init(&(m_part_info->partition_names), system_charset_info, 32, 0, 0,
-                   (hash_get_key) partition_names_get_key, 0, 0);
-
-  int index= 0;
-  partition_element *el;
-  while ((el= part_it++) != NULL)
-  {
-    bool has_sub_parts= is_sub_partitioned(m_part_info);
-    
-    if (! has_sub_parts)
-	    el->index= index++;
-    if (my_hash_insert(&(m_part_info->partition_names), (byte*)el))
-      return 1;
-    if (!has_sub_parts) 
-      continue;
-    List_iterator_fast <partition_element> sub_part_it(el->subpartitions);
-    partition_element *subel;
-    while ((subel= sub_part_it++) != NULL)
-    {
-      subel->index= index++;
-      if (my_hash_insert(&(m_part_info->partition_names), (byte*)subel))
-        return 1;
-    }
-  }
-  return 0;
-}
-
 
 /****************************************************************************
                 MODULE open/close object
@@ -949,7 +883,7 @@
   m_start_key.length= 0;
   m_rec0= table->record[0];
   m_rec_length= table->s->reclength;
-  alloc_len= m_tot_parts * (m_rec_length + PARTITION_BYTES_IN_POS); 
+  alloc_len= m_tot_parts * (m_rec_length + PARTITION_BYTES_IN_POS);
   alloc_len+= table->s->max_key_length;
   if (!m_ordered_rec_buffer)
   {
@@ -981,7 +915,7 @@
   bitmap_set_all(&(m_part_info->used_partitions));
 
   /* Here we stick all of our partition element objects in a hash by name */
-  if (populate_partition_name_hash())
+  if (populate_partition_name_hash(m_part_info))
     goto err_handler;
 
   file= m_file;
@@ -1053,7 +987,9 @@
   delete_queue(&queue);
   bitmap_free(&(m_part_info->used_partitions));
   file= m_file;
-  do { (*file)->close(); } while (*(++file));
+  do {
+    (*file)->close();
+  } while (*(++file));
   hash_free(&(m_part_info->partition_names));
 
   DBUG_RETURN(0);
@@ -1095,12 +1031,11 @@
   /* if this query specifies a partition, then set the bitmap accordingly */
   if (table->partition_name != NULL)
   {
-    if ((error= set_specific_partition(table->partition_name)))
+    if ((error= set_specific_partition(m_part_info, table->partition_name)))
     {
       DBUG_RETURN(error);
     }
   }
-  /* REMOVE when psergey pushes his fix */
   else
   {
     bitmap_set_all(&(m_part_info->used_partitions));
@@ -1109,18 +1044,26 @@
   handler **file= m_file;
   do
   {
-    if ((error= (*file)->external_lock(thd, lock_type)))
+    if (_bitmap_is_set(&(m_part_info->used_partitions), (file - m_file)))
     {
-      if (F_UNLCK != lock_type)
-        goto err_handler;
+      if ((error= (*file)->external_lock(thd, lock_type)))
+      {
+        if (F_UNLCK != lock_type)
+          goto err_handler;
+      }
     }
   } while (*(++file));
-  m_lock_type= lock_type;             // for the future (2009?)
+  m_lock_type= lock_type;
   DBUG_RETURN(0);
 
 err_handler:
   while (file-- != m_file)
-    (*file)->external_lock(thd, F_UNLCK);
+  {
+    if (_bitmap_is_set(&(m_part_info->used_partitions), (file - m_file)))
+    {
+      (*file)->external_lock(thd, F_UNLCK);
+    }
+  }
   DBUG_RETURN(error);
 }
 
@@ -1172,45 +1115,6 @@
   DBUG_RETURN(to);
 }
 
-/*
-  set_specific_partition
-  This function takes the given partition name and checks it against the list
-  of partitions and subpartitions, setting the current_partition_index and
-  start_part equal to the chosen 
-*/
-int ha_partition::set_specific_partition(const char *partition_name)
-{
-  int error;
-  DBUG_ENTER("ha_partition::set_specific_partition");
-  partition_element *el= (partition_element*)hash_search(
-	                                 &(m_part_info->partition_names), 
-	                                 (byte*)partition_name, 
-									                  strlen(partition_name));
-  if (el == NULL)
-  {
-    error= my_error(ER_NO_SUCH_PARTITION, MYF(0), partition_name);
-    DBUG_RETURN(error);
-  }
-
-  DBUG_PRINT("info", ("selected partition %s is in table", partition_name));
-  bitmap_clear_all(&m_part_info->used_partitions);
-  
-  if (is_sub_partitioned(m_part_info) && (el->subpartitions.elements > 0))
-  {
-    List_iterator<partition_element> sub_part_it(el->subpartitions);
-    partition_element *sub_el;
-    while ((sub_el= sub_part_it++) != NULL)
-    {
-      bitmap_set_bit(&(m_part_info->used_partitions), sub_el->index);
-    }
-  }
-  else
-    bitmap_set_bit(&(m_part_info->used_partitions), el->index);
-    
-  DBUG_RETURN(0);
-}
-
-
 int ha_partition::start_stmt(THD *thd, thr_lock_type lock_type)
 {
   int i= 0;
@@ -1220,12 +1124,11 @@
   /* if this query specifies a partition, then set the bitmap accordingly */
   if (table->partition_name != NULL)
   {
-    if ((error= set_specific_partition(table->partition_name)))
+    if ((error= set_specific_partition(m_part_info, table->partition_name)))
     {
       DBUG_RETURN(error);
     }
   }
-  /* REMOVE when psergey pushes his fix */
   else
   {
     bitmap_set_all(&(m_part_info->used_partitions));
@@ -1235,8 +1138,11 @@
   handler **file= m_file;
   do
   {
-    if ((error= (*file)->start_stmt(thd, lock_type)))
-      break;
+    if (_bitmap_is_set(&(m_part_info->used_partitions), (file - m_file)))
+    {
+      if ((error= (*file)->start_stmt(thd, lock_type)))
+        break;
+    }
   } while (*(++file));
   DBUG_RETURN(error);
 }
@@ -1569,7 +1475,8 @@
     if (_bitmap_is_set(&(m_part_info->used_partitions), i))
       if ((error= m_file[i]->ha_rnd_init(scan)))
         goto err;
-    if (scan) break;
+    if (scan)
+      break;
   }
   m_scan_value= scan ? 1 : 0;
   DBUG_PRINT("info", ("m_scan_value=%d", m_scan_value));
@@ -1597,10 +1504,9 @@
       break;
     case 1:
       if (MY_BIT_NONE != current_partition_index)         // Table scan
-      //if (m_part_spec.start_part != NO_CURRENT_PART_ID)
       {
-        late_extra_no_cache(current_partition_index); //m_part_spec.start_part);
-        m_file[current_partition_index/*m_part_spec.start_part*/]->ha_rnd_end();
+        late_extra_no_cache(current_partition_index);
+        m_file[current_partition_index]->ha_rnd_end();
       }
       break;
     case 0:
@@ -1613,7 +1519,6 @@
       } while (*(++file));
       break;
   }
-  //m_part_spec.start_part= NO_CURRENT_PART_ID;
   m_scan_value= 2;
   DBUG_RETURN(0);
 }
@@ -1637,7 +1542,6 @@
 int ha_partition::rnd_next(byte *buf)
 {
   DBUG_ASSERT(m_scan_value);
-//  uint part_id= m_part_spec.start_part;         // Cache of this variable
   handler *file;
   int result= HA_ERR_END_OF_FILE;
   DBUG_ENTER("ha_partition::rnd_next");
@@ -1661,8 +1565,6 @@
     int result= file->rnd_next(buf);
     if (!result)
     {
-//      m_part_spec.start_part= part_id;
-  //    m_last_part= part_id;
       table->status= 0;
       DBUG_RETURN(0);
     }

--- 1.11/sql/ha_partition.h	2005-12-31 00:44:48 -08:00
+++ 1.12/sql/ha_partition.h	2006-01-16 16:50:32 -08:00
@@ -131,9 +131,8 @@
   THR_LOCK_DATA lock;                   /* MySQL lock */
   PARTITION_SHARE *share;               /* Shared lock info */
 
-  int set_specific_partition(const char *partition_name);
-  
 public:
+
   virtual void set_part_info(partition_info *part_info)
   {
      m_part_info= part_info;
@@ -207,8 +206,6 @@
   void set_up_table_before_create(TABLE * table_arg, HA_CREATE_INFO * info,
 				  uint part_id);
   partition_element *find_partition_element(uint part_id);
-  int populate_partition_name_hash();
-  int get_partition_index(const char* partition_name);
 public:
 
   /*

--- 1.18/sql/sql_partition.cc	2005-12-26 03:53:40 -08:00
+++ 1.19/sql/sql_partition.cc	2006-01-16 16:50:32 -08:00
@@ -89,6 +89,18 @@
 uint32 get_partition_id_key_sub(partition_info *part_info); 
 uint32 get_partition_id_linear_hash_sub(partition_info *part_info); 
 uint32 get_partition_id_linear_key_sub(partition_info *part_info); 
+
+
+/*
+  for storing partition names, in order to check if partition exists for a table
+*/
+static byte *partition_names_get_key(partition_element *partition_element, uint *length,
+			       my_bool not_used __attribute__ ((unused)))
+{
+  *length= strlen(partition_element->partition_name);
+  return (byte *) partition_element->partition_name;
+}
+
 #endif
 
 
@@ -114,6 +126,134 @@
 }
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
+
+/*
+  Populate partition name hash
+
+  SYNOPSIS
+   populate_partition_name_hash()
+   (no parameters)
+
+  DESCRIPTION
+   This method will iterate over the list of partition elements and insert them
+   into a hash based on partition name.  This hash sits on the partition info object
+   but is used by the handler for determining if a partition specified in a query
+   actually exists.
+
+  RETURN
+   1 on error
+   0 if successful
+
+*/
+int populate_partition_name_hash(partition_info *m_part_info)
+{
+  List_iterator_fast <partition_element> part_it(m_part_info->partitions);
+
+  (void) hash_init(&(m_part_info->partition_names), system_charset_info, 32, 0, 0,
+                   (hash_get_key) partition_names_get_key, 0, 0);
+
+  int index= 0;
+  partition_element *el;
+  while ((el= part_it++) != NULL)
+  {
+    bool has_sub_parts= is_sub_partitioned(m_part_info);
+
+    if (! has_sub_parts)
+	    el->index= index++;
+    if (my_hash_insert(&(m_part_info->partition_names), (byte*)el))
+      return 1;
+    if (!has_sub_parts)
+      continue;
+    List_iterator_fast <partition_element> sub_part_it(el->subpartitions);
+    partition_element *subel;
+    while ((subel= sub_part_it++) != NULL)
+    {
+      subel->index= index++;
+      if (my_hash_insert(&(m_part_info->partition_names), (byte*)subel))
+        return 1;
+    }
+  }
+  return 0;
+}
+/*
+
+  Check if a partition name exists in the table
+
+  SYNOPSIS
+    set_specific_partition
+    partition_name - string of partition name
+
+  DESCRIPTION
+    This function takes the given partition name and checks it against the list
+    of partitions and subpartitions, setting the current_partition_index and
+    start_part equal to the chosen
+
+  RETURN
+    error code if error
+    0 if no partition exists
+*/
+int set_specific_partition(partition_info *m_part_info,
+                                         const char *partition_name)
+{
+  int error;
+  DBUG_ENTER("set_specific_partition");
+  partition_element *el= (partition_element*)hash_search(
+	                                 &(m_part_info->partition_names), 
+	                                 (byte*)partition_name, 
+									                  strlen(partition_name));
+  if (el == NULL)
+  {
+    error= my_error(ER_NO_SUCH_PARTITION, MYF(0), partition_name);
+    DBUG_RETURN(error);
+  }
+
+  DBUG_PRINT("info", ("selected partition %s is in table", partition_name));
+  bitmap_clear_all(&m_part_info->used_partitions);
+
+  if (is_sub_partitioned(m_part_info) && (el->subpartitions.elements > 0))
+  {
+    List_iterator<partition_element> sub_part_it(el->subpartitions);
+    partition_element *sub_el;
+    while ((sub_el= sub_part_it++) != NULL)
+    {
+      bitmap_set_bit(&(m_part_info->used_partitions), sub_el->index);
+    }
+  }
+  else
+    bitmap_set_bit(&(m_part_info->used_partitions), el->index);
+
+  DBUG_RETURN(0);
+}
+
+/*
+  Return numeric partition number given a partition name
+
+  SYNOPSIS
+    get_partition_index()
+    partition_name - string of partition name
+
+  DESCRIPTION
+   This method returns a partition number based on a given partition
+   name by keying the hash with that name, and then returning the
+   partition_element index.
+
+  RETURN
+   -1 if error
+   > 0 integer representing the index number
+*/
+int get_partition_index(partition_info *m_part_info,
+                        const char* partition_name)
+{
+  partition_element *el= (partition_element*)hash_search(
+                                         &(m_part_info->partition_names),
+	                                 (byte*)partition_name,
+                                         strlen(partition_name));
+  if (el == NULL)
+    return -1;
+  return el->index;
+}
+
+
 /*
   A support function to check if a partition name is in a list of strings
   SYNOPSIS
Thread
bk commit into 5.1 tree (patg:1.2020)Patrick Galbraith17 Jan