From dc4e76ca78716e2b0c74c3896e189435ee829ecd Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 14 Sep 2005 18:15:40 -0400 Subject: [PATCH] Bug #13154: Used AND when modulo should have been used to calculate partition id for PARTITION BY KEY and SUBPARTITION BY KEY mysql-test/r/partition.result: New test for Bug #13154 mysql-test/t/partition.test: New test for Bug #13154 --- mysql-test/r/partition.result | 10 ++++++++++ mysql-test/t/partition.test | 18 ++++++++++++++++++ sql/sql_partition.cc | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 3136a32d8de..88e06e64956 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -87,3 +87,13 @@ partition by list (b*a) partition x2 values in (3, 11, 5, 7) tablespace ts2, partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3); drop table t1; +CREATE TABLE t1 ( +a int not null) +partition by key(a); +LOCK TABLES t1 WRITE; +insert into t1 values (1); +insert into t1 values (2); +insert into t1 values (3); +insert into t1 values (4); +UNLOCK TABLES; +drop table t1; diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 0905413e69d..37a4912702f 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -134,3 +134,21 @@ partition by list (b*a) partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3); drop table t1; + +# +# Bug 13154: Insert crashes due to bad calculation of partition id +# for PARTITION BY KEY and SUBPARTITION BY KEY +# +CREATE TABLE t1 ( +a int not null) +partition by key(a); + +LOCK TABLES t1 WRITE; +insert into t1 values (1); +insert into t1 values (2); +insert into t1 values (3); +insert into t1 values (4); +UNLOCK TABLES; + +drop table t1; + diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 1f24806dc5e..297e729a2ed 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -2298,7 +2298,7 @@ static uint32 get_part_id_key(Field **field_array, uint no_parts) { DBUG_ENTER("get_part_id_key"); - DBUG_RETURN(calculate_key_value(field_array) & no_parts); + DBUG_RETURN(calculate_key_value(field_array) % no_parts); }