List:Internals« Previous MessageNext Message »
From:mikael Date:September 19 2005 5:53am
Subject:bk commit into 5.1 tree (mronstrom:1.2017)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 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.2017 05/09/19 07:53:33 mronstrom@stripped +12 -0
  WL 2604: Partition Management
  Fix defaults in frm file

  sql/table.cc
    1.177 05/09/19 07:53:22 mronstrom@stripped +5 -3
    Fix defaults in frm file

  sql/sql_yacc.yy
    1.378 05/09/19 07:53:22 mronstrom@stripped +5 -1
    Fix defaults in frm file

  sql/sql_table.cc
    1.237 05/09/19 07:53:21 mronstrom@stripped +3 -3
    Fix defaults in frm file

  sql/sql_show.cc
    1.265 05/09/19 07:53:21 mronstrom@stripped +1 -1
    Fix defaults in frm file

  sql/sql_partition.cc
    1.10 05/09/19 07:53:21 mronstrom@stripped +123 -72
    Fix defaults in frm file

  sql/sql_base.cc
    1.274 05/09/19 07:53:21 mronstrom@stripped +3 -3
    Fix defaults in frm file

  sql/mysql_priv.h
    1.305 05/09/19 07:53:20 mronstrom@stripped +2 -1
    Fix defaults in frm file

  sql/handler.h
    1.149 05/09/19 07:53:20 mronstrom@stripped +9 -4
    Fix defaults in frm file

  sql/handler.cc
    1.156 05/09/19 07:53:20 mronstrom@stripped +2 -2
    Fix defaults in frm file

  sql/ha_partition.h
    1.5 05/09/19 07:53:20 mronstrom@stripped +1 -0
    Fix defaults in frm file

  sql/ha_ndbcluster.h
    1.81 05/09/19 07:53:20 mronstrom@stripped +1 -0
    Fix defaults in frm file

  sql/ha_ndbcluster.cc
    1.155 05/09/19 07:53:19 mronstrom@stripped +4 -0
    Fix defaults in frm file

# 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:	c-e409e253.1238-1-64736c10.cust.bredbandsbolaget.se
# Root:	/Users/mikron/wl2498

--- 1.155/sql/handler.cc	2005-09-14 15:58:26 +02:00
+++ 1.156/sql/handler.cc	2005-09-19 07:53:20 +02:00
@@ -2061,7 +2061,7 @@
   char name_buff[FN_REFLEN];
   DBUG_ENTER("ha_create_table");
 
-  if (openfrm(current_thd, name,"",0,(uint) READ_ALL, 0, &table))
+  if (openfrm(current_thd, name,"",0,(uint) READ_ALL, 0, &table, TRUE))
     DBUG_RETURN(1);
   if (update_create_info)
   {
@@ -2126,7 +2126,7 @@
   if (error)
     DBUG_RETURN(2);
 
-  if (openfrm(thd, path,"",0,(uint) READ_ALL, 0, &table))
+  if (openfrm(thd, path,"",0,(uint) READ_ALL, 0, &table, FALSE))
     DBUG_RETURN(3);
 
   update_create_info_from_table(&create_info, &table);

--- 1.148/sql/handler.h	2005-09-17 12:15:44 +02:00
+++ 1.149/sql/handler.h	2005-09-19 07:53:20 +02:00
@@ -538,6 +538,7 @@
   bool use_default_partitions;
   bool use_default_no_partitions;
   bool use_default_subpartitions;
+  bool use_default_no_subpartitions;
   bool defined_max_value;
   bool list_of_part_fields;
   bool list_of_subpart_fields;
@@ -563,7 +564,9 @@
     no_full_part_fields(0), linear_hash_mask(0),
     use_default_partitions(TRUE),
     use_default_no_partitions(TRUE),
-    use_default_subpartitions(TRUE), defined_max_value(FALSE),
+    use_default_subpartitions(TRUE),
+    use_default_no_subpartitions(TRUE),
+    defined_max_value(FALSE),
     list_of_part_fields(FALSE), list_of_subpart_fields(FALSE),
     linear_hash_ind(FALSE)
   {
@@ -682,10 +685,11 @@
                         partition_info *part_info, uint32 *part_id);
 bool check_partition_info(partition_info *part_info,enum db_type eng_type,
                           handler *file, ulonglong max_rows);
-bool fix_partition_func(THD *thd, const char *name, TABLE *table);
+bool fix_partition_func(THD *thd, const char *name, TABLE *table,
+                        bool create_table_ind);
 char *generate_partition_syntax(partition_info *part_info,
                                 uint *buf_length, bool use_sql_alloc,
-                                bool write_part_state);
+                                bool write_part_state, bool write_all);
 bool partition_key_modified(TABLE *table, List<Item> &fields);
 void get_partition_set(const TABLE *table, byte *buf, const uint index,
                        const key_range *key_spec,
@@ -695,7 +699,7 @@
                                const key_range *key_spec,
                                part_id_range *part_spec);
 bool mysql_unpack_partition(File file, THD *thd, uint part_info_len,
-                            TABLE *table);
+                            TABLE *table, bool create_table_ind);
 #endif
 
 
@@ -1303,6 +1307,7 @@
 
   virtual bool is_auto_partitioned() { return FALSE; }
   virtual void set_auto_partitions(partition_info *part_info) { return; }
+  virtual uint get_no_parts() { return 0; }
 #endif
   virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
   virtual ulong index_ddl_flags(KEY *wanted_index) const

--- 1.304/sql/mysql_priv.h	2005-09-16 08:40:42 +02:00
+++ 1.305/sql/mysql_priv.h	2005-09-19 07:53:20 +02:00
@@ -1356,7 +1356,8 @@
 int format_number(uint inputflag,uint max_length,my_string pos,uint length,
 		  my_string *errpos);
 int openfrm(THD *thd, const char *name,const char *alias,uint filestat,
-            uint prgflag, uint ha_open_flags, TABLE *outparam);
+            uint prgflag, uint ha_open_flags, TABLE *outparam,
+            bool create_table_ind);
 int readfrm(const char *name, const void** data, uint* length);
 int writefrm(const char* name, const void* data, uint len);
 int closefrm(TABLE *table);

--- 1.273/sql/sql_base.cc	2005-09-13 15:53:15 +02:00
+++ 1.274/sql/sql_base.cc	2005-09-19 07:53:21 +02:00
@@ -1721,7 +1721,7 @@
 			         HA_GET_INDEX | HA_TRY_READ_ONLY |
                                  NO_ERR_ON_NEW_FRM),
 		      READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
-		      thd->open_options, entry)) &&
+		      thd->open_options, entry, FALSE)) &&
       (error != 5 ||
        (fn_format(path, path, 0, reg_ext, MY_UNPACK_FILENAME),
         open_new_frm(path, alias, db, name,
@@ -1787,7 +1787,7 @@
 			 HA_TRY_READ_ONLY),
 		READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
 		ha_open_options | HA_OPEN_FOR_REPAIR,
-		entry) || ! entry->file ||
+		entry, FALSE) || ! entry->file ||
 	(entry->file->is_crashed() && entry->file->check_and_repair(thd)))
     {
       /* Give right error message */
@@ -2491,7 +2491,7 @@
 	      (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX),
 	      READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
 	      ha_open_options,
-	      tmp_table))
+	      tmp_table, FALSE))
   {
     my_free((char*) tmp_table,MYF(0));
     DBUG_RETURN(0);

--- 1.264/sql/sql_show.cc	2005-09-13 14:24:59 +02:00
+++ 1.265/sql/sql_show.cc	2005-09-19 07:53:21 +02:00
@@ -1057,7 +1057,7 @@
     if (table->s->part_info &&
         ((part_syntax= generate_partition_syntax(table->s->part_info,
                                                   &part_syntax_len,
-                                                  FALSE, FALSE))))
+                                                  FALSE, FALSE, FALSE))))
     {
        packet->append(part_syntax, part_syntax_len);
        my_free(part_syntax, MYF(0));

--- 1.236/sql/sql_table.cc	2005-09-17 12:15:44 +02:00
+++ 1.237/sql/sql_table.cc	2005-09-19 07:53:21 +02:00
@@ -126,7 +126,7 @@
     {
       if (!(part_syntax_buf= generate_partition_syntax(part_info,
                                                        &syntax_len,
-                                                       TRUE, TRUE)))
+                                                       TRUE, TRUE, FALSE)))
       {
         DBUG_RETURN(TRUE);
       }
@@ -1721,7 +1721,7 @@
     */
     if (!(part_syntax_buf= generate_partition_syntax(part_info,
                                                      &syntax_len,
-                                                     TRUE, FALSE)))
+                                                     TRUE, FALSE, FALSE)))
       DBUG_RETURN(TRUE);
     part_info->part_info_string= part_syntax_buf;
     part_info->part_info_len= syntax_len;
@@ -2235,7 +2235,7 @@
     char name[FN_REFLEN];
     build_table_path(name, sizeof(name), table_list->db,
                      table_list->table_name, "");
-    if (openfrm(thd, name, "", 0, 0, 0, &tmp_table))
+    if (openfrm(thd, name, "", 0, 0, 0, &tmp_table, FALSE))
       DBUG_RETURN(0);				// Can't open frm file
     table= &tmp_table;
   }

--- 1.377/sql/sql_yacc.yy	2005-09-17 12:15:44 +02:00
+++ 1.378/sql/sql_yacc.yy	2005-09-19 07:53:22 +02:00
@@ -3191,12 +3191,14 @@
         | SUBPARTITIONS_SYM ulong_num
         {
           uint no_parts= $2;
+          LEX *lex= Lex;
           if (no_parts == 0)
           {
             my_error(ER_NO_PARTS_ERROR, MYF(0), "subpartitions");
             YYABORT;
           }
-          Lex->part_info->no_subparts= no_parts;
+          lex->part_info->no_subparts= no_parts;
+          lex->part_info->use_default_no_subpartitions= FALSE;
         }
         ;
 
@@ -3244,6 +3246,7 @@
           part_info->curr_part_elem= p_elem;
           part_info->current_partition= p_elem;
           part_info->use_default_partitions= FALSE;
+          part_info->use_default_no_partitions= FALSE;
           p_elem->engine_type= DB_TYPE_UNKNOWN;
           part_info->count_curr_parts++;
         }
@@ -3535,6 +3538,7 @@
           }
           part_info->curr_part_elem= p_elem;
           part_info->use_default_subpartitions= FALSE;
+          part_info->use_default_no_subpartitions= FALSE;
           part_info->count_curr_subparts++;
           p_elem->engine_type= DB_TYPE_UNKNOWN;
         }

--- 1.176/sql/table.cc	2005-09-06 09:11:51 +02:00
+++ 1.177/sql/table.cc	2005-09-19 07:53:22 +02:00
@@ -63,7 +63,8 @@
 */
 
 int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
-            uint prgflag, uint ha_open_flags, TABLE *outparam)
+            uint prgflag, uint ha_open_flags, TABLE *outparam,
+            bool create_table_ind)
 {
   reg1 uint i;
   reg2 uchar *strpos;
@@ -436,7 +437,8 @@
   if (part_info_len > 0)
   {
 #ifdef HAVE_PARTITION_DB
-    if (mysql_unpack_partition(file, thd, part_info_len, outparam)) 
+    if (mysql_unpack_partition(file, thd, part_info_len,
+                               outparam, create_table_ind)) 
       goto err;
 #else
     goto err;
@@ -872,7 +874,7 @@
   /* Fix the partition functions and ensure they are not constant functions*/
   if (part_info_len > 0)
 #ifdef HAVE_PARTITION_DB
-    if (fix_partition_func(thd,name,outparam))
+    if (fix_partition_func(thd,name,outparam, create_table_ind))
 #endif
       goto err;
   

--- 1.154/sql/ha_ndbcluster.cc	2005-09-17 12:15:43 +02:00
+++ 1.155/sql/ha_ndbcluster.cc	2005-09-19 07:53:19 +02:00
@@ -7788,4 +7788,8 @@
   DBUG_RETURN(0);
 }
 
+uint ha_ndbcluster::get_no_parts()
+{
+  return 0;
+}
 #endif /* HAVE_NDBCLUSTER_DB */

--- 1.80/sql/ha_ndbcluster.h	2005-09-17 12:15:43 +02:00
+++ 1.81/sql/ha_ndbcluster.h	2005-09-19 07:53:20 +02:00
@@ -528,6 +528,7 @@
   int create(const char *name, TABLE *form, HA_CREATE_INFO *info);
   int get_default_no_partitions(ulonglong max_rows);
   bool is_auto_partitioned() { return TRUE; }
+  uint get_no_parts();
   void set_auto_partitions(partition_info *part_info);
   int change_partitions(HA_CREATE_INFO *create_info,
                         const char *path,

--- 1.4/sql/ha_partition.h	2005-09-16 08:40:42 +02:00
+++ 1.5/sql/ha_partition.h	2005-09-19 07:53:20 +02:00
@@ -179,6 +179,7 @@
                                 uint pack_frm_len);
   virtual int drop_partitions(const char *path);
   virtual int rename_partitions(const char *path);
+  uint get_no_parts() { return m_tot_parts; }
 private:
   int copy_partitions(ulonglong *copied, ulonglong *deleted);
   void handler_cleanup(uint part_count);

--- 1.9/sql/sql_partition.cc	2005-09-17 12:15:44 +02:00
+++ 1.10/sql/sql_partition.cc	2005-09-19 07:53:21 +02:00
@@ -1662,7 +1662,8 @@
     TABLE_LIST object for use in fix_fields.
 */
 
-bool fix_partition_func(THD *thd, const char* name, TABLE *table)
+bool fix_partition_func(THD *thd, const char* name, TABLE *table,
+                        bool create_table_ind)
 {
   bool result= TRUE;
   uint dir_length, home_dir_length;
@@ -1675,6 +1676,20 @@
   DBUG_ENTER("fix_partition_func");
 
   thd->set_query_id= 0;
+  if (!create_table_ind)
+  {
+    /*
+      Default handling postponed from mysql_unpack_partition.
+    */
+    if (part_info->use_default_no_partitions)
+      part_info->no_parts= table->file->get_no_parts();
+    else if (part_info->use_default_no_subpartitions)
+      part_info->no_subparts= table->file->get_no_parts() /
+                              part_info->no_parts;
+      DBUG_ASSERT((table->file->get_no_parts() % part_info->no_parts) == 0);
+    set_up_defaults_for_partitioning(part_info, table->file,
+                                     (ulonglong)0, (uint)0);
+  }
   /*
   Set-up the TABLE_LIST object to be a list with a single table
   Set the object to zero to create NULL pointers and set alias
@@ -2080,7 +2095,8 @@
 char *generate_partition_syntax(partition_info *part_info,
                                 uint *buf_length,
                                 bool use_sql_alloc,
-                                bool write_part_state)
+                                bool write_part_state,
+                                bool write_all)
 {
   uint i,j, tot_no_parts, no_subparts, no_parts;
   partition_element *part_elem, *save_part_elem= NULL;
@@ -2136,6 +2152,12 @@
                          part_info->part_func_len);
   err+= add_end_parenthesis(fptr);
   err+= add_space(fptr);
+  if (!part_info->use_default_no_partitions)
+  {
+    err+= add_string(fptr, "PARTITIONS ");
+    err+= add_int(fptr, part_info->no_parts);
+    err+= add_space(fptr);
+  }
   if (is_sub_partitioned(part_info))
   {
     err+= add_subpartition_by(fptr);
@@ -2149,99 +2171,109 @@
                            part_info->subpart_func_len);
     err+= add_end_parenthesis(fptr);
     err+= add_space(fptr);
+    if (!part_info->use_default_no_subpartitions)
+    {
+      err+= add_string(fptr, "SUBPARTITIONS ");
+      err+= add_int(fptr, part_info->no_subparts);
+      err+= add_space(fptr);
+    }
   }
   err+= add_begin_parenthesis(fptr);
   no_parts= part_info->no_parts;
   tot_no_parts= no_parts + no_temp_parts;
   no_subparts= part_info->no_subparts;
 
-  i= 0;
-  do
+  if (write_all || (!part_info->use_default_partitions))
   {
-    /*
-      We need to do some clever list manipulation here since we have two
-      different needs for our list processing and here we take some of the
-      cost of using a simpler list processing for the other parts of the
-      code.
-
-      ALTER TABLE REORGANISE PARTITIONS has the list of partitions to be
-      the final list as the main list and the reorganised partitions is in
-      the temporary partition list. Thus when finding the first part added
-      we insert the temporary list if there is such a list. If there is no
-      temporary list we are performing an ADD PARTITION.
-    */
-    if (use_temp && use_temp <= no_temp_parts)
-    {
-      part_elem= temp_it++;
-      DBUG_ASSERT(no_temp_parts);
-      no_temp_parts--;
-    }
-    else if (use_temp)
-    {
-      DBUG_ASSERT(no_parts);
-      part_elem= save_part_elem;
-      use_temp= 0;
-      no_parts--;
-    }
-    else
+    i= 0;
+    do
     {
-      part_elem= part_it++;
-      if (part_elem->part_state == PART_TO_BE_ADDED && no_temp_parts)
+      /*
+        We need to do some clever list manipulation here since we have two
+        different needs for our list processing and here we take some of the
+        cost of using a simpler list processing for the other parts of the
+        code.
+
+        ALTER TABLE REORGANISE PARTITIONS has the list of partitions to be
+        the final list as the main list and the reorganised partitions is in
+        the temporary partition list. Thus when finding the first part added
+        we insert the temporary list if there is such a list. If there is no
+        temporary list we are performing an ADD PARTITION.
+      */
+      if (use_temp && use_temp <= no_temp_parts)
       {
-        save_part_elem= part_elem;
         part_elem= temp_it++;
+        DBUG_ASSERT(no_temp_parts);
         no_temp_parts--;
-        use_temp= 1;
       }
-      else
+      else if (use_temp)
       {
         DBUG_ASSERT(no_parts);
+        part_elem= save_part_elem;
+        use_temp= 0;
         no_parts--;
       }
-    }
+      else
+      {
+        part_elem= part_it++;
+        if (part_elem->part_state == PART_TO_BE_ADDED && no_temp_parts)
+        {
+          save_part_elem= part_elem;
+          part_elem= temp_it++;
+          no_temp_parts--;
+          use_temp= 1;
+        }
+        else
+        {
+          DBUG_ASSERT(no_parts);
+          no_parts--;
+        }
+      }
 
-    if (part_elem->part_state != PART_IS_DROPPED)
-    {
-      err+= add_partition(fptr);
-      err+= add_string(fptr, part_elem->partition_name);
-      err+= add_space(fptr);
-      if (write_part_state)
-        err+= add_partition_state(fptr, part_elem);
-      err+= add_partition_values(fptr, part_info, part_elem);
-      if (!is_sub_partitioned(part_info))
-        err+= add_partition_options(fptr, part_elem);
-      if (is_sub_partitioned(part_info))
+      if (part_elem->part_state != PART_IS_DROPPED)
       {
+        err+= add_partition(fptr);
+        err+= add_string(fptr, part_elem->partition_name);
         err+= add_space(fptr);
-        err+= add_begin_parenthesis(fptr);
-        List_iterator<partition_element> sub_it(part_elem->subpartitions);
-        j= 0;
-        do
+        if (write_part_state)
+          err+= add_partition_state(fptr, part_elem);
+        err+= add_partition_values(fptr, part_info, part_elem);
+        if (!is_sub_partitioned(part_info))
+          err+= add_partition_options(fptr, part_elem);
+        if (is_sub_partitioned(part_info) &&
+            (write_all || (!part_info->use_default_subpartitions)))
         {
-          part_elem= sub_it++;
-          err+= add_subpartition(fptr);
-          err+= add_string(fptr, part_elem->partition_name);
           err+= add_space(fptr);
-          err+= add_partition_options(fptr, part_elem);
-          if (j != (no_subparts-1))
+          err+= add_begin_parenthesis(fptr);
+          List_iterator<partition_element> sub_it(part_elem->subpartitions);
+          j= 0;
+          do
           {
-            err+= add_comma(fptr);
+            part_elem= sub_it++;
+            err+= add_subpartition(fptr);
+            err+= add_string(fptr, part_elem->partition_name);
             err+= add_space(fptr);
-          }
-          else
-            err+= add_end_parenthesis(fptr);
-        } while (++j < no_subparts);
-      }
-      if (i != (tot_no_parts-1))
-      {
-        err+= add_comma(fptr);
-        err+= add_space(fptr);
+            err+= add_partition_options(fptr, part_elem);
+            if (j != (no_subparts-1))
+            {
+              err+= add_comma(fptr);
+              err+= add_space(fptr);
+            }
+            else
+              err+= add_end_parenthesis(fptr);
+          } while (++j < no_subparts);
+        }
+        if (i != (tot_no_parts-1))
+        {
+          err+= add_comma(fptr);
+          err+= add_space(fptr);
+        }
       }
-    }
-    if (i == (tot_no_parts-1))
-      err+= add_end_parenthesis(fptr);
-  } while (++i < tot_no_parts);
-  DBUG_ASSERT(!no_parts && !no_temp_parts);
+      if (i == (tot_no_parts-1))
+        err+= add_end_parenthesis(fptr);
+    } while (++i < tot_no_parts);
+    DBUG_ASSERT(!no_parts && !no_temp_parts);
+  }
   if (err)
     goto close_file;
   buffer_length= my_seek(fptr, 0L,MY_SEEK_END,MYF(0));
@@ -3221,7 +3253,7 @@
 */
 
 bool mysql_unpack_partition(File file, THD *thd, uint part_info_len,
-                            TABLE* table)
+                            TABLE* table, bool create_table_ind)
 {
   Item *thd_free_list= thd->free_list;
   bool result= TRUE;
@@ -3258,7 +3290,26 @@
     free_items(thd->free_list);
     goto end;
   }
+  /*
+    The parsed syntax residing in the frm file can still contain defaults.
+    The reason is that the frm file is sometimes saved outside of this
+    MySQL Server and used in backup and restore of clusters or partitioned
+    tables. It is not certain that the restore will restore exactly the
+    same default partitioning.
+    
+    The easiest manner of handling this is to simply continue using the
+    part_info we already built up during mysql_create_table if we are
+    in the process of creating a table. If the table already exists we
+    need to discover the number of partitions for the default parts. Since
+    the handler object hasn't been created here yet we need to postpone this
+    to the fix_partition_func method.
+
+  */
   part_info= lex.part_info;
+  if (create_table_ind)
+  {
+    part_info= old_lex->part_info;
+  }
   table->s->part_info= part_info;
   part_info->item_free_list= thd->free_list;
 
Thread
bk commit into 5.1 tree (mronstrom:1.2017)mikael22 Sep