List:Commits« Previous MessageNext Message »
From:Mattias Jonsson Date:January 23 2009 10:01am
Subject:bzr commit into mysql-5.1-bugteam branch (mattias.jonsson:2750)
Bug#35111
View as plain text  
#At file:///Users/mattiasj/clones/bzrroot/b35111-51-bugteam/ based on revid:serge.kozlov@stripped

 2750 Mattias Jonsson	2009-01-23
      Bug#35111: Truncate a MyISAM partitioned table does not reset
      the auto_increment value
      
      Problem was that a non partitioned table just did recreate of the table,
      overwriting the previous table. But a partitioned table could not indicate
      if the partitioning engine (or the partitions engines) did support recreate
      or not.
      
      Solution was to extend the 'peek at the table' function (mysql_frm_type) to also
      look at the default engine used by the table, resulting in the same handling of
      partitioned as of non partitioned tables.
modified:
  mysql-test/suite/parts/r/partition_auto_increment_memory.result
  mysql-test/suite/parts/r/partition_auto_increment_myisam.result
  sql/ha_partition.cc
  sql/sql_base.cc
  sql/sql_delete.cc
  sql/sql_rename.cc
  sql/sql_show.cc
  sql/sql_table.cc
  sql/sql_view.cc
  sql/sql_view.h

per-file messages:
  mysql-test/suite/parts/r/partition_auto_increment_memory.result
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Update of result (now correct)
  mysql-test/suite/parts/r/partition_auto_increment_myisam.result
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Update of result (now correct)
  sql/ha_partition.cc
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    use of function instead of direct access to the current sql command
  sql/sql_base.cc
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Updated the mysql_frm_type function, and removed a unnecessary variable.
  sql/sql_delete.cc
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Updated the use of the mysql_frm_type function.
    If the table is partitioned, look at the default partition engine type
    if it supports recreate instead of the partitioning hton.
  sql/sql_rename.cc
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Updated the mysql_frm_type function.
  sql/sql_show.cc
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Updated the mysql_frm_type function, and removed a unnecessary variable.
  sql/sql_table.cc
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Updated the mysql_frm_type function.
  sql/sql_view.cc
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Updated the mysql_frm_type function to also return the default table type for
    partitions if the table is partitioned.
    And removed a unnecessary variable.
  sql/sql_view.h
    Bug#35111: Truncate a MyISAM partitioned table does not reset
    the auto_increment value
    
    Updated the mysql_frm_type function.
=== modified file 'mysql-test/suite/parts/r/partition_auto_increment_memory.result'
--- a/mysql-test/suite/parts/r/partition_auto_increment_memory.result	2008-11-05 20:13:54 +0000
+++ b/mysql-test/suite/parts/r/partition_auto_increment_memory.result	2009-01-23 10:01:12 +0000
@@ -377,12 +377,12 @@ Table	Create Table
 t1	CREATE TABLE `t1` (
   `c1` int(11) NOT NULL AUTO_INCREMENT,
   PRIMARY KEY (`c1`)
-) ENGINE=MEMORY AUTO_INCREMENT=28 DEFAULT CHARSET=latin1
+) ENGINE=MEMORY AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY HASH (c1)
 PARTITIONS 2 */
 SELECT * FROM t1 ORDER BY c1;
 c1
-27
+1
 INSERT INTO t1 VALUES (100);
 INSERT INTO t1 VALUES (NULL);
 DELETE FROM t1 WHERE c1 >= 100;

=== modified file 'mysql-test/suite/parts/r/partition_auto_increment_myisam.result'
--- a/mysql-test/suite/parts/r/partition_auto_increment_myisam.result	2008-11-05 20:13:54 +0000
+++ b/mysql-test/suite/parts/r/partition_auto_increment_myisam.result	2009-01-23 10:01:12 +0000
@@ -377,12 +377,12 @@ Table	Create Table
 t1	CREATE TABLE `t1` (
   `c1` int(11) NOT NULL AUTO_INCREMENT,
   PRIMARY KEY (`c1`)
-) ENGINE=MyISAM AUTO_INCREMENT=28 DEFAULT CHARSET=latin1
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY HASH (c1)
 PARTITIONS 2 */
 SELECT * FROM t1 ORDER BY c1;
 c1
-27
+1
 INSERT INTO t1 VALUES (100);
 INSERT INTO t1 VALUES (NULL);
 DELETE FROM t1 WHERE c1 >= 100;

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2009-01-07 22:30:10 +0000
+++ b/sql/ha_partition.cc	2009-01-23 10:01:12 +0000
@@ -3183,7 +3183,7 @@ int ha_partition::delete_all_rows()
   THD *thd= ha_thd();
   DBUG_ENTER("ha_partition::delete_all_rows");
 
-  if (thd->lex->sql_command == SQLCOM_TRUNCATE)
+  if (thd_sql_command(thd) == SQLCOM_TRUNCATE)
   {
     HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
     lock_auto_increment();
@@ -6185,7 +6185,7 @@ void ha_partition::get_auto_increment(ul
       is done.
     */
     if (!auto_increment_safe_stmt_log_lock &&
-        thd->lex->sql_command != SQLCOM_INSERT &&
+        thd_sql_command(thd) != SQLCOM_INSERT &&
         mysql_bin_log.is_open() &&
         !thd->current_stmt_binlog_row_based &&
         (thd->options & OPTION_BIN_LOG))

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2009-01-07 12:11:37 +0000
+++ b/sql/sql_base.cc	2009-01-23 10:01:12 +0000
@@ -2676,10 +2676,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *
     */
     {
       char path[FN_REFLEN];
-      enum legacy_db_type not_used;
       build_table_filename(path, sizeof(path) - 1,
                            table_list->db, table_list->table_name, reg_ext, 0);
-      if (mysql_frm_type(thd, path, &not_used) == FRMTYPE_VIEW)
+      if (mysql_frm_type(thd, path, NULL, NULL) == FRMTYPE_VIEW)
       {
         /*
           Will not be used (because it's VIEW) but has to be passed.

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2009-01-09 10:20:32 +0000
+++ b/sql/sql_delete.cc	2009-01-23 10:01:12 +0000
@@ -997,6 +997,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST
   {
     handlerton *table_type= table->s->db_type();
     TABLE_SHARE *share= table->s;
+    /* a temporary table cannot be partitioned */
     if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
       goto trunc_by_del;
 
@@ -1024,15 +1025,22 @@ bool mysql_truncate(THD *thd, TABLE_LIST
 
   if (!dont_send_ok)
   {
-    enum legacy_db_type table_type;
-    mysql_frm_type(thd, path, &table_type);
+    enum legacy_db_type table_type, part_type;
+    mysql_frm_type(thd, path, &table_type, &part_type);
     if (table_type == DB_TYPE_UNKNOWN)
     {
       my_error(ER_NO_SUCH_TABLE, MYF(0),
                table_list->db, table_list->table_name);
       DBUG_RETURN(TRUE);
     }
-    if (!ha_check_storage_engine_flag(ha_resolve_by_legacy_type(thd, table_type),
+    /*
+      The partition handler it self supports recreate, so if partitioned, look
+      at the type of engine used by the partitions.
+    */
+    if (table_type == DB_TYPE_PARTITION_DB)
+      table_type= part_type;
+    if (!ha_check_storage_engine_flag(ha_resolve_by_legacy_type(thd,
+                                                                table_type),
                                       HTON_CAN_RECREATE))
       goto trunc_by_del;
 

=== modified file 'sql/sql_rename.cc'
--- a/sql/sql_rename.cc	2008-02-19 12:45:21 +0000
+++ b/sql/sql_rename.cc	2009-01-23 10:01:12 +0000
@@ -271,7 +271,7 @@ do_rename(THD *thd, TABLE_LIST *ren_tabl
   build_table_filename(name, sizeof(name),
                        ren_table->db, old_alias, reg_ext, 0);
 
-  frm_type= mysql_frm_type(thd, name, &table_type);
+  frm_type= mysql_frm_type(thd, name, &table_type, NULL);
   switch (frm_type)
   {
     case FRMTYPE_TABLE:

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2009-01-05 18:47:28 +0000
+++ b/sql/sql_show.cc	2009-01-23 10:01:12 +0000
@@ -2966,11 +2966,10 @@ static int fill_schema_table_names(THD *
   }
   else
   {
-    enum legacy_db_type not_used;
     char path[FN_REFLEN];
     (void) build_table_filename(path, sizeof(path), db_name->str, 
                                 table_name->str, reg_ext, 0);
-    switch (mysql_frm_type(thd, path, &not_used)) {
+    switch (mysql_frm_type(thd, path, NULL, NULL)) {
     case FRMTYPE_ERROR:
       table->field[3]->store(STRING_WITH_LEN("ERROR"),
                              system_charset_info);

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-01-14 14:50:51 +0000
+++ b/sql/sql_table.cc	2009-01-23 10:01:12 +0000
@@ -1700,7 +1700,7 @@ int mysql_rm_table_part2(THD *thd, TABLE
          (access(path, F_OK) &&
           ha_create_table_from_engine(thd, db, alias)) ||
          (!drop_view &&
-          mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE)))
+          mysql_frm_type(thd, path, &frm_db_type, NULL) != FRMTYPE_TABLE)))
     {
       // Table was not found on disk and table can't be created from engine
       if (if_exists)
@@ -1715,7 +1715,7 @@ int mysql_rm_table_part2(THD *thd, TABLE
       char *end;
       if (table_type == NULL)
       {
-	mysql_frm_type(thd, path, &frm_db_type);
+	mysql_frm_type(thd, path, &frm_db_type, NULL);
         table_type= ha_resolve_by_legacy_type(thd, frm_db_type);
       }
       // Remove extension for delete
@@ -6125,7 +6125,7 @@ bool mysql_alter_table(THD *thd,char *ne
     into the main table list, like open_tables does).
     This code is wrong and will be removed, please do not copy.
   */
-  frm_type= mysql_frm_type(thd, new_name_buff, &table_type);
+  frm_type= mysql_frm_type(thd, new_name_buff, &table_type, NULL);
   /* Rename a view */
   /* Sic: there is a race here */
   if (frm_type == FRMTYPE_VIEW && !(alter_info->flags & ~ALTER_RENAME))

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2009-01-15 18:11:25 +0000
+++ b/sql/sql_view.cc	2009-01-23 10:01:12 +0000
@@ -1562,7 +1562,6 @@ bool mysql_drop_view(THD *thd, TABLE_LIS
   String non_existant_views;
   char *wrong_object_db= NULL, *wrong_object_name= NULL;
   bool error= FALSE;
-  enum legacy_db_type not_used;
   bool some_views_deleted= FALSE;
   bool something_wrong= FALSE;
   DBUG_ENTER("mysql_drop_view");
@@ -1576,7 +1575,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIS
                          view->db, view->table_name, reg_ext, 0);
 
     if (access(path, F_OK) || 
-        FRMTYPE_VIEW != (type= mysql_frm_type(thd, path, &not_used)))
+        FRMTYPE_VIEW != (type= mysql_frm_type(thd, path, NULL, NULL)))
     {
       char name[FN_REFLEN];
       my_snprintf(name, sizeof(name), "%s.%s", view->db, view->table_name);
@@ -1660,7 +1659,10 @@ bool mysql_drop_view(THD *thd, TABLE_LIS
 
   SYNOPSIS
     mysql_frm_type()
-    path	path to file
+    thd         THD
+    path        path to file
+    dbt         table type
+    pdbt        default table type for partitions
 
   RETURN
     FRMTYPE_ERROR	error
@@ -1668,14 +1670,23 @@ bool mysql_drop_view(THD *thd, TABLE_LIS
     FRMTYPE_VIEW	view
 */
 
-frm_type_enum mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
+frm_type_enum mysql_frm_type(THD *thd, char *path,
+                             enum legacy_db_type *dbt,
+                             enum legacy_db_type *pdbt)
 {
   File file;
-  uchar header[10];	//"TYPE=VIEW\n" it is 10 characters
+  /*
+    "TYPE=VIEW\n" it is 10 characters, default engine type for partitions
+    is in [61]
+  */
+  uchar header[62];
   int error;
   DBUG_ENTER("mysql_frm_type");
 
-  *dbt= DB_TYPE_UNKNOWN;
+  if (dbt)
+    (*dbt)= DB_TYPE_UNKNOWN;
+  if (pdbt)
+    (*pdbt)= DB_TYPE_UNKNOWN;
 
   if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)
     DBUG_RETURN(FRMTYPE_ERROR);
@@ -1692,12 +1703,15 @@ frm_type_enum mysql_frm_type(THD *thd, c
     if the following test is true (arg #3). This should not have effect
     on return value from this function (default FRMTYPE_TABLE)
   */
-  if (header[0] != (uchar) 254 || header[1] != 1 ||
+  if (!dbt || header[0] != (uchar) 254 || header[1] != 1 ||
       (header[2] != FRM_VER && header[2] != FRM_VER+1 &&
        (header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
     DBUG_RETURN(FRMTYPE_TABLE);
 
-  *dbt= (enum legacy_db_type) (uint) *(header + 3);
+  (*dbt)= (enum legacy_db_type) *(header + 3);
+
+  if ((*dbt) == DB_TYPE_PARTITION_DB && pdbt)
+    (*pdbt)= (enum legacy_db_type) *(header + 61);
   DBUG_RETURN(FRMTYPE_TABLE);                   // Is probably a .frm table
 }
 

=== modified file 'sql/sql_view.h'
--- a/sql/sql_view.h	2008-02-22 01:21:52 +0000
+++ b/sql/sql_view.h	2009-01-23 10:01:12 +0000
@@ -30,7 +30,9 @@ bool check_key_in_view(THD *thd, TABLE_L
 
 bool insert_view_fields(THD *thd, List<Item> *list, TABLE_LIST *view);
 
-frm_type_enum mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt);
+frm_type_enum mysql_frm_type(THD *thd, char *path,
+                             enum legacy_db_type *dbt,
+                             enum legacy_db_type *pdbt);
 
 int view_checksum(THD *thd, TABLE_LIST *view);
 

Thread
bzr commit into mysql-5.1-bugteam branch (mattias.jonsson:2750)Bug#35111Mattias Jonsson23 Jan