#At file:///Users/mattiasj/mysql-bzr/b28928-51/ based on revid:dmitry.shulga@stripped
3576 Mattias Jonsson 2011-02-04
Bug#28928: UNIX_TIMESTAMP() should be considered unary monotonic by partition pruning
Preliminary patch to support range pruning for UNIX_TIMESTAMP.
TODO: Fix the tests, add better tests.
modified:
mysql-test/r/partition.result
mysql-test/t/partition.test
sql/item_timefunc.cc
sql/item_timefunc.h
=== modified file 'mysql-test/r/partition.result'
--- a/mysql-test/r/partition.result 2010-12-22 09:50:36 +0000
+++ b/mysql-test/r/partition.result 2011-02-04 14:08:34 +0000
@@ -76,6 +76,15 @@ a b
2007-07-30 17:35:48 p1
2009-07-14 17:35:55 pmax
2009-09-21 17:31:42 pmax
+SELECT * FROM t1 where a between '2007-01-01' and '2007-08-01';
+a b
+2007-07-30 17:35:48 p1
+EXPLAIN PARTITIONS SELECT * FROM t1 where a between '2007-01-01' and '2007-08-01';
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p1 system PRIMARY NULL NULL NULL 1
+EXPLAIN PARTITIONS SELECT * FROM t1 where a = '2007-07-30 17:35:48';
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p1 system PRIMARY NULL NULL NULL 1
ALTER TABLE t1 REORGANIZE PARTITION pmax INTO (
PARTITION p3 VALUES LESS THAN (1247688000),
PARTITION pmax VALUES LESS THAN MAXVALUE);
@@ -84,6 +93,15 @@ a b
2007-07-30 17:35:48 p1
2009-07-14 17:35:55 pmax
2009-09-21 17:31:42 pmax
+SELECT * FROM t1 where a between '2007-01-01' and '2007-08-01';
+a b
+2007-07-30 17:35:48 p1
+EXPLAIN PARTITIONS SELECT * FROM t1 where a between '2007-01-01' and '2007-08-01';
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p1 system PRIMARY NULL NULL NULL 1
+EXPLAIN PARTITIONS SELECT * FROM t1 where a = '2007-07-30 17:35:48';
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p1 system PRIMARY NULL NULL NULL 1
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
=== modified file 'mysql-test/t/partition.test'
--- a/mysql-test/t/partition.test 2010-12-22 09:50:36 +0000
+++ b/mysql-test/t/partition.test 2011-02-04 14:08:34 +0000
@@ -112,10 +112,16 @@ INSERT INTO t1 VALUES ('2009-07-14 17:35
INSERT INTO t1 VALUES ('2009-09-21 17:31:42', 'pmax');
SELECT * FROM t1;
+SELECT * FROM t1 where a between '2007-01-01' and '2007-08-01';
+EXPLAIN PARTITIONS SELECT * FROM t1 where a between '2007-01-01' and '2007-08-01';
+EXPLAIN PARTITIONS SELECT * FROM t1 where a = '2007-07-30 17:35:48';
ALTER TABLE t1 REORGANIZE PARTITION pmax INTO (
PARTITION p3 VALUES LESS THAN (1247688000),
PARTITION pmax VALUES LESS THAN MAXVALUE);
SELECT * FROM t1;
+SELECT * FROM t1 where a between '2007-01-01' and '2007-08-01';
+EXPLAIN PARTITIONS SELECT * FROM t1 where a between '2007-01-01' and '2007-08-01';
+EXPLAIN PARTITIONS SELECT * FROM t1 where a = '2007-07-30 17:35:48';
SHOW CREATE TABLE t1;
DROP TABLE t1;
=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc 2010-11-12 10:12:15 +0000
+++ b/sql/item_timefunc.cc 2011-02-04 14:08:34 +0000
@@ -1316,6 +1316,26 @@ longlong Item_func_unix_timestamp::val_i
return (longlong) TIME_to_timestamp(current_thd, <ime, ¬_used);
}
+enum_monotonicity_info Item_func_unix_timestamp::get_monotonicity_info() const
+{
+ if (args[0]->type() == Item::FIELD_ITEM &&
+ (args[0]->field_type() == MYSQL_TYPE_TIMESTAMP))
+ return MONOTONIC_INCREASING;
+ return NON_MONOTONIC;
+}
+
+
+longlong Item_func_unix_timestamp::val_int_endpoint(bool left_endp, bool *incl_endp)
+{
+ DBUG_ASSERT(fixed == 1);
+ DBUG_ASSERT(arg_count == 1 &&
+ args[0]->type() == Item::FIELD_ITEM &&
+ args[0]->field_type() == MYSQL_TYPE_TIMESTAMP);
+ Field *field=((Item_field*) args[0])->field;
+ /* Leave the incl_endp intact */
+ return ((Field_timestamp*) field)->get_timestamp(&null_value);
+}
+
longlong Item_func_time_to_sec::val_int()
{
=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h 2011-01-28 12:37:39 +0000
+++ b/sql/item_timefunc.h 2011-02-04 14:08:34 +0000
@@ -349,6 +349,8 @@ public:
Item_func_unix_timestamp(Item *a) :Item_int_func(a) {}
longlong val_int();
const char *func_name() const { return "unix_timestamp"; }
+ 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;}
/*
UNIX_TIMESTAMP() depends on the current timezone
Attachment: [text/bzr-bundle] bzr/mattias.jonsson@oracle.com-20110204140834-4gubgd4j28g595bi.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1 branch (mattias.jonsson:3576) Bug#28928 | Mattias Jonsson | 4 Feb |