diff --git a/mysql-test/suite/tianmu/r/issue1173.result b/mysql-test/suite/tianmu/r/issue1173.result new file mode 100644 index 000000000..35e21e2f9 --- /dev/null +++ b/mysql-test/suite/tianmu/r/issue1173.result @@ -0,0 +1,50 @@ +DROP DATABASE IF EXISTS issue1173_test_db; +CREATE DATABASE issue1173_test_db; +USE issue1173_test_db; +CREATE TABLE t1 (a TIME(1) NOT NULL)engine=tianmu; +INSERT INTO t1 VALUES ('00:00:02.9'); +INSERT INTO t1 VALUES ('00:00:02'); +INSERT INTO t1 VALUES ('00:00:02.98'); +INSERT INTO t1 VALUES ('00:00:02.5'); +INSERT INTO t1 VALUES ('00:00:02.51'); +INSERT INTO t1 VALUES ('00:00:02.49'); +CREATE TABLE t1i (a TIME(1) NOT NULL)engine=innodb; +INSERT INTO t1i VALUES ('00:00:02.9'); +INSERT INTO t1i VALUES ('00:00:02'); +INSERT INTO t1i VALUES ('00:00:02.98'); +INSERT INTO t1i VALUES ('00:00:02.5'); +INSERT INTO t1i VALUES ('00:00:02.51'); +INSERT INTO t1i VALUES ('00:00:02.49'); +select * from t1; +a +00:00:02.9 +00:00:02.0 +00:00:03.0 +00:00:02.5 +00:00:02.5 +00:00:02.5 +select * from t1i; +00:00:02.9 +00:00:02.0 +00:00:03.0 +00:00:02.5 +00:00:02.5 +00:00:02.5 +SELECT a, a & a, a | a, a^0, a<<1, a<<0, a>>1, bit_count(a) FROM t1; +a a & a a | a a^0 a<<1 a<<0 a>>1 bit_count(a) +00:00:02.9 3 3 3 6 3 1 2 +00:00:02.0 2 2 2 4 2 1 1 +00:00:03.0 3 3 3 6 3 1 2 +00:00:02.5 3 3 3 6 3 1 2 +00:00:02.5 3 3 3 6 3 1 2 +00:00:02.5 3 3 3 6 3 1 2 +CREATE TABLE t2 (a DATETIME(1) NOT NULL); +INSERT INTO t2 VALUES ('2001-01-01 00:00:02.9'); +INSERT INTO t2 VALUES ('2001-01-01 23:59:59.9'); +INSERT INTO t2 VALUES ('9999-12-31 23:59:59.9'); +SELECT a, a & a, a | a, a^0, a<<1, a<<0, a>>1, bit_count(a) FROM t2; +a a & a a | a a^0 a<<1 a<<0 a>>1 bit_count(a) +2001-01-01 00:00:02.9 20010101000003 20010101000003 20010101000003 40020202000006 20010101000003 10005050500001 24 +2001-01-01 23:59:59.9 20010102000000 20010102000000 20010102000000 40020204000000 20010102000000 10005051000000 18 +9999-12-31 23:59:59.9 99991231000000 99991231000000 99991231000000 199982462000000 99991231000000 49995615500000 24 +DROP DATABASE issue1173_test_db; diff --git a/mysql-test/suite/tianmu/t/issue1173.test b/mysql-test/suite/tianmu/t/issue1173.test new file mode 100644 index 000000000..b84532a5e --- /dev/null +++ b/mysql-test/suite/tianmu/t/issue1173.test @@ -0,0 +1,38 @@ +--source include/have_tianmu.inc + +--disable_warnings +DROP DATABASE IF EXISTS issue1173_test_db; +--enable_warnings +CREATE DATABASE issue1173_test_db; +USE issue1173_test_db; + +CREATE TABLE t1 (a TIME(1) NOT NULL)engine=tianmu; +INSERT INTO t1 VALUES ('00:00:02.9'); +INSERT INTO t1 VALUES ('00:00:02'); +INSERT INTO t1 VALUES ('00:00:02.98'); +INSERT INTO t1 VALUES ('00:00:02.5'); +INSERT INTO t1 VALUES ('00:00:02.51'); +INSERT INTO t1 VALUES ('00:00:02.49'); + +CREATE TABLE t1i (a TIME(1) NOT NULL)engine=innodb; +INSERT INTO t1i VALUES ('00:00:02.9'); +INSERT INTO t1i VALUES ('00:00:02'); +INSERT INTO t1i VALUES ('00:00:02.98'); +INSERT INTO t1i VALUES ('00:00:02.5'); +INSERT INTO t1i VALUES ('00:00:02.51'); +INSERT INTO t1i VALUES ('00:00:02.49'); + +select * from t1; + +select * from t1i; + +SELECT a, a & a, a | a, a^0, a<<1, a<<0, a>>1, bit_count(a) FROM t1; + +CREATE TABLE t2 (a DATETIME(1) NOT NULL); +INSERT INTO t2 VALUES ('2001-01-01 00:00:02.9'); +INSERT INTO t2 VALUES ('2001-01-01 23:59:59.9'); +INSERT INTO t2 VALUES ('9999-12-31 23:59:59.9'); + +SELECT a, a & a, a | a, a^0, a<<1, a<<0, a>>1, bit_count(a) FROM t2; + +DROP DATABASE issue1173_test_db; diff --git a/storage/tianmu/core/item_tianmu_field.cpp b/storage/tianmu/core/item_tianmu_field.cpp index 90a88537a..11d92b3b0 100644 --- a/storage/tianmu/core/item_tianmu_field.cpp +++ b/storage/tianmu/core/item_tianmu_field.cpp @@ -21,6 +21,7 @@ #include "core/quick_math.h" #include "core/transaction.h" #include "optimizer/compile/compilation_tools.h" +#include "util/log_ctl.h" namespace Tianmu { namespace core { @@ -266,8 +267,9 @@ bool Item_tianmudatetime_base::get_time(MYSQL_TIME *ltime) { } longlong Item_tianmudatetime::val_int() { - return dt.year * 10000000000LL + dt.month * 100000000 + dt.day * 1000000 + dt.hour * 10000 + dt.minute * 100 + - dt.second; + MYSQL_TIME my_time; + dt.Store(&my_time, MYSQL_TIMESTAMP_DATETIME); + return (longlong)TIME_to_ulonglong_datetime_round(&my_time); } String *Item_tianmudatetime::val_str(String *s) { @@ -317,7 +319,19 @@ bool Item_tianmudate::get_time(MYSQL_TIME *ltime) { return false; } -longlong Item_tianmutime::val_int() { return dt.hour * 10000 + dt.minute * 100 + dt.second; } +longlong Item_tianmutime::val_int() { + /* fix for issue#1173 + * This logic is consistent with innodb. + * Reffer to the function Field_timef::val_int() in field.cc + */ + MYSQL_TIME my_time; + dt.Store(&my_time, MYSQL_TIMESTAMP_TIME); + TIANMU_LOG(LogCtl_Level::INFO, "convert time: %d:%d:%d.%d", dt.hour, dt.minute, dt.second, dt.microsecond); + longlong tmp = (longlong)TIME_to_ulonglong_time_round(&my_time); + TIANMU_LOG(LogCtl_Level::INFO, "convert result: %lld", tmp); + return dt.Neg() ? -tmp : tmp; +} + String *Item_tianmutime::val_str(String *s) { MYSQL_TIME ltime; get_time(<ime);