Commit 3ad035f6 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-8658 DATE(zerofill_column) and DATE(COALESCE(zerofill_column)) return different results

MDEV-8660 TIME(int_zerofill_column) returns a wrong result
parent b9da3ba4
......@@ -172,8 +172,8 @@ INTERVAL( 9, 1, DATE_ADD( pk, INTERVAL pk MINUTE_SECOND ), 9, 8, 3, 5, 2, 1 )
8
8
Warnings:
Warning 1292 Incorrect datetime value: '10'
Warning 1292 Incorrect datetime value: '11'
Warning 1292 Incorrect datetime value: '10' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '11' for column 'pk' at row 2
DROP TABLE t1;
#
# End of 5.3 tests
......@@ -233,8 +233,8 @@ INTERVAL( 9, 1, DATE_ADD( pk, INTERVAL pk MINUTE_SECOND ), 9, 8, 3, 5, 2, 1 )
8
8
Warnings:
Warning 1292 Incorrect datetime value: '10'
Warning 1292 Incorrect datetime value: '11'
Warning 1292 Incorrect datetime value: '10' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '11' for column 'pk' at row 2
DROP TABLE t1;
#
# End of 5.3 tests
......
......@@ -1834,25 +1834,14 @@ select last_day(f2) from t1;
last_day(f2)
NULL
NULL
Warnings:
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
select last_day(f2) from t1 where last_day(f2) is null;
last_day(f2)
NULL
NULL
Warnings:
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
select * from t1 order by last_day (f2);
f2
0
0
Warnings:
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
drop table t1;
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
select convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow');
......@@ -1908,8 +1897,6 @@ insert ignore t1 values ('04:38:11','0000-00-00 00:00:00',0,'0000-00-00 00:00:00
select least(greatest(f3, f2, f4), f5) from t1;
least(greatest(f3, f2, f4), f5)
0000-00-00 00:00:00
Warnings:
Warning 1292 Incorrect datetime value: '0'
drop table t1;
select day(coalesce(null));
day(coalesce(null))
......
......@@ -296,8 +296,6 @@ INSERT INTO t1 VALUES ('2011-05-13', 0);
SELECT * FROM t1 WHERE b < (SELECT CAST(a as date) FROM t1 GROUP BY a);
a b
2011-05-13 0
Warnings:
Warning 1292 Incorrect datetime value: '0'
DROP TABLE t1;
#
# Bug #11766300 59387: FAILING ASSERTION: CURSOR->POS_STATE == 1997660512 (BTR_PCUR_IS_POSITIONE
......
......@@ -759,5 +759,48 @@ Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (coalesce(`test`.`t1`.`a`) = DATE'2001-01-01')
DROP TABLE t1;
#
# MDEV-8658 DATE(zerofill_column) and DATE(COALESCE(zerofill_column)) return different results
#
CREATE TABLE t1 (a INT(6) ZEROFILL, b DECIMAL(6) ZEROFILL, c DOUBLE(6,0) ZEROFILL);
INSERT INTO t1 VALUES (1,1,1);
INSERT INTO t1 VALUES (10101,10101,10101);
SELECT DATE(a), DATE(b), DATE(c) FROM t1;
DATE(a) DATE(b) DATE(c)
NULL NULL NULL
2001-01-01 2001-01-01 2001-01-01
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'a' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'b' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'c' at row 1
SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1;
DATE(COALESCE(a)) DATE(COALESCE(b)) DATE(COALESCE(c))
NULL NULL NULL
2001-01-01 2001-01-01 2001-01-01
Warnings:
Warning 1292 Incorrect datetime value: '1'
Warning 1292 Incorrect datetime value: '1'
Warning 1292 Incorrect datetime value: '1'
DROP TABLE t1;
CREATE TABLE t1 (a INT(6), b DECIMAL(6), c DOUBLE(6,0));
INSERT INTO t1 VALUES (1,1,1);
INSERT INTO t1 VALUES (10101,10101,10101);
SELECT DATE(a), DATE(b), DATE(c) FROM t1;
DATE(a) DATE(b) DATE(c)
NULL NULL NULL
2001-01-01 2001-01-01 2001-01-01
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'a' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'b' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'c' at row 1
SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1;
DATE(COALESCE(a)) DATE(COALESCE(b)) DATE(COALESCE(c))
NULL NULL NULL
2001-01-01 2001-01-01 2001-01-01
Warnings:
Warning 1292 Incorrect datetime value: '1'
Warning 1292 Incorrect datetime value: '1'
Warning 1292 Incorrect datetime value: '1'
DROP TABLE t1;
#
# End of 10.1 tests
#
......@@ -2042,33 +2042,19 @@ SELECT t1.* FROM t1 JOIN t2 USING(a);
a
10:20:30.000000
10:20:30.000000
Warnings:
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000010'
SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
a
10:20:30.000000
10:20:30.000000
Warnings:
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000010'
ALTER TABLE t2 ADD PRIMARY KEY(a);
SELECT t1.* FROM t1 JOIN t2 USING(a);
a
10:20:30.000000
10:20:30.000000
Warnings:
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000010'
SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
a
10:20:30.000000
10:20:30.000000
Warnings:
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000010'
# t2 should NOT be eliminated
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
id select_type table type possible_keys key key_len ref rows Extra
......
......@@ -1153,5 +1153,58 @@ SELECT * FROM t1 WHERE a>TIME('00:00:00');
a
DROP TABLE t1;
#
# MDEV-8660 TIME(int_zerofill_column) returns a wrong result
#
CREATE TABLE t1 (a BIGINT(15), b BIGINT(15) ZEROFILL);
INSERT INTO t1 VALUES (9,9);
SELECT TIME(a),TIME(b) FROM t1;
TIME(a) TIME(b)
00:00:09 00:00:09
DROP TABLE t1;
CREATE TABLE t1 (a BIGINT);
INSERT INTO t1 VALUES (-9223372036854775808);
SELECT CAST(a AS TIME), CAST(-9223372036854775808 AS TIME) FROM t1;
CAST(a AS TIME) CAST(-9223372036854775808 AS TIME)
-838:59:59 -838:59:59
Warnings:
Warning 1292 Incorrect time value: '-9223372036854775808' for column 'a' at row 1
Warning 1292 Truncated incorrect time value: '-9223372036854775808'
DROP TABLE t1;
CREATE TABLE t1 (a INT, b DECIMAL, c DOUBLE);
INSERT INTO t1 VALUES (-9000000,-9000000,-9000000);
INSERT INTO t1 VALUES (-1,-1,-1);
INSERT INTO t1 VALUES (0,0,0),(1,1,1),(9,9,9);
INSERT INTO t1 VALUES (9000000,9000000,9000000);
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
a TIME(a) TIME(b) TIME(c)
-9000000 -838:59:59 -838:59:59 -838:59:59.999999
-1 -00:00:01 -00:00:01 -00:00:01.000000
0 00:00:00 00:00:00 00:00:00.000000
1 00:00:01 00:00:01 00:00:01.000000
9 00:00:09 00:00:09 00:00:09.000000
9000000 838:59:59 838:59:59 838:59:59.999999
Warnings:
Warning 1292 Incorrect time value: '-9000000' for column 'a' at row 1
Warning 1292 Incorrect time value: '-9000000' for column 'b' at row 1
Warning 1292 Incorrect time value: '-9000000' for column 'c' at row 1
Warning 1292 Incorrect time value: '9000000' for column 'a' at row 6
Warning 1292 Incorrect time value: '9000000' for column 'b' at row 6
Warning 1292 Incorrect time value: '9000000' for column 'c' at row 6
DROP TABLE t1;
CREATE TABLE t1 (a INT, b DECIMAL, c DOUBLE);
INSERT INTO t1 VALUES (0,0,0),(1,1,1),(9,9,9);
INSERT INTO t1 VALUES (9000000,9000000,9000000);
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
a TIME(a) TIME(b) TIME(c)
0 00:00:00 00:00:00 00:00:00.000000
1 00:00:01 00:00:01 00:00:01.000000
9 00:00:09 00:00:09 00:00:09.000000
9000000 838:59:59 838:59:59 838:59:59.999999
Warnings:
Warning 1292 Incorrect time value: '9000000' for column 'a' at row 4
Warning 1292 Incorrect time value: '9000000' for column 'b' at row 4
Warning 1292 Incorrect time value: '9000000' for column 'c' at row 4
DROP TABLE t1;
#
# End of 10.1 tests
#
......@@ -539,6 +539,22 @@ INSERT INTO t1 VALUES ('2001-01-01'),('2001-01-02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COALESCE(a)=DATE'2001-01-01' AND COALESCE(a)>=DATE'2001-01-01';
DROP TABLE t1;
--echo #
--echo # MDEV-8658 DATE(zerofill_column) and DATE(COALESCE(zerofill_column)) return different results
--echo #
CREATE TABLE t1 (a INT(6) ZEROFILL, b DECIMAL(6) ZEROFILL, c DOUBLE(6,0) ZEROFILL);
INSERT INTO t1 VALUES (1,1,1);
INSERT INTO t1 VALUES (10101,10101,10101);
SELECT DATE(a), DATE(b), DATE(c) FROM t1;
SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT(6), b DECIMAL(6), c DOUBLE(6,0));
INSERT INTO t1 VALUES (1,1,1);
INSERT INTO t1 VALUES (10101,10101,10101);
SELECT DATE(a), DATE(b), DATE(c) FROM t1;
SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1;
DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
......
......@@ -688,6 +688,33 @@ SELECT * FROM t1 WHERE a>TIME'00:00:00';
SELECT * FROM t1 WHERE a>TIME('00:00:00');
DROP TABLE t1;
--echo #
--echo # MDEV-8660 TIME(int_zerofill_column) returns a wrong result
--echo #
CREATE TABLE t1 (a BIGINT(15), b BIGINT(15) ZEROFILL);
INSERT INTO t1 VALUES (9,9);
SELECT TIME(a),TIME(b) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a BIGINT);
INSERT INTO t1 VALUES (-9223372036854775808);
SELECT CAST(a AS TIME), CAST(-9223372036854775808 AS TIME) FROM t1;
DROP TABLE t1;
# Make sure all numeric types produce the same TIME value
CREATE TABLE t1 (a INT, b DECIMAL, c DOUBLE);
INSERT INTO t1 VALUES (-9000000,-9000000,-9000000);
INSERT INTO t1 VALUES (-1,-1,-1);
INSERT INTO t1 VALUES (0,0,0),(1,1,1),(9,9,9);
INSERT INTO t1 VALUES (9000000,9000000,9000000);
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b DECIMAL, c DOUBLE);
INSERT INTO t1 VALUES (0,0,0),(1,1,1),(9,9,9);
INSERT INTO t1 VALUES (9000000,9000000,9000000);
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
--echo #
......@@ -1992,6 +1992,16 @@ my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
}
bool Field_num::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate)
{
ASSERT_COLUMN_MARKED_FOR_READ;
longlong nr= val_int();
bool neg= !(flags & UNSIGNED_FLAG) && nr < 0;
return int_to_datetime_with_warn(neg, neg ? -nr : nr, ltime, fuzzydate,
field_name);
}
Field_str::Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const char *field_name_arg, CHARSET_INFO *charset_arg)
......@@ -3217,6 +3227,14 @@ String *Field_new_decimal::val_str(String *val_buffer,
}
bool Field_new_decimal::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
my_decimal value;
return decimal_to_datetime_with_warn(val_decimal(&value),
ltime, fuzzydate, field_name);
}
int Field_new_decimal::cmp(const uchar *a,const uchar*b)
{
return memcmp(a, b, bin_size);
......
......@@ -1487,6 +1487,7 @@ public:
{
return pos_in_interval_val_real(min, max);
}
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
};
......@@ -1665,6 +1666,7 @@ public:
longlong val_int(void);
my_decimal *val_decimal(my_decimal *);
String *val_str(String*, String *);
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
int cmp(const uchar *, const uchar *);
void sort_string(uchar *buff, uint length);
bool zero_pack() const { return 0; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment