MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Chuck Bell Date:December 15 2009 8:50pm
Subject:bzr commit into mysql-6.0-backup branch (charles.bell:2913) Bug#49414
View as plain text  
#At file:///Users/cbell/source/bzr/mysql-6.0-backup-fix/ based on revid:charles.bell@stripped

 2913 Chuck Bell	2009-12-15 [merge]
      BUG#49414 : Innodb tbl w/blob and text column with NULL no 
                  longer NULL after backup/restore
      
      The backup default driver was writing blobs even if there
      was no data and calling a method to set the field as not null. 
      This behavior writes an empty string.
      
      This patch changes the restore driver so that it checks the
      size of the blob data read from the backup image and only 
      writes to the field (and set not null) when there is data 
      to write.
     @ mysql-test/suite/backup/r/backup_blob.result
        Corrected result file.
     @ mysql-test/suite/backup/t/backup_blob.test
        Added test case for NULL blob fields.
     @ sql/backup/be_default.cc
        Changed to include check if there is data to write.

    modified:
      mysql-test/suite/backup/r/backup_blob.result
      mysql-test/suite/backup/t/backup_blob.test
      sql/backup/be_default.cc
=== modified file 'mysql-test/suite/backup/r/backup_blob.result'
--- a/mysql-test/suite/backup/r/backup_blob.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_blob.result	2009-12-11 13:21:10 +0000
@@ -46,7 +46,71 @@ mysqltest.t2	1646886041
 CHECKSUM TABLE t3;
 Table	Checksum
 mysqltest.t3	2938103984
+#
+# Verify NULL blob fields are not overwritten with a null string.
+# See BUG#49414.
+# 
+#
+# Create a database with tables that have blob fields set to NULL.
+#
+CREATE DATABASE mydb;
+CREATE TABLE mydb.mytbl1 (
+f1 char (255), 
+f2 varchar (1024), 
+f3 binary (255), 
+f4 varbinary (1024), 
+f5 blob, 
+f6 text,
+f7 mediumblob,
+f8 mediumtext,
+f9 longblob,
+f10 longtext
+);
+CREATE TABLE mydb.mytbl2 (
+f1 char (255), 
+f2 varchar (1024), 
+f3 binary (255), 
+f4 varbinary (1024), 
+f5 blob, 
+f6 text,
+f7 mediumblob,
+f8 mediumtext,
+f9 longblob,
+f10 longtext
+) ENGINE INNODB;
+#
+# Insert some data.
+#
+INSERT INTO mydb.mytbl1 
+values (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+INSERT INTO mydb.mytbl2 
+values (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+# 
+# Show valus from the tables.
+#
+SELECT * FROM mydb.mytbl1;
+f1	f2	f3	f4	f5	f6	f7	f8	f9	f10
+NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT * FROM mydb.mytbl2;
+f1	f2	f3	f4	f5	f6	f7	f8	f9	f10
+NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL
+BACKUP DATABASE mydb TO 'mydb.bak';
+backup_id
+#
+RESTORE FROM 'mydb.bak' OVERWRITE;
+backup_id
+#
+# 
+# Show valus from the tables.
+#
+SELECT * FROM mydb.mytbl1;
+f1	f2	f3	f4	f5	f6	f7	f8	f9	f10
+NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT * FROM mydb.mytbl2;
+f1	f2	f3	f4	f5	f6	f7	f8	f9	f10
+NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL
 
 Cleanup 
 
 DROP DATABASE mysqltest;
+DROP DATABASE mydb;

=== modified file 'mysql-test/suite/backup/t/backup_blob.test'
--- a/mysql-test/suite/backup/t/backup_blob.test	2008-10-29 08:45:14 +0000
+++ b/mysql-test/suite/backup/t/backup_blob.test	2009-12-11 13:21:10 +0000
@@ -57,10 +57,73 @@ SELECT * FROM t1 ORDER BY id; 
 CHECKSUM TABLE t2;
 CHECKSUM TABLE t3;
 
+--echo #
+--echo # Verify NULL blob fields are not overwritten with a null string.
+--echo # See BUG#49414.
+--echo # 
+
+--echo #
+--echo # Create a database with tables that have blob fields set to NULL.
+--echo #
+CREATE DATABASE mydb;
+CREATE TABLE mydb.mytbl1 (
+   f1 char (255), 
+   f2 varchar (1024), 
+   f3 binary (255), 
+   f4 varbinary (1024), 
+   f5 blob, 
+   f6 text,
+   f7 mediumblob,
+   f8 mediumtext,
+   f9 longblob,
+  f10 longtext
+);
+
+CREATE TABLE mydb.mytbl2 (
+   f1 char (255), 
+   f2 varchar (1024), 
+   f3 binary (255), 
+   f4 varbinary (1024), 
+   f5 blob, 
+   f6 text,
+   f7 mediumblob,
+   f8 mediumtext,
+   f9 longblob,
+  f10 longtext
+) ENGINE INNODB;
+
+--echo #
+--echo # Insert some data.
+--echo #
+INSERT INTO mydb.mytbl1 
+  values (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+INSERT INTO mydb.mytbl2 
+  values (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+
+--echo # 
+--echo # Show valus from the tables.
+--echo #
+SELECT * FROM mydb.mytbl1;
+SELECT * FROM mydb.mytbl2;
+
+--replace_column 1 #
+BACKUP DATABASE mydb TO 'mydb.bak';
+
+--replace_column 1 #
+RESTORE FROM 'mydb.bak' OVERWRITE;
+
+--echo # 
+--echo # Show valus from the tables.
+--echo #
+SELECT * FROM mydb.mytbl1;
+SELECT * FROM mydb.mytbl2;
+
 --echo
 --echo Cleanup 
 --echo
 
 DROP DATABASE mysqltest;
+DROP DATABASE mydb;
 
 --remove_file $MYSQLD_BACKUPDIR/blob.bak
+--remove_file $MYSQLD_BACKUPDIR/mydb.bak

=== modified file 'sql/backup/be_default.cc'
--- a/sql/backup/be_default.cc	2009-12-02 08:01:43 +0000
+++ b/sql/backup/be_default.cc	2009-12-11 13:21:10 +0000
@@ -912,10 +912,17 @@ result_t Restore::send_data(Buffer &buf)
     case BLOB_ONCE:
     {
       blob_ptrs[blob_ptr_index]= (byte *)my_malloc(size, MYF(MY_WME));
-      memcpy(blob_ptrs[blob_ptr_index], (byte *)buf.data + META_SIZE, size);
-      ((Field_blob*) cur_table->field[*cur_blob])->set_ptr(size,
-        (uchar *)blob_ptrs[blob_ptr_index]);
-      cur_table->field[*cur_blob]->set_notnull();
+      /*
+        Do not write the field if there is no data for the blob field.
+        Allow field to default to NULL if table permits.
+      */
+      if (size > 0)
+      {
+        memcpy(blob_ptrs[blob_ptr_index], (byte *)buf.data + META_SIZE, size);
+        ((Field_blob*) cur_table->field[*cur_blob])->set_ptr(size,
+          (uchar *)blob_ptrs[blob_ptr_index]);
+        cur_table->field[*cur_blob]->set_notnull();
+      }
       blob_ptr_index++;
       mode= CHECK_BLOBS;
       DBUG_RETURN(PROCESSING);


Attachment: [text/bzr-bundle] bzr/charles.bell@sun.com-20091215205036-ufkxr72u7v0ae9yi.bundle
Thread
bzr commit into mysql-6.0-backup branch (charles.bell:2913) Bug#49414Chuck Bell15 Dec