[Commits] 87c6bd2: Postreview fixes and more

Oleksandr Byelkin sanja at mariadb.com
Wed Sep 7 18:24:29 EEST 2016


revision-id: 87c6bd26ab910a69c92a610c185aa703d4a2a170 (mariadb-10.2.1-53-g87c6bd2)
parent(s): 06310902e5754fc2ead73d903267bb9fa85b85b2
committer: Oleksandr Byelkin
timestamp: 2016-09-07 17:24:28 +0200
message:

Postreview fixes and more

---
 mysql-test/r/partition_default.result | 107 ++++++++++++++++++++++++++++++++--
 mysql-test/t/partition_default.test   |  51 ++++++++++++++++
 sql/partition_info.cc                 |   4 +-
 sql/sql_partition.cc                  |  28 +++++----
 4 files changed, 172 insertions(+), 18 deletions(-)

diff --git a/mysql-test/r/partition_default.result b/mysql-test/r/partition_default.result
index 09d7a65..ab9fa58 100644
--- a/mysql-test/r/partition_default.result
+++ b/mysql-test/r/partition_default.result
@@ -34,9 +34,9 @@ a	b
 10	10
 select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 partition_name	table_rows
-p2	1
-p1	0
 p0	1
+p1	0
+p2	1
 drop table t1;
 create table t1 (a int, b int)
 PARTITION BY LIST (a)
@@ -80,6 +80,11 @@ insert into t1 values (10,10);
 select * from t1;
 a	b
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	0
+p2	0
 drop table t1;
 create table t1 (a int, b int)
 PARTITION BY LIST (a)
@@ -103,6 +108,11 @@ insert into t1 values (10,10);
 select * from t1;
 a	b
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	0
+p2	0
 drop table t1;
 create table t1 (a int, b int)
 PARTITION BY LIST COLUMNS(a,b)
@@ -126,6 +136,11 @@ insert into t1 values (10,10);
 select * from t1;
 a	b
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	0
+p2	0
 drop table t1;
 create table t1 (a int, b int)
 PARTITION BY LIST COLUMNS(a,b)
@@ -166,6 +181,11 @@ t1	CREATE TABLE `t1` (
  PARTITION p1 VALUES IN (1,20) ENGINE = MyISAM,
  PARTITION p0 DEFAULT ENGINE = MyISAM) */
 insert into t1 values (10,10);
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	0
+p2	0
 select * from t1 where a=10;
 a	b
 10	10
@@ -182,6 +202,11 @@ select * from t1 where a>=5;
 a	b
 10	10
 insert into t1 values (20,20),(5,5);
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
+p2	1
 select * from t1 where a=10;
 a	b
 10	10
@@ -236,6 +261,11 @@ t1	CREATE TABLE `t1` (
  PARTITION p1 VALUES IN ((1,1),(20,20)) ENGINE = MyISAM,
  PARTITION p0 DEFAULT ENGINE = MyISAM) */
 insert into t1 values (10,10);
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	0
+p2	0
 select * from t1 where a=10 and b=10;
 a	b
 10	10
@@ -255,6 +285,11 @@ select * from t1 where a>=10;
 a	b
 10	10
 insert into t1 values (20,20),(5,5);
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
+p2	1
 select * from t1 where a=10 and b=10;
 a	b
 10	10
@@ -336,6 +371,11 @@ a	b
 2	5
 10	10
 0	0
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	2
+p1	0
+p2	1
 explain partitions select * from t1 where a>=2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p2,p1,p0	ALL	NULL	NULL	NULL	NULL	3	Using where
@@ -801,6 +841,11 @@ a	b
 2	5
 0	0
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
+p2	1
 explain partitions select * from t1 where a=2 and b=5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p2	system	NULL	NULL	NULL	NULL	1	
@@ -830,6 +875,11 @@ a	b
 2	5
 0	0
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
+p2	1
 explain partitions select * from t1 where a=2 and b=5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p2	system	NULL	NULL	NULL	NULL	1	
@@ -859,6 +909,11 @@ a	b
 2	5
 0	0
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
+p2	1
 explain partitions select * from t1 where a=2 and b=5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p2	system	NULL	NULL	NULL	NULL	1	
@@ -882,6 +937,10 @@ select * from t1;
 a	b
 0	0
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
 alter table t1 add partition (PARTITION pd DEFAULT);
 show create table t1;
 Table	Create Table
@@ -930,6 +989,11 @@ a	b
 2	5
 0	0
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
+p2	1
 explain partitions select * from t1 where a=2 and b=5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p2	system	NULL	NULL	NULL	NULL	1	
@@ -959,6 +1023,11 @@ a	b
 2	5
 0	0
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
+p2	1
 explain partitions select * from t1 where a=2 and b=5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p2	system	NULL	NULL	NULL	NULL	1	
@@ -988,6 +1057,11 @@ a	b
 2	5
 0	0
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
+p2	1
 explain partitions select * from t1 where a=2 and b=5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p2	system	NULL	NULL	NULL	NULL	1	
@@ -1011,6 +1085,10 @@ select * from t1;
 a	b
 0	0
 10	10
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
+partition_name	table_rows
+p0	1
+p1	1
 alter table t1 add partition (PARTITION pd DEFAULT);
 show create table t1;
 Table	Create Table
@@ -1040,15 +1118,34 @@ PARTITION pd DEFAULT
 insert into t1 values (1),(2),(3),(4);
 select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 partition_name	table_rows
-p2	1
 p1	1
+p2	1
 pd	2
 alter table t1 add partition
 (partition p0 VALUES IN (2,3));
 select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 partition_name	table_rows
-p2	1
+p0	2
 p1	1
+p2	1
 pd	0
-p0	2
+drop table t1;
+create table t1 (a int, b int)
+PARTITION BY LIST COLUMNS(a,b)
+(
+PARTITION p0 DEFAULT,
+PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)),
+PARTITION p1 VALUES IN ((1,1),(0,0))
+)
+;
+show create table t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50500 PARTITION BY LIST  COLUMNS(a,b)
+(PARTITION p0 DEFAULT ENGINE = MyISAM,
+ PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)) ENGINE = MyISAM,
+ PARTITION p1 VALUES IN ((1,1),(0,0)) ENGINE = MyISAM) */
 drop table t1;
diff --git a/mysql-test/t/partition_default.test b/mysql-test/t/partition_default.test
index 07f85fe..8f7fe58 100644
--- a/mysql-test/t/partition_default.test
+++ b/mysql-test/t/partition_default.test
@@ -26,6 +26,7 @@ show create table t1;
 insert into t1 values (10,10);
 insert into t1 values (4,4);
 select * from t1;
+--sorted_result
 select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 drop table t1;
 
@@ -61,6 +62,8 @@ create table t1 (a int, b int)
 show create table t1;
 insert into t1 values (10,10);
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 drop table t1;
 
 #
@@ -77,6 +80,8 @@ create table t1 (a int, b int)
 show create table t1;
 insert into t1 values (10,10);
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 drop table t1;
 
 #
@@ -93,6 +98,8 @@ create table t1 (a int, b int)
 show create table t1;
 insert into t1 values (10,10);
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 drop table t1;
 
 --error ER_PARTITION_DEFAULT_ERROR
@@ -131,12 +138,16 @@ create table t1 (a int, b int)
 ;
 show create table t1;
 insert into t1 values (10,10);
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 select * from t1 where a=10;
 select * from t1 where a<=10;
 select * from t1 where a<=20;
 select * from t1 where a>=10;
 select * from t1 where a>=5;
 insert into t1 values (20,20),(5,5);
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 select * from t1 where a=10;
 select * from t1 where a<=10;
 select * from t1 where a<=20;
@@ -159,6 +170,8 @@ create table t1 (a int, b int)
 ;
 show create table t1;
 insert into t1 values (10,10);
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 select * from t1 where a=10 and b=10;
 explain partitions select * from t1 where a=10 and b=10;
 select * from t1 where a=10;
@@ -166,6 +179,8 @@ explain partitions select * from t1 where a=10;
 select * from t1 where a<=10;
 select * from t1 where a>=10;
 insert into t1 values (20,20),(5,5);
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 select * from t1 where a=10 and b=10;
 explain partitions select * from t1 where a=10 and b=10;
 select * from t1 where a=10 and b=10 or a=20 and b=20;
@@ -211,6 +226,8 @@ alter table t1
 ;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 explain partitions select * from t1 where a>=2;
 explain partitions select * from t1 where a>=2 and a<=3;
 explain partitions select * from t1 where a=10;
@@ -276,6 +293,8 @@ alter table t1
 ;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 explain partitions select * from t1 where a=2 and b=5;
 explain partitions select * from t1 where a=10 and b=10;
 alter table t1
@@ -288,6 +307,8 @@ alter table t1
 ;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 explain partitions select * from t1 where a=2 and b=5;
 explain partitions select * from t1 where a=10 and b=10;
 alter table t1
@@ -300,6 +321,8 @@ alter table t1
 ;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 explain partitions select * from t1 where a=2 and b=5;
 explain partitions select * from t1 where a=10 and b=10;
 
@@ -309,6 +332,8 @@ delete from t1 where a=2;
 alter table t1 drop partition p2;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 
 alter table t1 add partition (PARTITION pd DEFAULT);
 show create table t1;
@@ -337,6 +362,8 @@ alter table t1
 ;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 explain partitions select * from t1 where a=2 and b=5;
 explain partitions select * from t1 where a=10 and b=10;
 alter table t1
@@ -349,6 +376,8 @@ alter table t1
 ;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 explain partitions select * from t1 where a=2 and b=5;
 explain partitions select * from t1 where a=10 and b=10;
 alter table t1
@@ -361,6 +390,8 @@ alter table t1
 ;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 explain partitions select * from t1 where a=2 and b=5;
 explain partitions select * from t1 where a=10 and b=10;
 
@@ -370,6 +401,8 @@ delete from t1 where a=2;
 alter table t1 drop partition p2;
 show create table t1;
 select * from t1;
+--sorted_result
+select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 
 alter table t1 add partition (PARTITION pd DEFAULT);
 show create table t1;
@@ -394,11 +427,29 @@ create table t1 (a int)
   )
 ;
 insert into t1 values (1),(2),(3),(4);
+--sorted_result
 select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 
 alter table t1 add partition
  (partition p0 VALUES IN (2,3));
 
+--sorted_result
 select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
 
 drop table t1;
+
+#
+# Check that first DEFAULT works in LIST COLUMN
+#
+create table t1 (a int, b int)
+  PARTITION BY LIST COLUMNS(a,b)
+  (
+    PARTITION p0 DEFAULT,
+    PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)),
+    PARTITION p1 VALUES IN ((1,1),(0,0))
+  )
+;
+
+show create table t1;
+
+drop table t1;
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index de41523..9d31667 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -1472,6 +1472,8 @@ bool partition_info::check_list_constants(THD *thd)
   List_iterator<partition_element> list_func_it(partitions);
   DBUG_ENTER("partition_info::check_list_constants");
 
+  DBUG_ASSERT(part_type == LIST_PARTITION);
+
   num_list_values= 0;
   /*
     We begin by calculating the number of list values that have been
@@ -1524,7 +1526,6 @@ bool partition_info::check_list_constants(THD *thd)
       part_def= list_func_it++;
       if (part_def->max_value)
       {
-        DBUG_ASSERT(part_type == LIST_PARTITION);
         // DEFAULT is not a real value so let's exclude it from sorting.
         DBUG_ASSERT(num_list_values);
         num_list_values--;
@@ -2816,6 +2817,7 @@ bool partition_info::fix_parser_data(THD *thd)
         key_algorithm == KEY_ALGORITHM_NONE)
       key_algorithm= KEY_ALGORITHM_55;
   }
+  defined_max_value= FALSE; // in case it already set (CREATE TABLE LIKE)
   do
   {
     part_elem= it++;
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index fdbce23..54396b9 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -4710,9 +4710,12 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
     DBUG_RETURN(TRUE);
   }
 
-  thd->work_part_info= thd->lex->part_info;
-  partition_info *alt_part_info= thd->work_part_info;
-  bool only_default_value=
+  partition_info *alt_part_info= thd->lex->part_info;
+  /*
+    This variable is TRUE in very special case when we add only DEFAULT
+    partition to the existing table
+  */
+  bool only_default_value_added=
     (alt_part_info &&
      alt_part_info->current_partition &&
      alt_part_info->current_partition->list_val_list.elements == 1 &&
@@ -4720,12 +4723,13 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
      added_items >= 1 &&
      alt_part_info->current_partition->list_val_list.head()->
      col_val_array[0].max_value) &&
-    alt_part_info->part_type == LIST_PARTITION;
-  if (only_default_value &&
+    alt_part_info->part_type == LIST_PARTITION &&
+    (alter_info->flags & Alter_info::ALTER_ADD_PARTITION);
+  if (only_default_value_added &&
       !thd->lex->part_info->num_columns)
     thd->lex->part_info->num_columns= 1; // to make correct clone
 
-  if (thd->work_part_info &&
+  if ((thd->work_part_info= thd->lex->part_info) &&
       !(thd->work_part_info= thd->lex->part_info->get_clone(thd)))
     DBUG_RETURN(TRUE);
 
@@ -4913,12 +4917,12 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
       }
       if ((tab_part_info->column_list &&
           alt_part_info->num_columns != tab_part_info->num_columns &&
-          !only_default_value) ||
+          !only_default_value_added) ||
           (!tab_part_info->column_list &&
             (tab_part_info->part_type == RANGE_PARTITION ||
              tab_part_info->part_type == LIST_PARTITION) &&
             alt_part_info->num_columns != 1U &&
-             !only_default_value) ||
+             !only_default_value_added) ||
           (!tab_part_info->column_list &&
             tab_part_info->part_type == HASH_PARTITION &&
             (alt_part_info->num_columns != 0)))
@@ -4958,8 +4962,8 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
           (tab_part_info->part_type == RANGE_PARTITION ||
            alt_part_info->defined_max_value))
       {
-        my_error((tab_part_info->part_type == RANGE_PARTITION?
-                  ER_PARTITION_MAXVALUE_ERROR:
+        my_error((tab_part_info->part_type == RANGE_PARTITION ?
+                  ER_PARTITION_MAXVALUE_ERROR :
                   ER_PARTITION_DEFAULT_ERROR), MYF(0));
         goto err;
       }
@@ -7740,7 +7744,7 @@ int get_part_iter_for_interval_cols_via_map(partition_info *part_info,
                                (NO_MIN_RANGE | NO_MAX_RANGE | NEAR_MIN |
                                 NEAR_MAX)) ||
                               memcmp(min_value, max_value, min_len));
-  DBUG_ASSERT(can_match_multiple_values || !(flags & (~EQ_RANGE)));
+  DBUG_ASSERT(can_match_multiple_values || (flags & EQ_RANGE) || flags == 0);
   if (can_match_multiple_values && part_info->has_default_partititon())
     part_iter->ret_default_part= part_iter->ret_default_part_orig= TRUE;
 
@@ -7889,7 +7893,7 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info,
                                (NO_MIN_RANGE | NO_MAX_RANGE | NEAR_MIN |
                                 NEAR_MAX)) ||
                               memcmp(min_value, max_value, field_len));
-  DBUG_ASSERT(can_match_multiple_values || !(flags & (~EQ_RANGE)));
+  DBUG_ASSERT(can_match_multiple_values || (flags & EQ_RANGE) || flags == 0);
   if (can_match_multiple_values && part_info->has_default_partititon())
     part_iter->ret_default_part= part_iter->ret_default_part_orig= TRUE;
   if (can_match_multiple_values &&


More information about the commits mailing list