List:Commits« Previous MessageNext Message »
From:Alexey Kopytov Date:August 27 2009 4:06pm
Subject:bzr commit into mysql-5.1-bugteam branch (Alexey.Kopytov:2920)
Bug#42849
View as plain text  
#At file:///data/src/bzr/bugteam/bug42849/my51-bug42849/ based on revid:alexey.kopytov@stripped0090601124448-i5iz72e0reh5pbmn

 2920 Alexey Kopytov	2009-08-27
      Bug #42849: innodb crash with varying time_zone on partitioned 
                  timestamp primary key 
       
      Since TIMESTAMP values are adjusted by the current time zone 
      settings, using any expressions involving TIMESTAMP values as a 
      (sub)partitioning function leads to undeterministic behavior of 
      partitioned tables. The effect may vary depending on a storage 
      engine, it can be either incorrect data being retrieved or 
      stored, or an assertion failure. The root cause of this is the 
      fact that the calculated partition ID may differ from a 
      previously calculated ID for the same data due to timezone 
      adjustments of the partitioning expression value. 
       
      Fixed by disabling any expressions involving TIMESTAMP values 
      to be used in partitioning functions. 
     @ mysql-test/r/partition_error.result
        Test case for bug #42849: check that any arithmetic 
        expressions or functions allowed for partitioning cannot
        be used in partitioning expression.
     @ mysql-test/t/partition_error.test
        Test case for bug #42849: check that any arithmetic 
        expressions or functions allowed for partitioning cannot
        be used in partitioning expression.
     @ sql/item_timefunc.h
        Changed the check_partition_func_processor() method of all
        Items that correspond to functions allowed in partitioning
        to check whether their argument has the TIMESTAMP type.
     @ sql/share/errmsg.txt
        Renamed ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR to
        ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR to better reflect the
        meaning. Adjusted the error message.
     @ sql/sql_partition.cc
        Modified fix_fields_part_func() to do another walk through
        Items tree with check_partition_func_processor() to check
        if none of the expression arguments has the TIMESTAMP type.
     @ sql/sql_yacc.yy
        ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR ->
        ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR.

    modified:
      mysql-test/r/partition_error.result
      mysql-test/t/partition_error.test
      sql/item.h
      sql/item_func.h
      sql/item_timefunc.h
      sql/share/errmsg.txt
      sql/sql_partition.cc
      sql/sql_yacc.yy
=== modified file 'mysql-test/r/partition_error.result'
--- a/mysql-test/r/partition_error.result	2009-02-18 20:29:30 +0000
+++ b/mysql-test/r/partition_error.result	2009-08-27 16:06:24 +0000
@@ -138,7 +138,7 @@ primary key(a,b))
 partition by hash (rand(a))
 partitions 2
 (partition x1, partition x2);
-ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')
+ERROR 42000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near ')
 partitions 2
 (partition x1, partition x2)' at line 6
 CREATE TABLE t1 (
@@ -149,7 +149,7 @@ primary key(a,b))
 partition by range (rand(a))
 partitions 2
 (partition x1 values less than (0), partition x2 values less than (2));
-ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')
+ERROR 42000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near ')
 partitions 2
 (partition x1 values less than (0), partition x2 values less than' at line 6
 CREATE TABLE t1 (
@@ -160,7 +160,7 @@ primary key(a,b))
 partition by list (rand(a))
 partitions 2
 (partition x1 values in (1), partition x2 values in (2));
-ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')
+ERROR 42000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near ')
 partitions 2
 (partition x1 values in (1), partition x2 values in (2))' at line 6
 CREATE TABLE t1 (
@@ -275,7 +275,7 @@ c int not null,
 primary key (a,b))
 partition by key (a)
 subpartition by hash (rand(a+b));
-ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')' at line 7
+ERROR 42000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near ')' at line 7
 CREATE TABLE t1 (
 a int not null,
 b int not null,
@@ -372,7 +372,7 @@ partition by range (3+4)
 partitions 2
 (partition x1 values less than (4) tablespace ts1,
 partition x2 values less than (8) tablespace ts2);
-ERROR HY000: Constant/Random expression in (sub)partitioning function is not allowed
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
 CREATE TABLE t1 ( 
 a int not null,
 b int not null,
@@ -542,7 +542,7 @@ partition by list (3+4)
 partitions 2 
 (partition x1 values in (4) tablespace ts1,
 partition x2 values in (8) tablespace ts2);
-ERROR HY000: Constant/Random expression in (sub)partitioning function is not allowed
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
 CREATE TABLE t1 (
 a int not null,
 b int not null,
@@ -634,13 +634,13 @@ partition by range (ascii(v))
 ERROR HY000: This partition function is not allowed
 create table t1 (a int)
 partition by hash (rand(a));
-ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')' at line 2
+ERROR 42000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near ')' at line 2
 create table t1 (a int)
 partition by hash(CURTIME() + a);
-ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')' at line 2
+ERROR 42000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near ')' at line 2
 create table t1 (a int)
 partition by hash (NOW()+a);
-ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')' at line 2
+ERROR 42000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near ')' at line 2
 create table t1 (a int)
 partition by hash (extract(hour from convert_tz(a, '+00:00', '+00:00')));
 ERROR HY000: This partition function is not allowed
@@ -651,3 +651,118 @@ ERROR HY000: This partition function is 
 create table t1 (a char(10))
 partition by hash (extractvalue(a,'a'));
 ERROR HY000: This partition function is not allowed
+#
+# Bug #42849: innodb crash with varying time_zone on partitioned
+#             timestamp primary key
+#
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (a) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: The PARTITION function returns the wrong type
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (a+0) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: The PARTITION function returns the wrong type
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (a % 2) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: The PARTITION function returns the wrong type
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (ABS(a)) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: The PARTITION function returns the wrong type
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (CEILING(a)) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: The PARTITION function returns the wrong type
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (FLOOR(a)) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: The PARTITION function returns the wrong type
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (TO_DAYS(a)) (
+PARTITION p VALUES LESS THAN (733638), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (DAYOFYEAR(a)) (
+PARTITION p VALUES LESS THAN (231), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (DAYOFMONTH(a)) (
+PARTITION p VALUES LESS THAN (19), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (DAYOFWEEK(a)) (
+PARTITION p VALUES LESS THAN (3), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (MONTH(a)) (
+PARTITION p VALUES LESS THAN (8), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (HOUR(a)) (
+PARTITION p VALUES LESS THAN (17), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (MINUTE(a)) (
+PARTITION p VALUES LESS THAN (55), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (QUARTER(a)) (
+PARTITION p VALUES LESS THAN (3), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (SECOND(a)) (
+PARTITION p VALUES LESS THAN (7), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (YEARWEEK(a)) (
+PARTITION p VALUES LESS THAN (200833), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (YEAR(a)) (
+PARTITION p VALUES LESS THAN (2008), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (WEEKDAY(a)) (
+PARTITION p VALUES LESS THAN (3), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (WEEKDAY(a)) (
+PARTITION p VALUES LESS THAN (3), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (TIME_TO_SEC(a)) (
+PARTITION p VALUES LESS THAN (64507), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (EXTRACT(DAY FROM a)) (
+PARTITION p VALUES LESS THAN (18), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+CREATE TABLE t1 (a TIMESTAMP NOT NULL, b TIMESTAMP NOT NULL, PRIMARY KEY(a,b))
+PARTITION BY RANGE (DATEDIFF(a, b)) (
+PARTITION p VALUES LESS THAN (18), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
+End of 5.1 tests

=== modified file 'mysql-test/t/partition_error.test'
--- a/mysql-test/t/partition_error.test	2009-02-18 20:29:30 +0000
+++ b/mysql-test/t/partition_error.test	2009-08-27 16:06:24 +0000
@@ -466,7 +466,7 @@ partitions 2
 #
 # Partition by range, constant partition function not allowed
 #
---error ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
 CREATE TABLE t1 (
 a int not null,
 b int not null,
@@ -681,7 +681,7 @@ partition by list (a);
 #
 # Partition by list, constant partition function not allowed
 #
---error ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
 CREATE TABLE t1 (
 a int not null,
 b int not null,
@@ -840,4 +840,148 @@ partition by range (a + (select count(*)
 create table t1 (a char(10))
 partition by hash (extractvalue(a,'a'));
 
+--echo #
+--echo # Bug #42849: innodb crash with varying time_zone on partitioned
+--echo #             timestamp primary key
+--echo #
+
+# Check that allowed arithmetic/math functions involving TIMESTAMP values result
+# in ER_PARTITION_FUNC_NOT_ALLOWED_ERROR when used as a partitioning function
+
+--error ER_PARTITION_FUNC_NOT_ALLOWED_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (a) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_PARTITION_FUNC_NOT_ALLOWED_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (a+0) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_PARTITION_FUNC_NOT_ALLOWED_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (a % 2) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_PARTITION_FUNC_NOT_ALLOWED_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (ABS(a)) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_PARTITION_FUNC_NOT_ALLOWED_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (CEILING(a)) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_PARTITION_FUNC_NOT_ALLOWED_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (FLOOR(a)) (
+PARTITION p VALUES LESS THAN (20080819), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+# Check that allowed date/time functions involving TIMESTAMP values result
+# in ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR when used as a partitioning function
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (TO_DAYS(a)) (
+PARTITION p VALUES LESS THAN (733638), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (DAYOFYEAR(a)) (
+PARTITION p VALUES LESS THAN (231), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (DAYOFMONTH(a)) (
+PARTITION p VALUES LESS THAN (19), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (DAYOFWEEK(a)) (
+PARTITION p VALUES LESS THAN (3), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (MONTH(a)) (
+PARTITION p VALUES LESS THAN (8), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (HOUR(a)) (
+PARTITION p VALUES LESS THAN (17), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (MINUTE(a)) (
+PARTITION p VALUES LESS THAN (55), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (QUARTER(a)) (
+PARTITION p VALUES LESS THAN (3), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (SECOND(a)) (
+PARTITION p VALUES LESS THAN (7), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (YEARWEEK(a)) (
+PARTITION p VALUES LESS THAN (200833), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (YEAR(a)) (
+PARTITION p VALUES LESS THAN (2008), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (WEEKDAY(a)) (
+PARTITION p VALUES LESS THAN (3), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (WEEKDAY(a)) (
+PARTITION p VALUES LESS THAN (3), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (TIME_TO_SEC(a)) (
+PARTITION p VALUES LESS THAN (64507), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY)
+PARTITION BY RANGE (EXTRACT(DAY FROM a)) (
+PARTITION p VALUES LESS THAN (18), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+CREATE TABLE t1 (a TIMESTAMP NOT NULL, b TIMESTAMP NOT NULL, PRIMARY KEY(a,b))
+PARTITION BY RANGE (DATEDIFF(a, b)) (
+PARTITION p VALUES LESS THAN (18), 
+PARTITION pmax VALUES LESS THAN MAXVALUE);
+
+--echo End of 5.1 tests
 

=== modified file 'sql/item.h'
--- a/sql/item.h	2009-05-25 08:00:40 +0000
+++ b/sql/item.h	2009-08-27 16:06:24 +0000
@@ -950,6 +950,15 @@ public:
   virtual Item *equal_fields_propagator(uchar * arg) { return this; }
   virtual bool set_no_const_sub(uchar *arg) { return FALSE; }
   virtual Item *replace_equal_field(uchar * arg) { return this; }
+  /*
+    Check if an expression value depends on the current timezone. Used by
+    partitioning code to reject timezone-dependent expressions in a
+    (sub)partitioning function.
+  */
+  virtual bool is_timezone_dependent_processor(uchar *bool_arg)
+  {
+    return FALSE;
+  }
 
   /*
     For SP local variable returns pointer to Item representing its

=== modified file 'sql/item_func.h'
--- a/sql/item_func.h	2009-05-21 20:22:46 +0000
+++ b/sql/item_func.h	2009-08-27 16:06:24 +0000
@@ -200,6 +200,21 @@ public:
     null_value=1;
     return 0.0;
   }
+  /*
+    Used by some Item_func_* subclasses to check whether the function argument
+    is a TIMESTAMP value and hence the function value is timezone-dependent.
+  */
+  bool has_timestamp_args()
+  {
+    DBUG_ASSERT(fixed == TRUE);
+    for (uint i= 0; i < arg_count; i++)
+    {
+      if (args[i]->type() == Item::FIELD_ITEM &&
+          args[i]->field_type() == MYSQL_TYPE_TIMESTAMP)
+        return true;
+    }
+    return FALSE;
+  }
 };
 
 

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2009-02-07 15:50:31 +0000
+++ b/sql/item_timefunc.h	2009-08-27 16:06:24 +0000
@@ -70,6 +70,10 @@ public:
   enum_monotonicity_info get_monotonicity_info() const;
   longlong val_int_endpoint(bool left_endp, bool *incl_endp);
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -86,6 +90,10 @@ public:
     maybe_null=1; 
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -111,6 +119,10 @@ public:
     maybe_null=1; 
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -140,6 +152,10 @@ public:
     maybe_null=1; 
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -156,6 +172,10 @@ public:
     maybe_null=1;
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 

 
@@ -172,6 +192,10 @@ public:
     maybe_null=1;
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -188,6 +212,10 @@ public:
      maybe_null=1;
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -204,6 +232,10 @@ public:
     maybe_null=1;
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -234,6 +266,10 @@ public:
     maybe_null=1;
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -252,6 +288,10 @@ public:
     maybe_null=1;
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -282,6 +322,10 @@ public:
     maybe_null=1;
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 class Item_func_dayname :public Item_func_weekday
@@ -294,6 +338,10 @@ class Item_func_dayname :public Item_fun
   enum Item_result result_type () const { return STRING_RESULT; }
   void fix_length_and_dec();
   bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -325,6 +373,10 @@ public:
     max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
   }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 
@@ -705,6 +757,10 @@ class Item_extract :public Item_int_func
   bool eq(const Item *item, bool binary_cmp) const;
   virtual void print(String *str, enum_query_type query_type);
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+  bool is_timezone_dependent_processor(uchar *int_arg)
+  {
+    return has_timestamp_args();
+  }
 };
 
 

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2009-05-27 15:19:44 +0000
+++ b/sql/share/errmsg.txt	2009-08-27 16:06:24 +0000
@@ -5696,8 +5696,8 @@ ER_PARTITION_WRONG_NO_SUBPART_ERROR
         eng "Wrong number of subpartitions defined, mismatch with previous setting"
         ger "Falsche Anzahl von Unterpartitionen definiert, stimmt nicht mit vorherigen Einstellungen �n"
         swe "Antal subpartitioner definierade och antal subpartitioner �inte lika"
-ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR
-        eng "Constant/Random expression in (sub)partitioning function is not allowed"
+ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+        eng "Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed"
         ger "Konstante oder Random-Ausdr�n (Unter-)Partitionsfunktionen sind nicht erlaubt"
         swe "Konstanta uttryck eller slumpm�iga uttryck �inte till�a (sub)partitioneringsfunktioner"
 ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2009-04-01 05:34:59 +0000
+++ b/sql/sql_partition.cc	2009-08-27 16:06:24 +0000
@@ -980,9 +980,11 @@ bool fix_fields_part_func(THD *thd, Item
     goto end;
   }
   thd->where= save_where;
-  if (unlikely(func_expr->const_item()))
+  if (unlikely(func_expr->const_item() ||
+               func_expr->walk(&Item::is_timezone_dependent_processor,
+                               0, NULL)))
   {
-    my_error(ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR, MYF(0));
+    my_error(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR, MYF(0));
     clear_field_flag(table);
     goto end;
   }

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2009-06-01 12:43:16 +0000
+++ b/sql/sql_yacc.yy	2009-08-27 16:06:24 +0000
@@ -3931,7 +3931,7 @@ part_func_expr:
             lex->safe_to_cache_query= 1;
             if (not_corr_func)
             {
-              my_parse_error(ER(ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR));
+              my_parse_error(ER(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR));
               MYSQL_YYABORT;
             }
             $$=$1;

Attachment: [text/bzr-bundle] bzr/alexey.kopytov@sun.com-20090827160624-qnfbinl1emz00pcc.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (Alexey.Kopytov:2920)Bug#42849Alexey Kopytov27 Aug
  • Re: bzr commit into mysql-5.1-bugteam branch (Alexey.Kopytov:2920)Bug#42849Mattias Jonsson3 Sep
  • Re: bzr commit into mysql-5.1-bugteam branch (Alexey.Kopytov:2920)Bug#42849Mattias Jonsson3 Sep