Bug #57924 crash when creating partitioned table with multiple columns in the partition key
Submitted: 2 Nov 2010 12:22 Modified: 28 Jan 2011 12:10
Reporter: Maitrayi Sabaratnam Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Mattias Jonsson CPU Architecture:Any

[2 Nov 2010 12:22] Maitrayi Sabaratnam
Description:
This bug is fixed in mysql-5.1-telco-7.0 and 7.1, See bug#53354. It would ease the merge between the MySQL Server and Cluster if it is included in the 5.1 version. It is a low risk and low effort fix.

How to repeat:
See bug#53354.

Suggested fix:
Fix as in cluster:

=== modified file 'sql/sql_partition.cc'
--- sql/sql_partition.cc        2010-10-12 14:53:28 +0000
+++ sql/sql_partition.cc        2010-10-28 13:28:50 +0000
@@ -764,6 +764,9 @@
   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++))
@@ -779,6 +782,24 @@
       result= TRUE;
       goto end;
     }
+
+#ifndef MCP_BUG53354
+    /* Check for duplicate fields in the list.
+     * Assuming that there are not many fields in the partition key list.
+     * If there were, better algorithm than the for-loop is recommended.
+     */
+
+    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++;
+#endif
   }
   if (is_list_empty)
   {
[3 Nov 2010 11:48] Sveta Smirnova
Thank you for the report.

Verified as described: "please push fix in main tree"
[4 Nov 2010 13:32] Jon Stephens
Hi Kostja,

I'm changing the category from Parser to Partitioning, so that this will come to me for documentation rather than to Paul. (I'm already documenting the related Cluster BUG#53354.)

Thanks!
[6 Dec 2010 11:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/126121

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.
[10 Jan 2011 12:45] Magnus BlÄudd
CREATE TABLE t2(a int, b int, PRIMARY KEY(a, b, a))
 => 1060: Duplicate column name 'a'

CREATE TABLE t2(a int, b int, PRIMARY KEY(A, b, a))
 => 1060: Duplicate column name 'a'

CREATE TABLE t2(a int, b int, PRIMARY KEY(a, b, A));
 => 1060: Duplicate column name 'A'

CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a,b))
PARTITION BY KEY(a, b, a)
 => 1488: Field in list of fields for partition function not found in table

CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a,b))
PARTITION BY KEY(a, b, A)
 => Success!

I think we should use my_strcasecmp when comparing the field names.

From 'mysql_prepare_create_table' in sql_table.cc

    /* Check if we have used the same field name before */
    for (dup_no=0; (dup_field=it2++) != sql_field; dup_no++)
    {
      if (my_strcasecmp(system_charset_info,
			sql_field->field_name,
			dup_field->field_name) == 0)
[10 Jan 2011 15:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/128325

3512 Mattias Jonsson	2011-01-10
      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.
      
      Changed from case sensitive field name comparision
      to non case sensitive too.
     @ 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.
[10 Jan 2011 15:24] Mattias Jonsson
Great catch Magnus, I've updated the patch.
[26 Jan 2011 20:15] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:mattias.jonsson@oracle.com-20110126201331-ab82uv7s5qmdufs5) (version source revid:mattias.jonsson@oracle.com-20110126201331-ab82uv7s5qmdufs5) (merge vers: 5.6.2) (pib:24)
[26 Jan 2011 20:16] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:mattias.jonsson@oracle.com-20110126183353-8fngni1uuyybmz9u) (version source revid:mattias.jonsson@oracle.com-20110126183353-8fngni1uuyybmz9u) (merge vers: 5.5.10) (pib:24)
[26 Jan 2011 20:16] Bugs System
Pushed into mysql-5.1 5.1.56 (revid:mattias.jonsson@oracle.com-20110126155021-evjpfdciphnd50sy) (version source revid:mattias.jonsson@oracle.com-20110126155021-evjpfdciphnd50sy) (merge vers: 5.1.56) (pib:24)
[26 Jan 2011 20:18] Mattias Jonsson
Note that the code is pushed into 5.1 only (the code was null-merged to 5.5 because the bug did not exists there, it was fixed by the COLUMNS partitioning feature.) The test was merged through 5.5 up to trunk though.
[27 Jan 2011 16:45] Jon Stephens
See BUG#53354 for docs info.

Closed.
[28 Jan 2011 12:10] Jon Stephens
Already documented. Set back to Closed.