2917 Mikael Ronstrom 2009-10-31
Fixed a test error
modified:
mysql-test/suite/funcs_1/r/is_columns_is.result
2916 Mikael Ronstrom 2009-10-31
Fixed a test error
modified:
mysql-test/r/type_decimal.result
2915 Mikael Ronstrom 2009-10-30
Added more comments and a safer error check
modified:
sql/sql_partition.cc
2914 Mikael Ronstrom 2009-10-30
Fixed such that we fail if using integer constants for character set fields, now need to have correct constant types
modified:
mysql-test/r/partition_column.result
mysql-test/t/partition_column.test
sql/sql_partition.cc
2913 Mikael Ronstrom 2009-10-30
Fixed so that character set constants are encoded as hex strings in frm file, but as utf8 strings in the same manner as default values in show create table and information schema tables
modified:
mysql-test/r/partition_column.result
mysql-test/t/partition_column.test
sql/partition_info.cc
sql/sql_partition.cc
sql/sql_partition.h
sql/sql_show.cc
2912 Mikael Ronstrom 2009-10-30
Ensuring character set constants are safe, first step fix
modified:
mysql-test/r/partition_column.result
sql/sql_partition.cc
2911 Mikael Ronstrom 2009-10-29
Changed COLUMN_LIST to COLUMNS after arch review
modified:
mysql-test/r/partition_column.result
mysql-test/r/partition_column_prune.result
mysql-test/r/partition_innodb.result
mysql-test/r/partition_range.result
mysql-test/t/partition_column.test
mysql-test/t/partition_column_prune.test
mysql-test/t/partition_innodb.test
mysql-test/t/partition_range.test
sql/lex.h
sql/opt_range.cc
sql/sql_partition.cc
sql/sql_yacc.yy
=== modified file 'mysql-test/r/partition_column.result'
--- a/mysql-test/r/partition_column.result 2009-10-29 17:04:23 +0000
+++ b/mysql-test/r/partition_column.result 2009-10-30 20:44:41 +0000
@@ -28,14 +28,6 @@ create table t1 (a varchar(2) character
partition by list columns (a)
(partition p0 values in (0x2020),
partition p1 values in (''));
-show create table t1;
-Table Create Table
-t1 CREATE TABLE `t1` (
- `a` varchar(2) CHARACTER SET ucs2 DEFAULT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1
-/*!50100 PARTITION BY LIST COLUMNS(a)
-(PARTITION p0 VALUES IN (_ucs2' ') ENGINE = MyISAM,
- PARTITION p1 VALUES IN (_ucs2'') ENGINE = MyISAM) */
insert into t1 values ('');
insert into t1 values (_ucs2 0x2020);
drop table t1;
@@ -47,6 +39,15 @@ subpartitions 4
partition p1 values less than (1, 'a', MAXVALUE, '1999-01-01'),
partition p2 values less than (1, 'a', MAXVALUE, MAXVALUE),
partition p3 values less than (1, MAXVALUE, MAXVALUE, MAXVALUE));
+ERROR HY000: Partition column values of incorrect type
+create table t1 (a int, b char(10), c varchar(25), d datetime)
+partition by range columns(a,b,c,d)
+subpartition by hash (to_seconds(d))
+subpartitions 4
+( partition p0 values less than (1, '0', MAXVALUE, '1900-01-01'),
+partition p1 values less than (1, 'a', MAXVALUE, '1999-01-01'),
+partition p2 values less than (1, 'a', MAXVALUE, MAXVALUE),
+partition p3 values less than (1, MAXVALUE, MAXVALUE, MAXVALUE));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
@@ -77,9 +78,9 @@ t1 CREATE TABLE `t1` (
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c,d)
SUBPARTITION BY HASH (to_seconds(d))
SUBPARTITIONS 4
-(PARTITION p0 VALUES LESS THAN (1,_latin1'0',MAXVALUE,'1900-01-01') ENGINE = MyISAM,
- PARTITION p1 VALUES LESS THAN (1,_latin1'a',MAXVALUE,'1999-01-01') ENGINE = MyISAM,
- PARTITION p2 VALUES LESS THAN (1,_latin1'a',MAXVALUE,MAXVALUE) ENGINE = MyISAM,
+(PARTITION p0 VALUES LESS THAN (1,'0',MAXVALUE,'1900-01-01') ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN (1,'a',MAXVALUE,'1999-01-01') ENGINE = MyISAM,
+ PARTITION p2 VALUES LESS THAN (1,'a',MAXVALUE,MAXVALUE) ENGINE = MyISAM,
PARTITION p3 VALUES LESS THAN (1,MAXVALUE,MAXVALUE,MAXVALUE) ENGINE = MyISAM) */
drop table t1;
create table t1 (a int, b int)
@@ -298,10 +299,10 @@ t1 CREATE TABLE `t1` (
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c)
SUBPARTITION BY KEY (c,d)
SUBPARTITIONS 3
-(PARTITION p0 VALUES LESS THAN (1,_latin1'abc',_latin1'abc') ENGINE = MyISAM,
- PARTITION p1 VALUES LESS THAN (2,_latin1'abc',_latin1'abc') ENGINE = MyISAM,
- PARTITION p2 VALUES LESS THAN (3,_latin1'abc',_latin1'abc') ENGINE = MyISAM,
- PARTITION p3 VALUES LESS THAN (4,_latin1'abc',_latin1'abc') ENGINE = MyISAM) */
+(PARTITION p0 VALUES LESS THAN (1,'abc','abc') ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN (2,'abc','abc') ENGINE = MyISAM,
+ PARTITION p2 VALUES LESS THAN (3,'abc','abc') ENGINE = MyISAM,
+ PARTITION p3 VALUES LESS THAN (4,'abc','abc') ENGINE = MyISAM) */
insert into t1 values (1,'a','b',1),(2,'a','b',2),(3,'a','b',3);
insert into t1 values (1,'b','c',1),(2,'b','c',2),(3,'b','c',3);
insert into t1 values (1,'c','d',1),(2,'c','d',2),(3,'c','d',3);
@@ -329,8 +330,8 @@ t1 CREATE TABLE `t1` (
`c` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c)
-(PARTITION p0 VALUES LESS THAN (1,_latin1'A',1) ENGINE = MyISAM,
- PARTITION p1 VALUES LESS THAN (1,_latin1'B',1) ENGINE = MyISAM) */
+(PARTITION p0 VALUES LESS THAN (1,'A',1) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN (1,'B',1) ENGINE = MyISAM) */
insert into t1 values (1, 'A', 1);
explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
@@ -429,7 +430,7 @@ create table t1 (a char(6))
partition by range columns(a)
(partition p0 values less than (23456),
partition p1 values less than (23456));
-ERROR HY000: VALUES LESS THAN value must be strictly increasing for each partition
+ERROR HY000: Partition column values of incorrect type
create table t1 (a int, b int)
partition by range columns(a,b)
(partition p0 values less than (10));
=== modified file 'mysql-test/r/type_decimal.result'
--- a/mysql-test/r/type_decimal.result 2008-04-28 18:12:52 +0000
+++ b/mysql-test/r/type_decimal.result 2009-10-31 09:48:18 +0000
@@ -3,13 +3,13 @@ SET SQL_WARNINGS=1;
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
datatype_id int(11) DEFAULT '0' NOT NULL,
-minvalue decimal(20,10) DEFAULT '0.0000000000' NOT NULL,
-maxvalue decimal(20,10) DEFAULT '0.0000000000' NOT NULL,
+min_value decimal(20,10) DEFAULT '0.0000000000' NOT NULL,
+max_value decimal(20,10) DEFAULT '0.0000000000' NOT NULL,
valuename varchar(20),
forecolor int(11),
backcolor int(11),
PRIMARY KEY (id),
-UNIQUE datatype_id (datatype_id, minvalue, maxvalue)
+UNIQUE datatype_id (datatype_id, min_value, max_value)
);
INSERT INTO t1 VALUES ( '1', '4', '0.0000000000', '0.0000000000', 'Ei saja', '0', '16776960');
INSERT INTO t1 VALUES ( '2', '4', '1.0000000000', '1.0000000000', 'Sajab', '16777215', '255');
@@ -143,12 +143,12 @@ INSERT INTO t1 VALUES ( '139', '21', '32
INSERT INTO t1 VALUES ( '143', '16', '-4.9000000000', '-0.1000000000', '', NULL, '15774720');
INSERT INTO t1 VALUES ( '145', '15', '0.0000000000', '1.9000000000', '', '0', '16769024');
INSERT INTO t1 VALUES ( '146', '16', '0.0000000000', '1.9000000000', '', '0', '16769024');
-select * from t1 where minvalue<=1 and maxvalue>=-1 and datatype_id=16;
-id datatype_id minvalue maxvalue valuename forecolor backcolor
+select * from t1 where min_value<=1 and max_value>=-1 and datatype_id=16;
+id datatype_id min_value max_value valuename forecolor backcolor
143 16 -4.9000000000 -0.1000000000 NULL 15774720
146 16 0.0000000000 1.9000000000 0 16769024
-select * from t1 where minvalue<=-1 and maxvalue>=-1 and datatype_id=16;
-id datatype_id minvalue maxvalue valuename forecolor backcolor
+select * from t1 where min_value<=-1 and max_value>=-1 and datatype_id=16;
+id datatype_id min_value max_value valuename forecolor backcolor
143 16 -4.9000000000 -0.1000000000 NULL 15774720
drop table t1;
create table t1 (a decimal(10,2));
=== modified file 'mysql-test/suite/funcs_1/r/is_columns_is.result'
--- a/mysql-test/suite/funcs_1/r/is_columns_is.result 2009-08-07 20:04:53 +0000
+++ b/mysql-test/suite/funcs_1/r/is_columns_is.result 2009-10-31 09:54:28 +0000
@@ -137,7 +137,7 @@ NULL information_schema PARTITIONS NODEG
NULL information_schema PARTITIONS PARTITION_COMMENT 23 NO varchar 80 240 NULL NULL utf8 utf8_general_ci varchar(80) select
NULL information_schema PARTITIONS PARTITION_DESCRIPTION 12 NULL YES longtext 4294967295 4294967295 NULL NULL utf8 utf8_general_ci longtext select
NULL information_schema PARTITIONS PARTITION_EXPRESSION 10 NULL YES longtext 4294967295 4294967295 NULL NULL utf8 utf8_general_ci longtext select
-NULL information_schema PARTITIONS PARTITION_METHOD 8 NULL YES varchar 12 36 NULL NULL utf8 utf8_general_ci varchar(12) select
+NULL information_schema PARTITIONS PARTITION_METHOD 8 NULL YES varchar 18 54 NULL NULL utf8 utf8_general_ci varchar(18) select
NULL information_schema PARTITIONS PARTITION_NAME 4 NULL YES varchar 64 192 NULL NULL utf8 utf8_general_ci varchar(64) select
NULL information_schema PARTITIONS PARTITION_ORDINAL_POSITION 6 NULL YES bigint NULL NULL 19 0 NULL NULL bigint(21) unsigned select
NULL information_schema PARTITIONS SUBPARTITION_EXPRESSION 11 NULL YES longtext 4294967295 4294967295 NULL NULL utf8 utf8_general_ci longtext select
@@ -487,7 +487,7 @@ NULL information_schema KEY_COLUMN_USAGE
3.0000 information_schema PARTITIONS SUBPARTITION_NAME varchar 64 192 utf8 utf8_general_ci varchar(64)
NULL information_schema PARTITIONS PARTITION_ORDINAL_POSITION bigint NULL NULL NULL NULL bigint(21) unsigned
NULL information_schema PARTITIONS SUBPARTITION_ORDINAL_POSITION bigint NULL NULL NULL NULL bigint(21) unsigned
-3.0000 information_schema PARTITIONS PARTITION_METHOD varchar 12 36 utf8 utf8_general_ci varchar(12)
+3.0000 information_schema PARTITIONS PARTITION_METHOD varchar 18 54 utf8 utf8_general_ci varchar(18)
3.0000 information_schema PARTITIONS SUBPARTITION_METHOD varchar 12 36 utf8 utf8_general_ci varchar(12)
1.0000 information_schema PARTITIONS PARTITION_EXPRESSION longtext 4294967295 4294967295 utf8 utf8_general_ci longtext
1.0000 information_schema PARTITIONS SUBPARTITION_EXPRESSION longtext 4294967295 4294967295 utf8 utf8_general_ci longtext
=== modified file 'mysql-test/t/partition_column.test'
--- a/mysql-test/t/partition_column.test 2009-10-29 17:04:23 +0000
+++ b/mysql-test/t/partition_column.test 2009-10-30 20:44:41 +0000
@@ -47,11 +47,11 @@ create table t1 (a varchar(2) character
partition by list columns (a)
(partition p0 values in (0x2020),
partition p1 values in (''));
-show create table t1;
insert into t1 values ('');
insert into t1 values (_ucs2 0x2020);
drop table t1;
+--error ER_WRONG_TYPE_COLUMN_VALUE_ERROR
create table t1 (a int, b char(10), c varchar(25), d datetime)
partition by range columns(a,b,c,d)
subpartition by hash (to_seconds(d))
@@ -60,6 +60,15 @@ subpartitions 4
partition p1 values less than (1, 'a', MAXVALUE, '1999-01-01'),
partition p2 values less than (1, 'a', MAXVALUE, MAXVALUE),
partition p3 values less than (1, MAXVALUE, MAXVALUE, MAXVALUE));
+
+create table t1 (a int, b char(10), c varchar(25), d datetime)
+partition by range columns(a,b,c,d)
+subpartition by hash (to_seconds(d))
+subpartitions 4
+( partition p0 values less than (1, '0', MAXVALUE, '1900-01-01'),
+ partition p1 values less than (1, 'a', MAXVALUE, '1999-01-01'),
+ partition p2 values less than (1, 'a', MAXVALUE, MAXVALUE),
+ partition p3 values less than (1, MAXVALUE, MAXVALUE, MAXVALUE));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
show create table t1;
@@ -311,7 +320,7 @@ partition by range columns(a)
(partition p0 values less than (H23456),
partition p1 values less than (M23456));
--- error ER_RANGE_NOT_INCREASING_ERROR
+-- error ER_WRONG_TYPE_COLUMN_VALUE_ERROR
create table t1 (a char(6))
partition by range columns(a)
(partition p0 values less than (23456),
=== modified file 'sql/partition_info.cc'
--- a/sql/partition_info.cc 2009-10-28 17:22:36 +0000
+++ b/sql/partition_info.cc 2009-10-30 20:08:34 +0000
@@ -2062,10 +2062,8 @@ int partition_info::fix_parser_data(THD
{
List_iterator<partition_element> it(partitions);
partition_element *part_elem;
- part_elem_value *val;
uint num_elements;
uint i= 0, j, k;
- int result;
DBUG_ENTER("partition_info::fix_parser_data");
if (!(part_type == RANGE_PARTITION ||
=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc 2009-10-29 17:04:23 +0000
+++ b/sql/sql_partition.cc 2009-10-30 21:35:20 +0000
@@ -2027,6 +2027,23 @@ static int add_partition_options(File fp
return err + add_engine(fptr,p_elem->engine_type);
}
+
+/*
+ Check partition fields for result type and if they need
+ to check the character set.
+
+ SYNOPSIS
+ check_part_field()
+ sql_type Type provided by user
+ field_name Name of field, used for error handling
+ result_type Out value: Result type of field
+ need_cs_check Out value: Do we need character set check
+
+ RETURN VALUES
+ TRUE Error
+ FALSE Ok
+*/
+
static int check_part_field(enum_field_types sql_type,
const char *field_name,
Item_result *result_type,
@@ -2055,7 +2072,7 @@ static int check_part_field(enum_field_t
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_DATETIME:
*result_type= STRING_RESULT;
- *need_cs_check= FALSE;
+ *need_cs_check= TRUE;
return FALSE;
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_STRING:
@@ -2081,6 +2098,20 @@ error:
return TRUE;
}
+
+/*
+ Find the given field's Create_field object using name of field
+
+ SYNOPSIS
+ get_sql_field()
+ field_name Field name
+ alter_info Info from ALTER TABLE/CREATE TABLE
+
+ RETURN VALUE
+ sql_field Object filled in by parser about field
+ NULL No field found
+*/
+
static Create_field* get_sql_field(char *field_name,
Alter_info *alter_info)
{
@@ -2100,6 +2131,93 @@ static Create_field* get_sql_field(char
DBUG_RETURN(NULL);
}
+
+/*
+ Convert a string in a given character set to a string which can be
+ used for FRM file storage in which case use_hex is TRUE and we store
+ the character constants as hex strings in the character set encoding
+ their field have. In the case of SHOW CREATE TABLE and the
+ PARTITIONS information schema table we instead provide utf8 strings
+ to the user and convert to the utf8 character set.
+
+ SYNOPSIS
+ get_converted_part_value_from_string()
+ item Item from which constant comes
+ res String as provided by val_str after
+ conversion to character set
+ field_cs Character set string is encoded in
+ NULL for INT_RESULT's here
+ val_conv Out value: The string created
+ use_hex TRUE => hex string created
+ FALSE => utf8 constant string created
+ RETURN VALUES
+ TRUE Error
+ FALSE Ok
+*/
+
+int get_converted_part_value_from_string(Item *item,
+ String *res,
+ CHARSET_INFO *field_cs,
+ String *val_conv,
+ bool use_hex)
+{
+ String val;
+ uint dummy_errors;
+ uint len, high, low, i;
+ const char *ptr;
+ char buf[3];
+
+ if (item->result_type() == INT_RESULT)
+ {
+ longlong value= item->val_int();
+ val_conv->set(value, system_charset_info);
+ return FALSE;
+ }
+ if (!res)
+ {
+ my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
+ return TRUE;
+ }
+ val_conv->length(0);
+ if (!field_cs || res->length() == 0)
+ {
+ val_conv->append("'");
+ if (res->length() != 0)
+ val_conv->append(*res);
+ val_conv->append("'");
+ return FALSE;
+ }
+ if (field_cs && use_hex)
+ {
+ val_conv->append("_");
+ val_conv->append(field_cs->csname);
+ val_conv->append(" ");
+ }
+ if (use_hex)
+ {
+ val_conv->append("0x");
+ len= res->length();
+ ptr= res->ptr();
+ for (i= 0; i < len; i++)
+ {
+ high= (*ptr) >> 4;
+ low= (*ptr) & 0x0F;
+ buf[0]= _dig_vec_upper[high];
+ buf[1]= _dig_vec_upper[low];
+ buf[2]= 0;
+ val_conv->append((const char*)buf);
+ ptr++;
+ }
+ }
+ else
+ {
+ val.copy(res->ptr(), res->length(), field_cs,
+ system_charset_info, &dummy_errors);
+ append_unescaped(val_conv, val.ptr(), val.length());
+ }
+ return FALSE;
+}
+
static int add_column_list_values(File fptr, partition_info *part_info,
part_elem_value *list_value,
HA_CREATE_INFO *create_info,
@@ -2177,6 +2295,11 @@ static int add_column_list_values(File f
else
field_cs= NULL;
}
+ if (result_type != item_expr->result_type())
+ {
+ my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0));
+ return 1;
+ }
if (field_cs && field_cs != item_expr->collation.collation)
{
if (!(item_expr= convert_charset_partition_constant(item_expr,
@@ -2186,33 +2309,14 @@ static int add_column_list_values(File f
return 1;
}
}
- if (result_type != item_expr->result_type())
- {
- my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0));
- return 1;
- }
- if (result_type == INT_RESULT)
- {
- longlong val;
- val= item_expr->val_int();
- err+= add_int(fptr, val);
- }
- else
{
+ String val_conv;
res= item_expr->val_str(&str);
- if (!res)
- {
- my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
+ if (get_converted_part_value_from_string(item_expr, res,
+ field_cs, &val_conv,
+ (bool)(alter_info != NULL)))
return 1;
- }
- if (field_cs)
- {
- err+= add_string(fptr,"_");
- err+= add_string(fptr, field_cs->csname);
- }
- err+= add_string(fptr,"'");
- err+= add_string_object(fptr, res);
- err+= add_string(fptr,"'");
+ err+= add_string_object(fptr, &val_conv);
}
}
}
=== modified file 'sql/sql_partition.h'
--- a/sql/sql_partition.h 2009-10-28 17:32:48 +0000
+++ b/sql/sql_partition.h 2009-10-30 20:08:34 +0000
@@ -75,6 +75,11 @@ void get_partition_set(const TABLE *tabl
const key_range *key_spec,
part_id_range *part_spec);
uint get_partition_field_store_length(Field *field);
+int get_converted_part_value_from_string(Item *item,
+ String *res,
+ CHARSET_INFO *cs,
+ String *val_conv,
+ bool use_hex);
void get_full_part_id_from_key(const TABLE *table, uchar *buf,
KEY *key_info,
const key_range *key_spec,
=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc 2009-10-28 17:22:36 +0000
+++ b/sql/sql_show.cc 2009-10-30 20:08:34 +0000
@@ -25,6 +25,7 @@
#include "sql_trigger.h"
#include "authors.h"
#include "contributors.h"
+#include "sql_partition.h"
#ifdef HAVE_EVENT_SCHEDULER
#include "events.h"
#include "event_data_objects.h"
@@ -4970,6 +4971,7 @@ get_partition_column_description(partiti
{
char buffer[MAX_KEY_LENGTH];
String str(buffer, sizeof(buffer), &my_charset_bin);
+ String val_conv;
Item *item= col_val->item_expression;
if (!(item= part_info->get_column_item(item,
@@ -4978,16 +4980,13 @@ get_partition_column_description(partiti
DBUG_RETURN(1);
}
String *res= item->val_str(&str);
- if (!res)
+ if (get_converted_part_value_from_string(item, res,
+ part_info->part_field_array[i]->charset(),
+ &val_conv, FALSE))
{
- my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
DBUG_RETURN(1);
}
- if (item->result_type() == STRING_RESULT)
- tmp_str.append("'");
- tmp_str.append(*res);
- if (item->result_type() == STRING_RESULT)
- tmp_str.append("'");
+ tmp_str.append(val_conv);
}
if (i != num_elements - 1)
tmp_str.append(",");
@@ -5004,7 +5003,6 @@ static int get_schema_partitions_record(
char buff[61];
String tmp_res(buff, sizeof(buff), cs);
String tmp_str;
- uint num_elements;
TABLE *show_table= tables->table;
handler *file;
#ifdef WITH_PARTITION_STORAGE_ENGINE
| Thread |
|---|
| • bzr push into mysql-5.5-next-mr branch (mikael:2911 to 2917) | Mikael Ronstrom | 2 Nov |