[Commits] fab3cba: # This is a combination of 4 commits.

Oleksandr Byelkin sanja at mariadb.com
Fri Sep 2 16:09:02 EEST 2016


revision-id: fab3cba6add98a82303c71282474b8b2affeb248 (mariadb-10.2.1-52-gfab3cba)
parent(s): 1eb58ff3b8569d7dad1f5c180a5e55683e53d205
committer: Oleksandr Byelkin
timestamp: 2016-09-02 15:09:02 +0200
message:

# This is a combination of 4 commits.
# The first commit's message is:
MDEV-8348: Add catchall to all table partitioning for list partitions

DEFAULT partition support added to LIST and LIST COLUMN partitioning.
Partitions Prunning added for DEFAULT partititon.

# The 2nd commit message will be skipped:

#	More cleanup

# The 3rd commit message will be skipped:

#	fixed problems of simple list

# The 4th commit message will be skipped:

#	comments

---
 mysql-test/r/partition_default.result | 89 +++++++++++++++++++++++++++++++++++
 mysql-test/t/partition_default.test   | 65 +++++++++++++++++++++++++
 sql/partition_element.h               |  2 +-
 sql/partition_info.cc                 | 19 ++++++--
 sql/partition_info.h                  |  1 +
 sql/share/errmsg-utf8.txt             |  3 ++
 sql/sql_partition.cc                  | 13 +++++
 sql/sql_yacc.yy                       | 21 +++++++++
 8 files changed, 209 insertions(+), 4 deletions(-)

diff --git a/mysql-test/r/partition_default.result b/mysql-test/r/partition_default.result
new file mode 100644
index 0000000..fd04e4d
--- /dev/null
+++ b/mysql-test/r/partition_default.result
@@ -0,0 +1,89 @@
+create table t1 (a int, b int)
+PARTITION BY LIST (a)
+(
+PARTITION p2 VALUES IN (4,5,6),
+PARTITION p1 VALUES IN (1),
+PARTITION p0 DEFAULT
+)
+;
+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
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p2 VALUES IN (4,5,6) ENGINE = MyISAM,
+ PARTITION p1 VALUES IN (1) ENGINE = MyISAM,
+ PARTITION p0 DEFAULT ENGINE = MyISAM) */
+insert into t1 values (10,10);
+select * from t1;
+a	b
+10	10
+drop table t1;
+create table t1 (a int, b int)
+PARTITION BY LIST (a)
+(
+PARTITION p2 VALUES IN (4,5,6),
+PARTITION p1 VALUES IN (1),
+PARTITION p0 DEFAULT,
+PARTITION p3 DEFAULT
+)
+;
+ERROR HY000: Only one DEFAULT partition allowed
+create table t1 (a int, b int)
+PARTITION BY LIST (a)
+(
+PARTITION p0 DEFAULT,
+PARTITION p2 VALUES IN (4,5,6),
+PARTITION p1 VALUES IN (1),
+PARTITION p3 DEFAULT
+)
+;
+ERROR HY000: Only one DEFAULT partition allowed
+create table t1 (a int, b int)
+PARTITION BY LIST (a)
+(
+PARTITION p0 DEFAULT,
+PARTITION p2 VALUES IN (4,5,6),
+PARTITION p1 VALUES IN (1)
+)
+;
+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
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 DEFAULT ENGINE = MyISAM,
+ PARTITION p2 VALUES IN (4,5,6) ENGINE = MyISAM,
+ PARTITION p1 VALUES IN (1) ENGINE = MyISAM) */
+insert into t1 values (10,10);
+select * from t1;
+a	b
+10	10
+drop table t1;
+create table t1 (a int, b int)
+PARTITION BY LIST (a)
+(
+PARTITION p0 DEFAULT,
+PARTITION p2 VALUES IN (4,5,6),
+PARTITION p1 VALUES IN (1, 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
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 DEFAULT ENGINE = MyISAM,
+ PARTITION p2 VALUES IN (4,5,6) ENGINE = MyISAM,
+ PARTITION p1 VALUES IN (1,0) ENGINE = MyISAM) */
+insert into t1 values (10,10);
+select * from t1;
+a	b
+10	10
+drop table t1;
diff --git a/mysql-test/t/partition_default.test b/mysql-test/t/partition_default.test
new file mode 100644
index 0000000..5becfbb
--- /dev/null
+++ b/mysql-test/t/partition_default.test
@@ -0,0 +1,65 @@
+
+--source include/have_partition.inc
+
+create table t1 (a int, b int)
+  PARTITION BY LIST (a)
+  (
+    PARTITION p2 VALUES IN (4,5,6),
+    PARTITION p1 VALUES IN (1),
+    PARTITION p0 DEFAULT
+  )
+;
+show create table t1;
+insert into t1 values (10,10);
+select * from t1;
+drop table t1;
+
+--error ER_PARTITION_DEFAULT_ERROR
+create table t1 (a int, b int)
+  PARTITION BY LIST (a)
+  (
+    PARTITION p2 VALUES IN (4,5,6),
+    PARTITION p1 VALUES IN (1),
+    PARTITION p0 DEFAULT,
+    PARTITION p3 DEFAULT
+  )
+;
+--error ER_PARTITION_DEFAULT_ERROR
+create table t1 (a int, b int)
+  PARTITION BY LIST (a)
+  (
+    PARTITION p0 DEFAULT,
+    PARTITION p2 VALUES IN (4,5,6),
+    PARTITION p1 VALUES IN (1),
+    PARTITION p3 DEFAULT
+  )
+;
+
+create table t1 (a int, b int)
+  PARTITION BY LIST (a)
+  (
+    PARTITION p0 DEFAULT,
+    PARTITION p2 VALUES IN (4,5,6),
+    PARTITION p1 VALUES IN (1)
+  )
+;
+show create table t1;
+insert into t1 values (10,10);
+select * from t1;
+drop table t1;
+
+#
+# Default has its value as 0 check that they are not clash.
+#
+create table t1 (a int, b int)
+  PARTITION BY LIST (a)
+  (
+    PARTITION p0 DEFAULT,
+    PARTITION p2 VALUES IN (4,5,6),
+    PARTITION p1 VALUES IN (1, 0)
+  )
+;
+show create table t1;
+insert into t1 values (10,10);
+select * from t1;
+drop table t1;
diff --git a/sql/partition_element.h b/sql/partition_element.h
index 308a4d6..b979b7a 100644
--- a/sql/partition_element.h
+++ b/sql/partition_element.h
@@ -65,7 +65,7 @@ typedef struct p_column_list_val
   Item* item_expression;
   partition_info *part_info;
   uint partition_id;
-  bool max_value;
+  bool max_value; // MAXVALUE for RANGE type or DEFAULT value for LIST type
   bool null_value;
   char fixed;
 } part_column_list_val;
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index 4f297c6..0c0ab14 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -1557,6 +1557,13 @@ bool partition_info::check_list_constants(THD *thd)
     do
     {
       part_def= list_func_it++;
+      if (part_def->max_value && 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--;
+        continue;
+      }
       List_iterator<part_elem_value> list_val_it2(part_def->list_val_list);
       while ((list_value= list_val_it2++))
       {
@@ -2584,20 +2591,26 @@ int partition_info::fix_partition_values(THD *thd,
   if (col_val->max_value)
   {
     /* The parser ensures we're not LIST partitioned here */
-    DBUG_ASSERT(part_type == RANGE_PARTITION);
+    DBUG_ASSERT(part_type == RANGE_PARTITION ||
+                part_type == LIST_PARTITION);
     if (defined_max_value)
     {
-      my_error(ER_PARTITION_MAXVALUE_ERROR, MYF(0));
+      my_error((part_type == RANGE_PARTITION) ?
+               ER_PARTITION_MAXVALUE_ERROR :
+               ER_PARTITION_DEFAULT_ERROR, MYF(0));
       DBUG_RETURN(TRUE);
     }
-    if (part_id == (num_parts - 1))
+    if (part_id == (num_parts - 1) ||
+        part_type == LIST_PARTITION)
     {
       defined_max_value= TRUE;
+      default_partition_id= part_id;
       part_elem->max_value= TRUE;
       part_elem->range_value= LONGLONG_MAX;
     }
     else
     {
+      DBUG_ASSERT(part_type != LIST_PARTITION);
       my_error(ER_PARTITION_MAXVALUE_ERROR, MYF(0));
       DBUG_RETURN(TRUE);
     }
diff --git a/sql/partition_info.h b/sql/partition_info.h
index 5181e19..0c7448f 100644
--- a/sql/partition_info.h
+++ b/sql/partition_info.h
@@ -202,6 +202,7 @@ class partition_info : public Sql_alloc
   uint num_full_part_fields;
 
   uint has_null_part_id;
+  uint32 default_partition_id;
   /*
     This variable is used to calculate the partition id when using
     LINEAR KEY/HASH. This functionality is kept in the MySQL Server
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 361d68f..af85e1c 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -7213,3 +7213,6 @@ ER_CALCULATING_DEFAULT_VALUE
         eng "Got an error when calculating default value for %`s"
 ER_EXPRESSION_REFERS_TO_UNINIT_FIELD 01000
         eng "Expression for field %`-.64s is refering to uninitialized field %`s"
+ER_PARTITION_DEFAULT_ERROR
+        eng "Only one DEFAULT partition allowed"
+        ukr "Припустимо мати тільки один DEFAULT розділ" 
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index b45f855..260f5e0 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -2311,6 +2311,14 @@ static int add_partition_values(File fptr, partition_info *part_info,
   {
     uint i;
     List_iterator<part_elem_value> list_val_it(p_elem->list_val_list);
+
+    if (p_elem->max_value)
+    {
+      DBUG_ASSERT(part_info->defined_max_value);
+      err+= add_string(fptr, " DEFAULT");
+      goto end;
+    }
+
     err+= add_string(fptr, " VALUES IN ");
     uint num_items= p_elem->list_val_list.elements;
 
@@ -3123,6 +3131,11 @@ int get_partition_id_list(partition_info *part_info,
     }
   }
 notfound:
+  if (part_info->defined_max_value)
+  {
+    *part_id= part_info->default_partition_id;
+    DBUG_RETURN(0);
+  }
   *part_id= 0;
   DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
 }
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 9d7e735..072eb1b 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -5242,6 +5242,27 @@ opt_part_values:
               part_info->part_type= LIST_PARTITION;
           }
           part_values_in {}
+        | DEFAULT
+         {
+            LEX *lex= Lex;
+            partition_info *part_info= lex->part_info;
+            if (! lex->is_partition_management())
+            {
+              if (part_info->part_type != LIST_PARTITION)
+                my_yyabort_error((ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
+                                  "LIST", "DEFAULT"));
+            }
+            else
+              part_info->part_type= LIST_PARTITION;
+            if (part_info->init_column_part(thd))
+            {
+              MYSQL_YYABORT;
+            }
+            if (part_info->add_max_value(thd))
+            {
+              MYSQL_YYABORT;
+            }
+         }
         ;
 
 part_func_max:


More information about the commits mailing list