From: Date: May 12 2005 9:42pm Subject: bk commit into 4.1 tree (ingo:1.2267) BUG#10400 List-Archive: http://lists.mysql.com/internals/24818 X-Bug: 10400 Message-Id: Below is the list of changes that have just been committed into a local 4.1 repository of mydev. When mydev 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.2267 05/05/12 21:41:58 ingo@stripped +4 -0 Bug#10400 - Improperly-defined MERGE table crashes with INSERT ... ON DUPLICATE KEY UPDATE Added a condition for MERGE tables. These do not have unique indexes. But every key could be a unique key on the underlying MyISAM table. So get the maximum key length for MERGE tables instead of the maximum unique key length. This is used for buffer allocation in write_record(). sql/table.cc 1.129 05/05/12 21:40:58 ingo@stripped +6 -1 Bug#10400 - Improperly-defined MERGE table crashes with INSERT ... ON DUPLICATE KEY UPDATE Added a condition for MERGE tables. These do not have unique indexes. But every key could be a unique key on the underlying MyISAM table. So get the maximum key length for MERGE tables instead of the maximum unique key length. This is used for buffer allocation in write_record(). sql/sql_insert.cc 1.162 05/05/12 21:40:58 ingo@stripped +1 -1 Bug#10400 - Improperly-defined MERGE table crashes with INSERT ... ON DUPLICATE KEY UPDATE Changed the freeing of the memory to be symmetric to its allocation (my_safe_alloc -> my_safe_afree). This is not directly related to the bug. mysql-test/t/merge.test 1.31 05/05/12 21:40:58 ingo@stripped +12 -0 Bug#10400 - Improperly-defined MERGE table crashes with INSERT ... ON DUPLICATE KEY UPDATE The test case does not in all cases show the problem without the bugfix. The improper memory allocation might get through undetected in many cases. mysql-test/r/merge.result 1.35 05/05/12 21:40:58 ingo@stripped +10 -0 Bug#10400 - Improperly-defined MERGE table crashes with INSERT ... ON DUPLICATE KEY UPDATE The test result. # 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: ingo # Host: chilla.local # Root: /home/mydev/mysql-4.1-4100 --- 1.161/sql/sql_insert.cc Sat May 7 14:31:15 2005 +++ 1.162/sql/sql_insert.cc Thu May 12 21:40:58 2005 @@ -682,7 +682,7 @@ err: if (key) - my_afree(key); + my_safe_afree(key,table->max_unique_length,MAX_KEY_LENGTH); info->last_errno= error; table->file->print_error(error,MYF(0)); DBUG_RETURN(1); --- 1.128/sql/table.cc Sat May 7 22:54:07 2005 +++ 1.129/sql/table.cc Thu May 12 21:40:58 2005 @@ -688,7 +688,12 @@ set_if_bigger(outparam->max_key_length,keyinfo->key_length+ keyinfo->key_parts); outparam->total_key_length+= keyinfo->key_length; - if (keyinfo->flags & HA_NOSAME) + /* + MERGE tables do not have unique indexes. But every key could be + an unique index on the underlying MyISAM table. (Bug #10400) + */ + if ((keyinfo->flags & HA_NOSAME) || + (outparam->db_type == DB_TYPE_MRG_MYISAM)) set_if_bigger(outparam->max_unique_length,keyinfo->key_length); } if (primary_key < MAX_KEY && --- 1.34/mysql-test/r/merge.result Mon Dec 27 13:01:59 2004 +++ 1.35/mysql-test/r/merge.result Thu May 12 21:40:58 2005 @@ -681,3 +681,13 @@ t3 1 a 2 b A NULL NULL NULL YES BTREE t3 1 a 3 c A NULL NULL NULL YES BTREE drop table t1, t2, t3; +CREATE TABLE t1 ( a INT AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10), UNIQUE (b) ) +ENGINE=MyISAM; +CREATE TABLE t2 ( a INT AUTO_INCREMENT, b VARCHAR(10), INDEX (a), INDEX (b) ) +ENGINE=MERGE UNION (t1) INSERT_METHOD=FIRST; +INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=2; +INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=3; +SELECT b FROM t2; +b +3 +DROP TABLE t1, t2; --- 1.30/mysql-test/t/merge.test Mon Dec 27 13:01:59 2004 +++ 1.31/mysql-test/t/merge.test Thu May 12 21:40:58 2005 @@ -306,3 +306,15 @@ drop table t1, t2, t3; +# +# Bug#10400 - Improperly-defined MERGE table crashes with INSERT ... ON DUPLICATE KEY UPDATE +# +CREATE TABLE t1 ( a INT AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10), UNIQUE (b) ) + ENGINE=MyISAM; +CREATE TABLE t2 ( a INT AUTO_INCREMENT, b VARCHAR(10), INDEX (a), INDEX (b) ) + ENGINE=MERGE UNION (t1) INSERT_METHOD=FIRST; +INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=2; +INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=3; +SELECT b FROM t2; +DROP TABLE t1, t2; +