List:Commits« Previous MessageNext Message »
From:Mattias Jonsson Date:December 6 2010 11:37am
Subject:bzr commit into mysql-5.1-bugteam branch (mattias.jonsson:3512) Bug#57924
View as plain text  
#At file:///Users/mattiasj/mysql-bzr/b57924-51-bt/ based on revid:mats.kindahl@stripped

 3512 Mattias Jonsson	2010-12-06
      Bug#57924: crash when creating partitioned table with
      multiple columns in the partition key
      
      ndb crash if duplicate columns in the partitioning key.
      
      Backport from mysql-5.1-telco-7.0, see bug#53354.
     @ mysql-test/r/partition_error.result
        updated result
     @ mysql-test/t/partition_error.test
        Added test for the error in non-ndb partitioned table.
     @ sql/sql_partition.cc
        Added check for duplicated field names in the
        partitioning key.

    modified:
      mysql-test/r/partition_error.result
      mysql-test/suite/ndb/r/ndb_basic.result
      mysql-test/suite/ndb/t/ndb_basic.test
      mysql-test/t/partition_error.test
      sql/sql_partition.cc
=== modified file 'mysql-test/r/partition_error.result'
--- a/mysql-test/r/partition_error.result	2010-09-22 19:33:18 +0000
+++ b/mysql-test/r/partition_error.result	2010-12-06 11:37:10 +0000
@@ -1,5 +1,12 @@
 drop table if exists t1;
 #
+# Bug#57924: crash when creating partitioned table with
+#            multiple columns in the partition key
+#
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a,b))
+PARTITION BY KEY(a, b, a);
+ERROR HY000: Field in list of fields for partition function not found in table
+#
 # Bug#49161: Out of memory; restart server and try again (needed 2 bytes)
 #
 CREATE TABLE t1 (a INT) PARTITION BY HASH (a);

=== modified file 'mysql-test/suite/ndb/r/ndb_basic.result'
--- a/mysql-test/suite/ndb/r/ndb_basic.result	2007-10-26 07:06:18 +0000
+++ b/mysql-test/suite/ndb/r/ndb_basic.result	2010-12-06 11:37:10 +0000
@@ -585,6 +585,8 @@ c127 int,
 c128 int,
 primary key using hash(c1)) engine=ndb partition by key(c1);
 drop table t1;
+create table `t1` (`a` int, b int, primary key (a,b)) engine=ndb partition by key(`a`,`b`,`a`);
+ERROR HY000: Field in list of fields for partition function not found in table
 create table t1 (
 a1234567890123456789012345678901234567890 int primary key,
 a12345678901234567890123456789a1234567890 int,

=== modified file 'mysql-test/suite/ndb/t/ndb_basic.test'
--- a/mysql-test/suite/ndb/t/ndb_basic.test	2007-10-26 06:57:10 +0000
+++ b/mysql-test/suite/ndb/t/ndb_basic.test	2010-12-06 11:37:10 +0000
@@ -548,6 +548,13 @@ primary key using hash(c1)) engine=ndb p
 drop table t1;
 
 #
+# test bug#53354 - crash when creating partitioned table with multiple columns in the partition key
+#
+
+--error ER_FIELD_NOT_FOUND_PART_ERROR
+create table `t1` (`a` int, b int, primary key (a,b)) engine=ndb partition by key(`a`,`b`,`a`);
+
+#
 # test max size of attribute name and truncation
 #
 

=== modified file 'mysql-test/t/partition_error.test'
--- a/mysql-test/t/partition_error.test	2010-09-22 19:33:18 +0000
+++ b/mysql-test/t/partition_error.test	2010-12-06 11:37:10 +0000
@@ -11,6 +11,14 @@ drop table if exists t1;
 let $MYSQLD_DATADIR= `SELECT @@datadir`;
 
 --echo #
+--echo # Bug#57924: crash when creating partitioned table with
+--echo #            multiple columns in the partition key
+--echo #
+--error ER_FIELD_NOT_FOUND_PART_ERROR
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a,b))
+PARTITION BY KEY(a, b, a);
+
+--echo #
 --echo # Bug#49161: Out of memory; restart server and try again (needed 2 bytes)
 --echo #
 CREATE TABLE t1 (a INT) PARTITION BY HASH (a);

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2010-11-10 21:14:47 +0000
+++ b/sql/sql_partition.cc	2010-12-06 11:37:10 +0000
@@ -761,6 +761,9 @@ static bool handle_list_of_fields(List_i
   bool result;
   char *field_name;
   bool is_list_empty= TRUE;
+  int fields_handled = 0;
+  char* field_name_array[MAX_KEY];
+
   DBUG_ENTER("handle_list_of_fields");
 
   while ((field_name= it++))
@@ -776,6 +779,24 @@ static bool handle_list_of_fields(List_i
       result= TRUE;
       goto end;
     }
+
+    /*
+      Check for duplicate fields in the list.
+      Assuming that there are not many fields in the partition key list.
+      If there were, it would be better to replace the for-loop
+      with a more efficient algorithm.
+    */
+
+    field_name_array[fields_handled] = field_name;
+    for (int i = 0; i < fields_handled; ++i)
+    {
+      if (strcmp(field_name_array[i], field_name) == 0)
+      {
+        my_error(ER_FIELD_NOT_FOUND_PART_ERROR, MYF(0));
+        DBUG_RETURN(TRUE);
+      }
+    }
+    fields_handled++;
   }
   if (is_list_empty)
   {


Attachment: [text/bzr-bundle] bzr/mattias.jonsson@oracle.com-20101206113710-e36woi0el8g55gqy.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (mattias.jonsson:3512) Bug#57924Mattias Jonsson6 Dec