Commit e30ccf7a authored by Mikael Ronstrom's avatar Mikael Ronstrom

Fixed Information schema for column list partitioned tables

parent 9ef69958
...@@ -50,6 +50,12 @@ partition by list column_list(a,b) ...@@ -50,6 +50,12 @@ partition by list column_list(a,b)
column_list(NULL, NULL)), column_list(NULL, NULL)),
partition p1 values in (column_list(1,1), column_list(2,2)), partition p1 values in (column_list(1,1), column_list(2,2)),
partition p2 values in (column_list(3, NULL), column_list(NULL, 1))); partition p2 values in (column_list(3, NULL), column_list(NULL, 1)));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
LIST COLUMN_LIST a,b (1,NULL),(2,NULL),(NULL,NULL)
LIST COLUMN_LIST a,b (1,1),(2,2)
LIST COLUMN_LIST a,b (3,NULL),(NULL,1)
insert into t1 values (3, NULL); insert into t1 values (3, NULL);
insert into t1 values (NULL, 1); insert into t1 values (NULL, 1);
insert into t1 values (NULL, NULL); insert into t1 values (NULL, NULL);
...@@ -94,6 +100,11 @@ create table t1 (a int) ...@@ -94,6 +100,11 @@ create table t1 (a int)
partition by list (a) partition by list (a)
( partition p0 values in (2, 1), ( partition p0 values in (2, 1),
partition p1 values in (4, NULL, 3)); partition p1 values in (4, NULL, 3));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
LIST a 2,1
LIST a NULL,4,3
insert into t1 values (1); insert into t1 values (1);
insert into t1 values (2); insert into t1 values (2);
insert into t1 values (3); insert into t1 values (3);
...@@ -106,6 +117,11 @@ create table t1 (a int) ...@@ -106,6 +117,11 @@ create table t1 (a int)
partition by list column_list(a) partition by list column_list(a)
( partition p0 values in (column_list(2), column_list(1)), ( partition p0 values in (column_list(2), column_list(1)),
partition p1 values in (column_list(4), column_list(NULL), column_list(3))); partition p1 values in (column_list(4), column_list(NULL), column_list(3)));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
LIST COLUMN_LIST a 2,1
LIST COLUMN_LIST a 4,NULL,3
insert into t1 values (1); insert into t1 values (1);
insert into t1 values (2); insert into t1 values (2);
insert into t1 values (3); insert into t1 values (3);
...@@ -130,6 +146,25 @@ subpartitions 4 ...@@ -130,6 +146,25 @@ subpartitions 4
partition p1 values less than (column_list(1, 'a', MAXVALUE, TO_DAYS('1999-01-01'))), partition p1 values less than (column_list(1, 'a', MAXVALUE, TO_DAYS('1999-01-01'))),
partition p2 values less than (column_list(1, 'a', MAXVALUE, MAXVALUE)), partition p2 values less than (column_list(1, 'a', MAXVALUE, MAXVALUE)),
partition p3 values less than (column_list(1, MAXVALUE, MAXVALUE, MAXVALUE))); partition p3 values less than (column_list(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
RANGE COLUMN_LIST a,b,c,d 1,NULL,MAXVALUE,NULL
RANGE COLUMN_LIST a,b,c,d 1,NULL,MAXVALUE,NULL
RANGE COLUMN_LIST a,b,c,d 1,NULL,MAXVALUE,NULL
RANGE COLUMN_LIST a,b,c,d 1,NULL,MAXVALUE,NULL
RANGE COLUMN_LIST a,b,c,d 1,'a',MAXVALUE,730120
RANGE COLUMN_LIST a,b,c,d 1,'a',MAXVALUE,730120
RANGE COLUMN_LIST a,b,c,d 1,'a',MAXVALUE,730120
RANGE COLUMN_LIST a,b,c,d 1,'a',MAXVALUE,730120
RANGE COLUMN_LIST a,b,c,d 1,'a',MAXVALUE,MAXVALUE
RANGE COLUMN_LIST a,b,c,d 1,'a',MAXVALUE,MAXVALUE
RANGE COLUMN_LIST a,b,c,d 1,'a',MAXVALUE,MAXVALUE
RANGE COLUMN_LIST a,b,c,d 1,'a',MAXVALUE,MAXVALUE
RANGE COLUMN_LIST a,b,c,d 1,MAXVALUE,MAXVALUE,MAXVALUE
RANGE COLUMN_LIST a,b,c,d 1,MAXVALUE,MAXVALUE,MAXVALUE
RANGE COLUMN_LIST a,b,c,d 1,MAXVALUE,MAXVALUE,MAXVALUE
RANGE COLUMN_LIST a,b,c,d 1,MAXVALUE,MAXVALUE,MAXVALUE
drop table t1; drop table t1;
create table t1 (a int, b char(10), c varchar(5), d int) create table t1 (a int, b char(10), c varchar(5), d int)
partition by range column_list(a,b,c) partition by range column_list(a,b,c)
...@@ -139,6 +174,21 @@ subpartitions 3 ...@@ -139,6 +174,21 @@ subpartitions 3
partition p1 values less than (column_list(2,'abc','abc')), partition p1 values less than (column_list(2,'abc','abc')),
partition p2 values less than (column_list(3,'abc','abc')), partition p2 values less than (column_list(3,'abc','abc')),
partition p3 values less than (column_list(4,'abc','abc'))); partition p3 values less than (column_list(4,'abc','abc')));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
RANGE COLUMN_LIST a,b,c 1,'abc','abc'
RANGE COLUMN_LIST a,b,c 1,'abc','abc'
RANGE COLUMN_LIST a,b,c 1,'abc','abc'
RANGE COLUMN_LIST a,b,c 2,'abc','abc'
RANGE COLUMN_LIST a,b,c 2,'abc','abc'
RANGE COLUMN_LIST a,b,c 2,'abc','abc'
RANGE COLUMN_LIST a,b,c 3,'abc','abc'
RANGE COLUMN_LIST a,b,c 3,'abc','abc'
RANGE COLUMN_LIST a,b,c 3,'abc','abc'
RANGE COLUMN_LIST a,b,c 4,'abc','abc'
RANGE COLUMN_LIST a,b,c 4,'abc','abc'
RANGE COLUMN_LIST a,b,c 4,'abc','abc'
insert into t1 values (1,'a','b',1),(2,'a','b',2),(3,'a','b',3); 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,'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); insert into t1 values (1,'c','d',1),(2,'c','d',2),(3,'c','d',3);
...@@ -153,6 +203,11 @@ create table t1 (a int, b varchar(2), c int) ...@@ -153,6 +203,11 @@ create table t1 (a int, b varchar(2), c int)
partition by range column_list (a, b, c) partition by range column_list (a, b, c)
(partition p0 values less than (column_list(1, 'A', 1)), (partition p0 values less than (column_list(1, 'A', 1)),
partition p1 values less than (column_list(1, 'B', 1))); partition p1 values less than (column_list(1, 'B', 1)));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
RANGE COLUMN_LIST a,b,c 1,'A',1
RANGE COLUMN_LIST a,b,c 1,'B',1
insert into t1 values (1, 'A', 1); insert into t1 values (1, 'A', 1);
explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 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 id select_type table partitions type possible_keys key key_len ref rows Extra
......
...@@ -54,6 +54,17 @@ subpartitions 2 ...@@ -54,6 +54,17 @@ subpartitions 2
partition p1 values in (1), partition p1 values in (1),
partition pnull values in (null, 2), partition pnull values in (null, 2),
partition p3 values in (3)); partition p3 values in (3));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
LIST a 0
LIST a 0
LIST a 1
LIST a 1
LIST a NULL,2
LIST a NULL,2
LIST a 3
LIST a 3
insert into t1 values (0,0),(0,1),(1,0),(1,1),(null,0),(null,1); insert into t1 values (0,0),(0,1),(1,0),(1,1),(null,0),(null,1);
insert into t1 values (2,0),(2,1),(3,0),(3,1); insert into t1 values (2,0),(2,1),(3,0),(3,1);
explain partitions select * from t1 where a is null; explain partitions select * from t1 where a is null;
......
...@@ -9,6 +9,11 @@ create table t1 (a datetime not null) ...@@ -9,6 +9,11 @@ create table t1 (a datetime not null)
partition by range (TO_SECONDS(a)) partition by range (TO_SECONDS(a))
( partition p0 VALUES LESS THAN (TO_SECONDS('2007-03-08 00:00:00')), ( partition p0 VALUES LESS THAN (TO_SECONDS('2007-03-08 00:00:00')),
partition p1 VALUES LESS THAN (TO_SECONDS('2007-04-01 00:00:00'))); partition p1 VALUES LESS THAN (TO_SECONDS('2007-04-01 00:00:00')));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
RANGE TO_SECONDS(a) 63340531200
RANGE TO_SECONDS(a) 63342604800
INSERT INTO t1 VALUES ('2007-03-01 12:00:00'), ('2007-03-07 12:00:00'); INSERT INTO t1 VALUES ('2007-03-01 12:00:00'), ('2007-03-07 12:00:00');
INSERT INTO t1 VALUES ('2007-03-08 12:00:00'), ('2007-03-15 12:00:00'); INSERT INTO t1 VALUES ('2007-03-08 12:00:00'), ('2007-03-15 12:00:00');
explain partitions select * from t1 where a < '2007-03-08 00:00:00'; explain partitions select * from t1 where a < '2007-03-08 00:00:00';
......
...@@ -52,6 +52,8 @@ partition by list column_list(a,b) ...@@ -52,6 +52,8 @@ partition by list column_list(a,b)
column_list(NULL, NULL)), column_list(NULL, NULL)),
partition p1 values in (column_list(1,1), column_list(2,2)), partition p1 values in (column_list(1,1), column_list(2,2)),
partition p2 values in (column_list(3, NULL), column_list(NULL, 1))); partition p2 values in (column_list(3, NULL), column_list(NULL, 1)));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
# #
# BUG#47754 Crash when selecting using NOT BETWEEN for column list partitioning # BUG#47754 Crash when selecting using NOT BETWEEN for column list partitioning
# #
...@@ -79,6 +81,8 @@ create table t1 (a int) ...@@ -79,6 +81,8 @@ create table t1 (a int)
partition by list (a) partition by list (a)
( partition p0 values in (2, 1), ( partition p0 values in (2, 1),
partition p1 values in (4, NULL, 3)); partition p1 values in (4, NULL, 3));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
insert into t1 values (1); insert into t1 values (1);
insert into t1 values (2); insert into t1 values (2);
insert into t1 values (3); insert into t1 values (3);
...@@ -92,6 +96,8 @@ create table t1 (a int) ...@@ -92,6 +96,8 @@ create table t1 (a int)
partition by list column_list(a) partition by list column_list(a)
( partition p0 values in (column_list(2), column_list(1)), ( partition p0 values in (column_list(2), column_list(1)),
partition p1 values in (column_list(4), column_list(NULL), column_list(3))); partition p1 values in (column_list(4), column_list(NULL), column_list(3)));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
insert into t1 values (1); insert into t1 values (1);
insert into t1 values (2); insert into t1 values (2);
insert into t1 values (3); insert into t1 values (3);
...@@ -110,6 +116,8 @@ subpartitions 4 ...@@ -110,6 +116,8 @@ subpartitions 4
partition p1 values less than (column_list(1, 'a', MAXVALUE, TO_DAYS('1999-01-01'))), partition p1 values less than (column_list(1, 'a', MAXVALUE, TO_DAYS('1999-01-01'))),
partition p2 values less than (column_list(1, 'a', MAXVALUE, MAXVALUE)), partition p2 values less than (column_list(1, 'a', MAXVALUE, MAXVALUE)),
partition p3 values less than (column_list(1, MAXVALUE, MAXVALUE, MAXVALUE))); partition p3 values less than (column_list(1, MAXVALUE, MAXVALUE, MAXVALUE)));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
drop table t1; drop table t1;
create table t1 (a int, b char(10), c varchar(5), d int) create table t1 (a int, b char(10), c varchar(5), d int)
...@@ -120,6 +128,8 @@ subpartitions 3 ...@@ -120,6 +128,8 @@ subpartitions 3
partition p1 values less than (column_list(2,'abc','abc')), partition p1 values less than (column_list(2,'abc','abc')),
partition p2 values less than (column_list(3,'abc','abc')), partition p2 values less than (column_list(3,'abc','abc')),
partition p3 values less than (column_list(4,'abc','abc'))); partition p3 values less than (column_list(4,'abc','abc')));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
insert into t1 values (1,'a','b',1),(2,'a','b',2),(3,'a','b',3); 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,'b','c',1),(2,'b','c',2),(3,'b','c',3);
...@@ -133,6 +143,8 @@ create table t1 (a int, b varchar(2), c int) ...@@ -133,6 +143,8 @@ create table t1 (a int, b varchar(2), c int)
partition by range column_list (a, b, c) partition by range column_list (a, b, c)
(partition p0 values less than (column_list(1, 'A', 1)), (partition p0 values less than (column_list(1, 'A', 1)),
partition p1 values less than (column_list(1, 'B', 1))); partition p1 values less than (column_list(1, 'B', 1)));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
insert into t1 values (1, 'A', 1); insert into t1 values (1, 'A', 1);
explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 1; explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 1;
select * from t1 where a = 1 AND b <= 'A' and c = 1; select * from t1 where a = 1 AND b <= 'A' and c = 1;
......
...@@ -40,6 +40,8 @@ subpartitions 2 ...@@ -40,6 +40,8 @@ subpartitions 2
partition p1 values in (1), partition p1 values in (1),
partition pnull values in (null, 2), partition pnull values in (null, 2),
partition p3 values in (3)); partition p3 values in (3));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
insert into t1 values (0,0),(0,1),(1,0),(1,1),(null,0),(null,1); insert into t1 values (0,0),(0,1),(1,0),(1,1),(null,0),(null,1);
insert into t1 values (2,0),(2,1),(3,0),(3,1); insert into t1 values (2,0),(2,1),(3,0),(3,1);
......
...@@ -21,6 +21,8 @@ create table t1 (a datetime not null) ...@@ -21,6 +21,8 @@ create table t1 (a datetime not null)
partition by range (TO_SECONDS(a)) partition by range (TO_SECONDS(a))
( partition p0 VALUES LESS THAN (TO_SECONDS('2007-03-08 00:00:00')), ( partition p0 VALUES LESS THAN (TO_SECONDS('2007-03-08 00:00:00')),
partition p1 VALUES LESS THAN (TO_SECONDS('2007-04-01 00:00:00'))); partition p1 VALUES LESS THAN (TO_SECONDS('2007-04-01 00:00:00')));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
INSERT INTO t1 VALUES ('2007-03-01 12:00:00'), ('2007-03-07 12:00:00'); INSERT INTO t1 VALUES ('2007-03-01 12:00:00'), ('2007-03-07 12:00:00');
INSERT INTO t1 VALUES ('2007-03-08 12:00:00'), ('2007-03-15 12:00:00'); INSERT INTO t1 VALUES ('2007-03-08 12:00:00'), ('2007-03-15 12:00:00');
explain partitions select * from t1 where a < '2007-03-08 00:00:00'; explain partitions select * from t1 where a < '2007-03-08 00:00:00';
......
...@@ -4827,6 +4827,43 @@ static void store_schema_partitions_record(THD *thd, TABLE *schema_table, ...@@ -4827,6 +4827,43 @@ static void store_schema_partitions_record(THD *thd, TABLE *schema_table,
return; return;
} }
static int
get_partition_column_description(partition_info *part_info,
part_elem_value *list_value,
String &tmp_str)
{
uint num_elements= part_info->part_field_list.elements;
uint i;
DBUG_ENTER("get_partition_column_description");
for (i= 0; i < num_elements; i++)
{
part_column_list_val *col_val= &list_value->col_val_array[i];
if (col_val->max_value)
tmp_str.append(partition_keywords[PKW_MAXVALUE].str);
else if (col_val->null_value)
tmp_str.append("NULL");
else
{
char buffer[MAX_STR_SIZE_PF];
String str(buffer, sizeof(buffer), &my_charset_bin);
String *res= col_val->item_expression->val_str(&str);
if (!res)
{
my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
DBUG_RETURN(1);
}
if (col_val->item_expression->result_type() == STRING_RESULT)
tmp_str.append("'");
tmp_str.append(*res);
if (col_val->item_expression->result_type() == STRING_RESULT)
tmp_str.append("'");
}
if (i != num_elements - 1)
tmp_str.append(",");
}
DBUG_RETURN(0);
}
static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables, static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
TABLE *table, bool res, TABLE *table, bool res,
...@@ -4837,6 +4874,7 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables, ...@@ -4837,6 +4874,7 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
char buff[61]; char buff[61];
String tmp_res(buff, sizeof(buff), cs); String tmp_res(buff, sizeof(buff), cs);
String tmp_str; String tmp_str;
uint num_elements;
TABLE *show_table= tables->table; TABLE *show_table= tables->table;
handler *file; handler *file;
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
...@@ -4958,36 +4996,68 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables, ...@@ -4958,36 +4996,68 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
/* Partition description */ /* Partition description */
if (part_info->part_type == RANGE_PARTITION) if (part_info->part_type == RANGE_PARTITION)
{ {
if (part_elem->range_value != LONGLONG_MAX) if (part_info->column_list)
table->field[11]->store((longlong) part_elem->range_value, FALSE); {
List_iterator<part_elem_value> list_val_it(part_elem->list_val_list);
part_elem_value *list_value= list_val_it++;
tmp_str.length(0);
if (get_partition_column_description(part_info,
list_value,
tmp_str))
{
DBUG_RETURN(1);
}
table->field[11]->store(tmp_str.ptr(), tmp_str.length(), cs);
}
else else
table->field[11]->store(partition_keywords[PKW_MAXVALUE].str, {
if (part_elem->range_value != LONGLONG_MAX)
table->field[11]->store((longlong) part_elem->range_value, FALSE);
else
table->field[11]->store(partition_keywords[PKW_MAXVALUE].str,
partition_keywords[PKW_MAXVALUE].length, cs); partition_keywords[PKW_MAXVALUE].length, cs);
}
table->field[11]->set_notnull(); table->field[11]->set_notnull();
} }
else if (part_info->part_type == LIST_PARTITION) else if (part_info->part_type == LIST_PARTITION)
{ {
List_iterator<part_elem_value> list_val_it(part_elem->list_val_list); List_iterator<part_elem_value> list_val_it(part_elem->list_val_list);
part_elem_value *list_value; part_elem_value *list_value;
uint no_items= part_elem->list_val_list.elements; uint num_items= part_elem->list_val_list.elements;
tmp_str.length(0); tmp_str.length(0);
tmp_res.length(0); tmp_res.length(0);
if (part_elem->has_null_value) if (part_elem->has_null_value)
{ {
tmp_str.append("NULL"); tmp_str.append("NULL");
if (no_items > 0) if (num_items > 0)
tmp_str.append(","); tmp_str.append(",");
} }
while ((list_value= list_val_it++)) while ((list_value= list_val_it++))
{ {
if (!list_value->unsigned_flag) if (part_info->column_list)
tmp_res.set(list_value->value, cs); {
if (part_info->part_field_list.elements > 1U)
tmp_str.append("(");
if (get_partition_column_description(part_info,
list_value,
tmp_str))
{
DBUG_RETURN(1);
}
if (part_info->part_field_list.elements > 1U)
tmp_str.append(")");
}
else else
tmp_res.set((ulonglong)list_value->value, cs); {
tmp_str.append(tmp_res); if (!list_value->unsigned_flag)
if (--no_items != 0) tmp_res.set(list_value->value, cs);
else
tmp_res.set((ulonglong)list_value->value, cs);
tmp_str.append(tmp_res);
}
if (--num_items != 0)
tmp_str.append(","); tmp_str.append(",");
}; }
table->field[11]->store(tmp_str.ptr(), tmp_str.length(), cs); table->field[11]->store(tmp_str.ptr(), tmp_str.length(), cs);
table->field[11]->set_notnull(); table->field[11]->set_notnull();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment