Bug #39399 Maria: ALTER TABLE renaming column: affected_rows <> from MyISAM
Submitted: 11 Sep 2008 14:03 Modified: 9 Jan 2009 15:29
Reporter: Guilhem Bichot Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Maria storage engine Severity:S3 (Non-critical)
Version:5.1 maria OS:Linux
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[11 Sep 2008 14:03] Guilhem Bichot
Description:
Put this in a .test file:
CREATE TABLE t1 (id int, c varchar(10));
INSERT INTO t1 VALUES (1,"1");
--enable_info
ALTER TABLE t1 CHANGE c d varchar(10);
With a MyISAM table, the ALTER gives:
affected rows: 0
info: Records: 0  Duplicates: 0  Warnings: 0
but with a Maria table:
affected rows: 1
info: Records: 1  Duplicates: 0  Warnings: 0
Happens in:
./mtr --mem --mysqld=--default-storage-engine=maria alter_table
Is it that Maria does a table rebuild where MyISAM doesn't? I counted my_rename() calls:
with MyISAM: 1 (frm)
with Maria : 6 (frm+MAI+MAD)
and this is not normal.

How to repeat:
see description
[23 Sep 2008 9:28] Guilhem Bichot
There are functions in sql_table.cc which decide if a full table rebuild is needed or not.
Before Sanja fixes this, Guilhem should update Maria with 6.0-specific MyISAM changes.
[26 Sep 2008 14:59] Oleksandr Byelkin
=== modified file 'storage/maria/ha_maria.cc'
--- storage/maria/ha_maria.cc	2008-08-28 18:52:23 +0000
+++ storage/maria/ha_maria.cc	2008-09-26 14:05:26 +0000
@@ -2825,15 +2825,15 @@
   if (create_info->auto_increment_value != stats.auto_increment_value ||
       create_info->data_file_name != data_file_name ||
       create_info->index_file_name != index_file_name ||
-      (maria_row_type(create_info,  1) != data_file_type &&
+      (maria_row_type(create_info,  0) != data_file_type &&
        create_info->row_type != ROW_TYPE_DEFAULT) ||
       table_changes == IS_EQUAL_NO ||
       table_changes & IS_EQUAL_PACK_LENGTH) // Not implemented yet
     return COMPATIBLE_DATA_NO;
 
-  if ((options & (HA_OPTION_PACK_RECORD | HA_OPTION_CHECKSUM |
+  if ((options & (HA_OPTION_CHECKSUM |
                   HA_OPTION_DELAY_KEY_WRITE)) !=
-      (create_info->table_options & (HA_OPTION_PACK_RECORD | HA_OPTION_CHECKSUM |
+      (create_info->table_options & (HA_OPTION_CHECKSUM |
                               HA_OPTION_DELAY_KEY_WRITE)))
     return COMPATIBLE_DATA_NO;
   return COMPATIBLE_DATA_YES;
[26 Sep 2008 15:04] Oleksandr Byelkin
=== modified file 'storage/maria/ha_maria.cc'
--- storage/maria/ha_maria.cc	2008-08-28 18:52:23 +0000
+++ storage/maria/ha_maria.cc	2008-09-26 15:02:28 +0000
@@ -2605,10 +2605,9 @@
 }
 
 
-static enum data_file_type maria_row_type(HA_CREATE_INFO *info,
-                                          my_bool ignore_transactional)
+static enum data_file_type maria_row_type(HA_CREATE_INFO *info)
 {
-  if (info->transactional == HA_CHOICE_YES && ! ignore_transactional)
+  if (info->transactional == HA_CHOICE_YES)
     return BLOCK_RECORD;
   switch (info->row_type) {
   case ROW_TYPE_FIXED:   return STATIC_RECORD;
@@ -2641,7 +2640,7 @@
     }
   }
   /* Note: BLOCK_RECORD is used if table is transactional */
-  row_type= maria_row_type(ha_create_info, 0);
+  row_type= maria_row_type(ha_create_info);
   if (ha_create_info->transactional == HA_CHOICE_YES &&
       ha_create_info->row_type != ROW_TYPE_PAGE &&
       ha_create_info->row_type != ROW_TYPE_NOT_USED &&
@@ -2825,15 +2824,15 @@
   if (create_info->auto_increment_value != stats.auto_increment_value ||
       create_info->data_file_name != data_file_name ||
       create_info->index_file_name != index_file_name ||
-      (maria_row_type(create_info,  1) != data_file_type &&
+      (maria_row_type(create_info) != data_file_type &&
        create_info->row_type != ROW_TYPE_DEFAULT) ||
       table_changes == IS_EQUAL_NO ||
       table_changes & IS_EQUAL_PACK_LENGTH) // Not implemented yet
     return COMPATIBLE_DATA_NO;
 
-  if ((options & (HA_OPTION_PACK_RECORD | HA_OPTION_CHECKSUM |
+  if ((options & (HA_OPTION_CHECKSUM |
                   HA_OPTION_DELAY_KEY_WRITE)) !=
-      (create_info->table_options & (HA_OPTION_PACK_RECORD | HA_OPTION_CHECKSUM |
+      (create_info->table_options & (HA_OPTION_CHECKSUM |
                               HA_OPTION_DELAY_KEY_WRITE)))
     return COMPATIBLE_DATA_NO;
   return COMPATIBLE_DATA_YES;
[29 Sep 2008 6:19] Oleksandr Byelkin
Commit e-mail: http://lists.mysql.com/maria/172
[26 Oct 2008 22:20] Bugs System
Pushed into 6.0.8-alpha  (revid:sanja@mysql.com-20080928183259-hd9pq1efoger4het) (version source revid:guilhem@mysql.com-20081020191322-i0e65e3k8044kkce) (pib:5)
[9 Jan 2009 15:29] MC Brown
Added a note to the 6.0.8 changelog: 

Performing an ALTER TABLE on a Maria table where you are changing the column name but not the type, a full table rebuild may be triggered, instead of just a simple rename.