summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Ronstrom <mikael@mysql.com>2009-10-21 20:04:34 +0200
committerMikael Ronstrom <mikael@mysql.com>2009-10-21 20:04:34 +0200
commite30ccf7a6772f52f1357d5e7ddba61660c9f73b8 (patch)
tree9f9a8ea4d4acd71a4326343ce9da44073ec93d76
parent9ef69958c5f9c0078b6e440cc2730c459d40964f (diff)
downloadmariadb-git-e30ccf7a6772f52f1357d5e7ddba61660c9f73b8.tar.gz
Fixed Information schema for column list partitioned tables
-rw-r--r--mysql-test/r/partition_column.result55
-rw-r--r--mysql-test/r/partition_list.result11
-rw-r--r--mysql-test/r/partition_range.result5
-rw-r--r--mysql-test/t/partition_column.test12
-rw-r--r--mysql-test/t/partition_list.test2
-rw-r--r--mysql-test/t/partition_range.test2
-rw-r--r--sql/sql_show.cc92
7 files changed, 168 insertions, 11 deletions
diff --git a/mysql-test/r/partition_column.result b/mysql-test/r/partition_column.result
index fb7f815fd98..c4333f9c101 100644
--- a/mysql-test/r/partition_column.result
+++ b/mysql-test/r/partition_column.result
@@ -50,6 +50,12 @@ partition by list column_list(a,b)
column_list(NULL, NULL)),
partition p1 values in (column_list(1,1), column_list(2,2)),
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 (NULL, 1);
insert into t1 values (NULL, NULL);
@@ -94,6 +100,11 @@ create table t1 (a int)
partition by list (a)
( partition p0 values in (2, 1),
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 (2);
insert into t1 values (3);
@@ -106,6 +117,11 @@ create table t1 (a int)
partition by list column_list(a)
( partition p0 values in (column_list(2), column_list(1)),
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 (2);
insert into t1 values (3);
@@ -130,6 +146,25 @@ subpartitions 4
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 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;
create table t1 (a int, b char(10), c varchar(5), d int)
partition by range column_list(a,b,c)
@@ -139,6 +174,21 @@ subpartitions 3
partition p1 values less than (column_list(2,'abc','abc')),
partition p2 values less than (column_list(3,'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,'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);
@@ -153,6 +203,11 @@ create table t1 (a int, b varchar(2), c int)
partition by range column_list (a, b, c)
(partition p0 values less than (column_list(1, 'A', 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);
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/r/partition_list.result b/mysql-test/r/partition_list.result
index a68a67c6386..e22fc11e5bb 100644
--- a/mysql-test/r/partition_list.result
+++ b/mysql-test/r/partition_list.result
@@ -54,6 +54,17 @@ subpartitions 2
partition p1 values in (1),
partition pnull values in (null, 2),
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 (2,0),(2,1),(3,0),(3,1);
explain partitions select * from t1 where a is null;
diff --git a/mysql-test/r/partition_range.result b/mysql-test/r/partition_range.result
index 237d026fe6e..4e18c9668e9 100644
--- a/mysql-test/r/partition_range.result
+++ b/mysql-test/r/partition_range.result
@@ -9,6 +9,11 @@ create table t1 (a datetime not null)
partition by range (TO_SECONDS(a))
( 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')));
+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-08 12:00:00'), ('2007-03-15 12:00:00');
explain partitions select * from t1 where a < '2007-03-08 00:00:00';
diff --git a/mysql-test/t/partition_column.test b/mysql-test/t/partition_column.test
index 1c7e8d59895..0cb99ebfcc2 100644
--- a/mysql-test/t/partition_column.test
+++ b/mysql-test/t/partition_column.test
@@ -52,6 +52,8 @@ partition by list column_list(a,b)
column_list(NULL, NULL)),
partition p1 values in (column_list(1,1), column_list(2,2)),
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
#
@@ -79,6 +81,8 @@ create table t1 (a int)
partition by list (a)
( partition p0 values in (2, 1),
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 (2);
insert into t1 values (3);
@@ -92,6 +96,8 @@ create table t1 (a int)
partition by list column_list(a)
( partition p0 values in (column_list(2), column_list(1)),
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 (2);
insert into t1 values (3);
@@ -110,6 +116,8 @@ subpartitions 4
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 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;
create table t1 (a int, b char(10), c varchar(5), d int)
@@ -120,6 +128,8 @@ subpartitions 3
partition p1 values less than (column_list(2,'abc','abc')),
partition p2 values less than (column_list(3,'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,'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)
partition by range column_list (a, b, c)
(partition p0 values less than (column_list(1, 'A', 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);
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;
diff --git a/mysql-test/t/partition_list.test b/mysql-test/t/partition_list.test
index 1c76de9d55a..8d2ec88e0f4 100644
--- a/mysql-test/t/partition_list.test
+++ b/mysql-test/t/partition_list.test
@@ -40,6 +40,8 @@ subpartitions 2
partition p1 values in (1),
partition pnull values in (null, 2),
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 (2,0),(2,1),(3,0),(3,1);
diff --git a/mysql-test/t/partition_range.test b/mysql-test/t/partition_range.test
index 741bae7b3cc..df4982298f9 100644
--- a/mysql-test/t/partition_range.test
+++ b/mysql-test/t/partition_range.test
@@ -21,6 +21,8 @@ create table t1 (a datetime not null)
partition by range (TO_SECONDS(a))
( 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')));
+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-08 12:00:00'), ('2007-03-15 12:00:00');
explain partitions select * from t1 where a < '2007-03-08 00:00:00';
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 3aef62dfb31..a74e9363bcf 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -4827,6 +4827,43 @@ static void store_schema_partitions_record(THD *thd, TABLE *schema_table,
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,
TABLE *table, bool res,
@@ -4837,6 +4874,7 @@ 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
@@ -4958,36 +4996,68 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
/* Partition description */
if (part_info->part_type == RANGE_PARTITION)
{
- if (part_elem->range_value != LONGLONG_MAX)
- table->field[11]->store((longlong) part_elem->range_value, FALSE);
+ if (part_info->column_list)
+ {
+ 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
- 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);
+ }
table->field[11]->set_notnull();
}
else if (part_info->part_type == LIST_PARTITION)
{
List_iterator<part_elem_value> list_val_it(part_elem->list_val_list);
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_res.length(0);
if (part_elem->has_null_value)
{
tmp_str.append("NULL");
- if (no_items > 0)
+ if (num_items > 0)
tmp_str.append(",");
}
while ((list_value= list_val_it++))
{
- if (!list_value->unsigned_flag)
- tmp_res.set(list_value->value, cs);
+ if (part_info->column_list)
+ {
+ 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
- tmp_res.set((ulonglong)list_value->value, cs);
- tmp_str.append(tmp_res);
- if (--no_items != 0)
+ {
+ if (!list_value->unsigned_flag)
+ 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(",");
- };
+ }
table->field[11]->store(tmp_str.ptr(), tmp_str.length(), cs);
table->field[11]->set_notnull();
}