summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/partition_column.result26
-rw-r--r--mysql-test/t/partition_column.test1
-rw-r--r--sql/partition_info.cc2
-rw-r--r--sql/sql_partition.cc143
-rw-r--r--sql/sql_partition.h5
-rw-r--r--sql/sql_show.cc14
6 files changed, 89 insertions, 102 deletions
diff --git a/mysql-test/r/partition_column.result b/mysql-test/r/partition_column.result
index ed0124cc848..d76220e35cb 100644
--- a/mysql-test/r/partition_column.result
+++ b/mysql-test/r/partition_column.result
@@ -28,14 +28,6 @@ create table t1 (a varchar(2) character set ucs2)
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 0x2020) ENGINE = MyISAM,
- PARTITION p1 VALUES IN (_ucs2 '') ENGINE = MyISAM) */
insert into t1 values ('');
insert into t1 values (_ucs2 0x2020);
drop table t1;
@@ -77,9 +69,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 0x30,MAXVALUE,'1900-01-01') ENGINE = MyISAM,
- PARTITION p1 VALUES LESS THAN (1,_latin1 0x61,MAXVALUE,'1999-01-01') ENGINE = MyISAM,
- PARTITION p2 VALUES LESS THAN (1,_latin1 0x61,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 +290,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 0x616263,_latin1 0x616263) ENGINE = MyISAM,
- PARTITION p1 VALUES LESS THAN (2,_latin1 0x616263,_latin1 0x616263) ENGINE = MyISAM,
- PARTITION p2 VALUES LESS THAN (3,_latin1 0x616263,_latin1 0x616263) ENGINE = MyISAM,
- PARTITION p3 VALUES LESS THAN (4,_latin1 0x616263,_latin1 0x616263) 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 +321,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 0x41,1) ENGINE = MyISAM,
- PARTITION p1 VALUES LESS THAN (1,_latin1 0x42,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
diff --git a/mysql-test/t/partition_column.test b/mysql-test/t/partition_column.test
index 3891610d12d..3d18fcdd337 100644
--- a/mysql-test/t/partition_column.test
+++ b/mysql-test/t/partition_column.test
@@ -47,7 +47,6 @@ create table t1 (a varchar(2) character set ucs2)
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;
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index 99d505a4540..cbb4d2331c9 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -2062,10 +2062,8 @@ int partition_info::fix_parser_data(THD *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 ||
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 75e4d1056f9..d530a25f05b 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -1818,46 +1818,6 @@ static int add_write(File fptr, const char *buf, uint len)
return 1;
}
-static int add_string(File fptr, const char *string);
-
-static int write_hex_char(File fptr, uint number)
-{
- char buf[2];
- char c= '0';
- /* Write number between 0 and 15 as 0-9,A-F */
- if (number < 10)
- c+= number;
- else
- {
- c= 'A';
- c+= (number - 10);
- }
- buf[0]= c;
- buf[1]= 0;
- return add_string(fptr, (const char*)buf);
-}
-
-static int add_hex_string_object(File fptr, String *string)
-{
- uint len= string->length();
- uint i;
- const char *ptr= string->ptr();
- char c;
- int err;
- uint low, high;
- err= add_string(fptr, "0x");
- for (i= 0; i < len; i++)
- {
- c= *ptr;
- ptr++;
- high= c >> 4;
- low= c & 15;
- err+= write_hex_char(fptr, high);
- err+= write_hex_char(fptr, low);
- }
- return err;
-}
-
static int add_string_object(File fptr, String *string)
{
return add_write(fptr, string->ptr(), string->length());
@@ -2095,7 +2055,7 @@ static int check_part_field(enum_field_types sql_type,
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:
@@ -2140,6 +2100,69 @@ static Create_field* get_sql_field(char *field_name,
DBUG_RETURN(NULL);
}
+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 (!res)
+ {
+ my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
+ return 1;
+ }
+ if (item->result_type() == INT_RESULT)
+ {
+ longlong value= item->val_int();
+ val_conv->set(value, system_charset_info);
+ return 0;
+ }
+ 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 0;
+ }
+ 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 0;
+}
+
static int add_column_list_values(File fptr, partition_info *part_info,
part_elem_value *list_value,
HA_CREATE_INFO *create_info,
@@ -2231,42 +2254,14 @@ static int add_column_list_values(File fptr, partition_info *part_info,
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_space(fptr);
- if (res->length())
- {
- err+= add_hex_string_object(fptr, res);
- }
- else
- {
- err+= add_string(fptr,"'");
- err+= add_string(fptr,"'");
- }
-
- }
- else
- {
- err+= add_string(fptr,"'");
- err+= add_string_object(fptr, res);
- err+= add_string(fptr,"'");
- }
+ err+= add_string_object(fptr, &val_conv);
}
}
}
diff --git a/sql/sql_partition.h b/sql/sql_partition.h
index e9de5f85870..97b361c4b43 100644
--- a/sql/sql_partition.h
+++ b/sql/sql_partition.h
@@ -75,6 +75,11 @@ void get_partition_set(const TABLE *table, uchar *buf, const uint index,
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,
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 64674eb5c57..979f7a98135 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -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(partition_info *part_info,
{
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(partition_info *part_info,
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(THD *thd, TABLE_LIST *tables,
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