summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/partition_column.result44
-rw-r--r--mysql-test/t/partition_column.test26
-rw-r--r--sql/sql_partition.cc13
3 files changed, 76 insertions, 7 deletions
diff --git a/mysql-test/r/partition_column.result b/mysql-test/r/partition_column.result
index 458343a6b92..506803238fe 100644
--- a/mysql-test/r/partition_column.result
+++ b/mysql-test/r/partition_column.result
@@ -1,4 +1,44 @@
drop table if exists t1;
+#
+# Bug#52815: LIST COLUMNS doesn't insert rows in correct partition
+# if muliple columns used
+CREATE TABLE t1 (
+id INT NOT NULL,
+name VARCHAR(255),
+department VARCHAR(10),
+country VARCHAR(255)
+) PARTITION BY LIST COLUMNS (department, country) (
+PARTITION first_office VALUES IN (('dep1', 'Russia'), ('dep1', 'Croatia')),
+PARTITION second_office VALUES IN (('dep2', 'Russia'))
+);
+INSERT INTO t1 VALUES(1, 'Ann', 'dep1', 'Russia');
+INSERT INTO t1 VALUES(2, 'Bob', 'dep1', 'Croatia');
+INSERT INTO t1 VALUES(3, 'Cecil', 'dep2', 'Russia');
+INSERT INTO t1 VALUES(3, 'Dan', 'dep2', 'Croatia');
+ERROR HY000: Table has no partition for value from column_list
+SELECT PARTITION_NAME,TABLE_ROWS
+FROM INFORMATION_SCHEMA.PARTITIONS
+WHERE TABLE_NAME = 't1';
+PARTITION_NAME TABLE_ROWS
+first_office 2
+second_office 1
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `id` int(11) NOT NULL,
+ `name` varchar(255) DEFAULT NULL,
+ `department` varchar(10) DEFAULT NULL,
+ `country` varchar(255) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50500 PARTITION BY LIST COLUMNS(department,country)
+(PARTITION first_office VALUES IN (('dep1','Russia'),('dep1','Croatia')) ENGINE = MyISAM,
+ PARTITION second_office VALUES IN (('dep2','Russia')) ENGINE = MyISAM) */
+SELECT * FROM t1 WHERE department = 'dep2' and country = 'Croatia';
+id name department country
+SELECT * FROM t1 WHERE department = 'dep1' and country = 'Croatia';
+id name department country
+2 Bob dep1 Croatia
+DROP TABLE t1;
CREATE TABLE t1 (a DECIMAL)
PARTITION BY RANGE COLUMNS (a)
(PARTITION p0 VALUES LESS THAN (0));
@@ -298,11 +338,11 @@ select * from t1 where a > 8;
a b
select * from t1 where a not between 8 and 8;
a b
+1 NULL
2 NULL
+1 1
2 2
3 NULL
-1 NULL
-1 1
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
diff --git a/mysql-test/t/partition_column.test b/mysql-test/t/partition_column.test
index d1d2d666a39..95a2be36395 100644
--- a/mysql-test/t/partition_column.test
+++ b/mysql-test/t/partition_column.test
@@ -8,6 +8,32 @@
drop table if exists t1;
--enable_warnings
+--echo #
+--echo # Bug#52815: LIST COLUMNS doesn't insert rows in correct partition
+--echo # if muliple columns used
+CREATE TABLE t1 (
+id INT NOT NULL,
+name VARCHAR(255),
+department VARCHAR(10),
+country VARCHAR(255)
+) PARTITION BY LIST COLUMNS (department, country) (
+PARTITION first_office VALUES IN (('dep1', 'Russia'), ('dep1', 'Croatia')),
+PARTITION second_office VALUES IN (('dep2', 'Russia'))
+);
+
+INSERT INTO t1 VALUES(1, 'Ann', 'dep1', 'Russia');
+INSERT INTO t1 VALUES(2, 'Bob', 'dep1', 'Croatia');
+INSERT INTO t1 VALUES(3, 'Cecil', 'dep2', 'Russia');
+--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+INSERT INTO t1 VALUES(3, 'Dan', 'dep2', 'Croatia');
+SELECT PARTITION_NAME,TABLE_ROWS
+FROM INFORMATION_SCHEMA.PARTITIONS
+WHERE TABLE_NAME = 't1';
+SHOW CREATE TABLE t1;
+SELECT * FROM t1 WHERE department = 'dep2' and country = 'Croatia';
+SELECT * FROM t1 WHERE department = 'dep1' and country = 'Croatia';
+DROP TABLE t1;
+
#
# Bug#51347: assertion with show create table + partition by columns
# on decimal column
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 0eb92dc23a9..153d958a362 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -3096,7 +3096,7 @@ int get_partition_id_list_col(partition_info *part_info,
}
else
{
- *part_id= (uint32)list_col_array[list_index].partition_id;
+ *part_id= (uint32)list_col_array[list_index*num_columns].partition_id;
DBUG_RETURN(0);
}
}
@@ -7701,7 +7701,7 @@ uint32 get_next_partition_id_range(PARTITION_ITERATOR* part_iter)
DESCRIPTION
This implementation of PARTITION_ITERATOR::get_next() is special for
LIST partitioning: it enumerates partition ids in
- part_info->list_array[i] (list_col_array[i] for COLUMNS LIST
+ part_info->list_array[i] (list_col_array[i*cols] for COLUMNS LIST
partitioning) where i runs over [min_idx, max_idx] interval.
The function conforms to partition_iter_func type.
@@ -7727,9 +7727,12 @@ uint32 get_next_partition_id_list(PARTITION_ITERATOR *part_iter)
{
partition_info *part_info= part_iter->part_info;
uint32 num_part= part_iter->part_nums.cur++;
- return part_info->column_list ?
- part_info->list_col_array[num_part].partition_id :
- part_info->list_array[num_part].partition_id;
+ if (part_info->column_list)
+ {
+ uint num_columns= part_info->part_field_list.elements;
+ return part_info->list_col_array[num_part*num_columns].partition_id;
+ }
+ return part_info->list_array[num_part].partition_id;
}
}