diff options
-rw-r--r-- | mysql-test/r/partition_range.result | 34 | ||||
-rw-r--r-- | mysql-test/t/partition_hash.test | 12 | ||||
-rw-r--r-- | mysql-test/t/partition_range.test | 43 | ||||
-rw-r--r-- | sql/item.h | 14 | ||||
-rw-r--r-- | sql/partition_info.cc | 9 | ||||
-rw-r--r-- | sql/sql_partition.cc | 13 |
6 files changed, 116 insertions, 9 deletions
diff --git a/mysql-test/r/partition_range.result b/mysql-test/r/partition_range.result index 2fa40b44815..c8380446f44 100644 --- a/mysql-test/r/partition_range.result +++ b/mysql-test/r/partition_range.result @@ -1,4 +1,38 @@ drop table if exists t1; +create table t1 (a varchar(10) charset latin1 collate latin1_bin, b int) +partition by range (length(a) * b) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 2),('a',3); +drop table t1; +create table t1 (a varchar(10) charset latin1 collate latin1_bin, b int) +partition by range (b* length(a) * b) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 2),('a',3); +drop table t1; +create table t1 (a varchar(10) charset latin1 collate latin1_bin, +b varchar(10) charset latin1 collate latin1_bin) +partition by range (length(b) * length(a)) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 'b '),('a','b'); +drop table t1; +create table t1 (a varchar(10) charset latin1 collate latin1_bin, +b varchar(10) charset latin1 collate latin1_bin) +partition by range (length(a) * length(b)) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 'b '),('a','b'); +drop table t1; +create table t1 (a varchar(10) charset latin1 collate latin1_bin, +b varchar(10) charset latin1 collate latin1_bin, c int) +partition by range (length(a) * c) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 'b ', 2),('a','b', 3); +drop table t1; +create table t1 (a varchar(10) charset latin1 collate latin1_bin, +b varchar(10) charset latin1 collate latin1_bin, c int) +partition by range (c * length(a)) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 'b ', 2),('a','b', 3); +drop table t1; create table t1 (a int unsigned) partition by range (a) (partition pnull values less than (0), diff --git a/mysql-test/t/partition_hash.test b/mysql-test/t/partition_hash.test index 3304f30fb1a..d3f1a5f4892 100644 --- a/mysql-test/t/partition_hash.test +++ b/mysql-test/t/partition_hash.test @@ -10,6 +10,18 @@ drop table if exists t1; --enable_warnings # +# BUG 18198: Partition functions handling +# +create table t1 (a varchar(10) charset latin1 collate latin1_bin) +partition by hash(length(a)) +partitions 10; +insert into t1 values (''),(' '),('a'),('a '),('a '); +explain partitions select * from t1 where a='a '; +explain partitions select * from t1 where a='a'; +explain partitions select * from t1 where a='a ' OR a='a'; +drop table t1; + +# # More partition pruning tests, especially on interval walking # create table t1 (a int unsigned) diff --git a/mysql-test/t/partition_range.test b/mysql-test/t/partition_range.test index 8cf2313e39c..ead971c189e 100644 --- a/mysql-test/t/partition_range.test +++ b/mysql-test/t/partition_range.test @@ -10,6 +10,49 @@ drop table if exists t1; --enable_warnings # +# BUG 18198: Various tests for partition functions +# +create table t1 (a varchar(10) charset latin1 collate latin1_bin, b int) +partition by range (length(a) * b) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 2),('a',3); +drop table t1; + +create table t1 (a varchar(10) charset latin1 collate latin1_bin, b int) +partition by range (b* length(a) * b) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 2),('a',3); +drop table t1; + +create table t1 (a varchar(10) charset latin1 collate latin1_bin, + b varchar(10) charset latin1 collate latin1_bin) +partition by range (length(b) * length(a)) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 'b '),('a','b'); +drop table t1; + +create table t1 (a varchar(10) charset latin1 collate latin1_bin, + b varchar(10) charset latin1 collate latin1_bin) +partition by range (length(a) * length(b)) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 'b '),('a','b'); +drop table t1; + +create table t1 (a varchar(10) charset latin1 collate latin1_bin, + b varchar(10) charset latin1 collate latin1_bin, c int) +partition by range (length(a) * c) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 'b ', 2),('a','b', 3); +drop table t1; + +create table t1 (a varchar(10) charset latin1 collate latin1_bin, + b varchar(10) charset latin1 collate latin1_bin, c int) +partition by range (c * length(a)) +(partition p0 values less than (2), partition p1 values less than (10)); +insert into t1 values ('a ', 'b ', 2),('a','b', 3); +drop table t1; + +# # More checks for partition pruning # create table t1 (a int unsigned) diff --git a/sql/item.h b/sql/item.h index 1f5324f33be..8799fa07eb7 100644 --- a/sql/item.h +++ b/sql/item.h @@ -831,12 +831,20 @@ public: Check if a partition function is allowed SYNOPSIS check_partition_func_processor() - int_arg Return argument + int_arg Ignored RETURN VALUE - 0 + TRUE Partition function not accepted + FALSE Partition function accepted + DESCRIPTION check_partition_func_processor is used to check if a partition function - uses an allowed function. The default is that an item is not allowed + uses an allowed function. An allowed function will always ensure that + X=Y guarantees that also part_function(X)=part_function(Y) where X is + a set of partition fields and so is Y. The problems comes mainly from + character sets where two equal strings can be quite unequal. E.g. the + german character for double s is equal to 2 s. + + The default is that an item is not allowed in a partition function. However all mathematical functions, string manipulation functions, date functions are allowed. Allowed functions can never depend on server version, they cannot depend on anything diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 724464125ea..1f84d3f1e83 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -838,11 +838,12 @@ end: /* Print error for no partition found + SYNOPSIS print_no_partition_found() table Table object + RETURN VALUES - NONE */ void partition_info::print_no_partition_found(TABLE *table) @@ -863,10 +864,11 @@ void partition_info::print_no_partition_found(TABLE *table) Set up buffers and arrays for fields requiring preparation SYNOPSIS set_up_charset_field_preps() - part_info Partition info object + RETURN VALUES TRUE Memory Allocation error FALSE Success + DESCRIPTION Set up arrays and buffers for fields that require special care for calculation of partition id. This is used for string fields with @@ -1025,5 +1027,4 @@ error: mem_alloc_error(size); DBUG_RETURN(TRUE); } -#endif - /* WITH_PARTITION_STORAGE_ENGINE */ +#endif /* WITH_PARTITION_STORAGE_ENGINE */ diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 796f018e04b..cedd3f6b265 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1437,9 +1437,11 @@ static uint32 get_part_id_from_linear_hash(longlong hash_value, uint mask, /* Check if a particular field is in need of character set handling for partition functions. + SYNOPSIS field_is_partition_charset() field The field to check + RETURN VALUES FALSE Not in need of character set handling TRUE In need of character set handling @@ -1461,8 +1463,9 @@ bool field_is_partition_charset(Field *field) /* - Check that partition function do not contain any forbidden + Check that partition function doesn't contain any forbidden character sets and collations. + SYNOPSIS check_part_func_fields() ptr Array of Field pointers @@ -1471,6 +1474,7 @@ bool field_is_partition_charset(Field *field) RETURN VALUES FALSE Success TRUE Error + DESCRIPTION We will check in this routine that the fields of the partition functions do not contain unallowed parts. It can also be used to check if there @@ -2390,9 +2394,13 @@ static uint32 get_part_id_linear_key(partition_info *part_info, /* Copy to field buffers and set up field pointers + SYNOPSIS copy_to_part_field_buffers() ptr Array of fields to copy + field_bufs Array of field buffers to copy to + restore_ptr Array of pointers to restore to + RETURN VALUES NONE DESCRIPTION @@ -2451,8 +2459,9 @@ static void copy_to_part_field_buffers(Field **ptr, SYNOPSIS restore_part_field_pointers() ptr Array of fields to restore + restore_ptr Array of field pointers to restore to + RETURN VALUES - NONE */ static void restore_part_field_pointers(Field **ptr, char **restore_ptr) |