diff options
author | Sergei Golubchik <sergii@pisem.net> | 2013-03-17 07:41:22 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-03-17 07:41:22 +0100 |
commit | 019f7425b70bb992bf6446a3c9a1dda041a4440d (patch) | |
tree | 16373a6476dcbace09c29dcf2155092dd37a781c | |
parent | 926b0f54c9b0f261460e886969dde9bbf1916852 (diff) | |
download | mariadb-git-019f7425b70bb992bf6446a3c9a1dda041a4440d.tar.gz |
MDEV-4281 Assertion `maybe_null && item->null_value' fails in make_sortkey on CASE with different return types, GROUP_CONCAT, GROUP BY
Fix Item::get_date() to mark the item NULL when returning an error.
-rw-r--r-- | mysql-test/r/cast.result | 20 | ||||
-rw-r--r-- | mysql-test/r/date_formats.result | 2 | ||||
-rw-r--r-- | mysql-test/r/func_sapdb.result | 4 | ||||
-rw-r--r-- | mysql-test/r/func_time.result | 7 | ||||
-rw-r--r-- | mysql-test/r/partition_pruning.result | 3 | ||||
-rw-r--r-- | mysql-test/r/type_date.result | 2 | ||||
-rw-r--r-- | mysql-test/r/type_datetime.result | 17 | ||||
-rw-r--r-- | mysql-test/t/type_datetime.test | 11 | ||||
-rw-r--r-- | sql/filesort.cc | 5 | ||||
-rw-r--r-- | sql/item.cc | 8 |
10 files changed, 56 insertions, 23 deletions
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index 37550ce77f2..72e6dca8890 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -268,37 +268,37 @@ cast(010203101112.121314 as datetime) 0001-02-03 10:11:12 select cast(120010203101112.121314 as datetime); cast(120010203101112.121314 as datetime) -NULL +0000-00-00 00:00:00 Warnings: Warning 1292 Incorrect datetime value: '120010203101112.121314' select cast(cast(1.1 as decimal) as datetime); cast(cast(1.1 as decimal) as datetime) -NULL +0000-00-00 00:00:00 Warnings: Warning 1292 Incorrect datetime value: '1' select cast(cast(-1.1 as decimal) as datetime); cast(cast(-1.1 as decimal) as datetime) -NULL +0000-00-00 00:00:00 Warnings: Warning 1292 Incorrect datetime value: '-1' select cast('0' as date); cast('0' as date) -NULL +0000-00-00 Warnings: Warning 1292 Incorrect datetime value: '0' select cast('' as date); cast('' as date) -NULL +0000-00-00 Warnings: Warning 1292 Incorrect datetime value: '' select cast('0' as datetime); cast('0' as datetime) -NULL +0000-00-00 00:00:00 Warnings: Warning 1292 Incorrect datetime value: '0' select cast('' as datetime); cast('' as datetime) -NULL +0000-00-00 00:00:00 Warnings: Warning 1292 Incorrect datetime value: '' select cast('0' as time); @@ -306,7 +306,7 @@ cast('0' as time) 00:00:00 select cast('' as time); cast('' as time) -NULL +00:00:00 Warnings: Warning 1292 Truncated incorrect time value: '' select cast(NULL as DATE); @@ -323,13 +323,13 @@ cast(NULL as BINARY) NULL select cast(cast(120010203101112.121314 as double) as datetime); cast(cast(120010203101112.121314 as double) as datetime) -NULL +0000-00-00 00:00:00 select cast(cast(1.1 as double) as datetime); cast(cast(1.1 as double) as datetime) 0000-00-00 00:00:01 select cast(cast(-1.1 as double) as datetime); cast(cast(-1.1 as double) as datetime) -NULL +0000-00-00 00:00:00 explain extended select cast(10 as double(5,2)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index dd346cb94dc..044338e98b8 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -586,7 +586,7 @@ TIME_FORMAT("25:00:00", '%l %p') 1 AM SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896); DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896) -NULL +1151414896 Warnings: Warning 1292 Incorrect datetime value: '%Y-%m-%d %H:%i:%s' select str_to_date('04 /30/2004', '%m /%d/%Y'); diff --git a/mysql-test/r/func_sapdb.result b/mysql-test/r/func_sapdb.result index f0c1abd84fe..5bd3b3f8fda 100644 --- a/mysql-test/r/func_sapdb.result +++ b/mysql-test/r/func_sapdb.result @@ -168,7 +168,7 @@ date("1997-12-31 23:59:59.000001") 1997-12-31 select date("1997-13-31 23:59:59.000001"); date("1997-13-31 23:59:59.000001") -NULL +0000-00-00 Warnings: Warning 1292 Incorrect datetime value: '1997-13-31 23:59:59.000001' select time("1997-12-31 23:59:59.000001"); @@ -176,7 +176,7 @@ time("1997-12-31 23:59:59.000001") 23:59:59.000001 select time("1997-12-31 25:59:59.000001"); time("1997-12-31 25:59:59.000001") -NULL +00:00:00 Warnings: Warning 1292 Truncated incorrect time value: '1997-12-31 25:59:59.000001' select microsecond("1997-12-31 23:59:59.000001"); diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 14d2729e952..c2e287be046 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -946,7 +946,6 @@ select f1 from t1 where cast("2006-1-1" as date) between f1 and cast('zzz' as da f1 Warnings: Warning 1292 Incorrect datetime value: 'zzz' -Warning 1292 Incorrect datetime value: 'zzz' select f1 from t1 where makedate(2006,1) between date(f1) and date(f3); f1 2006-01-01 @@ -1756,7 +1755,7 @@ Warnings: Warning 1441 Datetime function: time field overflow select cast('131415.123e0' as time); cast('131415.123e0' as time) -NULL +00:00:00 Warnings: Warning 1292 Truncated incorrect time value: '131415.123e0' select cast('2010-01-02 03:04:05' as datetime) between null and '2010-01-02 03:04:04'; @@ -1776,12 +1775,12 @@ unix_timestamp(null) NULL select truncate(date('2010-40-10'), 6); truncate(date('2010-40-10'), 6) -NULL +0.000000 Warnings: Warning 1292 Incorrect datetime value: '2010-40-10' select extract(month from '2010-40-50'); extract(month from '2010-40-50') -NULL +0 Warnings: Warning 1292 Incorrect datetime value: '2010-40-50' select subtime('0000-00-10 10:10:10', '30 10:00:00'); diff --git a/mysql-test/r/partition_pruning.result b/mysql-test/r/partition_pruning.result index d5594c7453e..f60c87aa351 100644 --- a/mysql-test/r/partition_pruning.result +++ b/mysql-test/r/partition_pruning.result @@ -1906,9 +1906,10 @@ INSERT INTO t1 VALUES (1, '2009-01-01'), (2, NULL); # test with an invalid date, which lead to item->null_value is set. EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-99' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 SIMPLE t1 p20090401 ALL NULL NULL NULL NULL 2 Using where Warnings: Warning 1292 Incorrect datetime value: '2009-04-99' +Warning 1292 Incorrect datetime value: '2009-04-99' DROP TABLE t1; CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, diff --git a/mysql-test/r/type_date.result b/mysql-test/r/type_date.result index 23de0607838..8f9e692d3e0 100644 --- a/mysql-test/r/type_date.result +++ b/mysql-test/r/type_date.result @@ -136,7 +136,7 @@ select @d:=1311; 1311 select year(@d), month(@d), day(@d), cast(@d as date); year(@d) month(@d) day(@d) cast(@d as date) -NULL NULL NULL NULL +0 0 0 0000-00-00 Warnings: Warning 1292 Incorrect datetime value: '1311' Warning 1292 Incorrect datetime value: '1311' diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 1a111fe591a..1019462cdb5 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -573,7 +573,7 @@ CAST('NULL' AS DATE) < CAST('2008-01-01' AS DATE) n7, CAST('2008-01-01' AS DATE) < CAST('NULL' AS DATE) n8, CAST('NULL' AS DATE) < CAST('NULL' AS DATE) n9; n1 n2 n3 n4 n5 n6 n7 n8 n9 -0 0 1 NULL NULL NULL NULL NULL NULL +0 0 1 1 1 0 1 0 0 Warnings: Warning 1292 Incorrect datetime value: 'NULL' Warning 1292 Incorrect datetime value: 'NULL' @@ -585,6 +585,8 @@ Warning 1292 Incorrect datetime value: 'NULL' Warning 1292 Incorrect datetime value: 'NULL' Warning 1292 Incorrect datetime value: 'NULL' Warning 1292 Incorrect datetime value: 'NULL' +Warning 1292 Incorrect datetime value: 'NULL' +Warning 1292 Incorrect datetime value: 'NULL' End of 5.0 tests set @org_mode=@@sql_mode; create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03'); @@ -651,3 +653,16 @@ SELECT * FROM t1; dt1 DROP TABLE t1; End of 5.1 tests +create table t1 (d date, t time) engine=myisam; +insert into t1 values ('2000-12-03','22:55:23'),('2008-05-03','10:19:31'); +select case when d = '2012-12-12' then d else t end as cond, group_concat( d ) from t1 group by cond; +cond group_concat( d ) +0000-00-00 00:00:00 2000-12-03 +0000-00-00 00:00:00 2008-05-03 +Warnings: +Warning 1292 Incorrect datetime value: '22:55:23' +Warning 1292 Incorrect datetime value: '10:19:31' +Warning 1292 Incorrect datetime value: '22:55:23' +Warning 1292 Incorrect datetime value: '10:19:31' +drop table t1; +End of 5.3 tests diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index f9ee8dfd5d3..eeba0ca69e3 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -462,3 +462,14 @@ SELECT * FROM t1; DROP TABLE t1; --echo End of 5.1 tests + +# +# MDEV-4281 Assertion `maybe_null && item->null_value' fails in make_sortkey on CASE with different return types, GROUP_CONCAT, GROUP BY +# +create table t1 (d date, t time) engine=myisam; +insert into t1 values ('2000-12-03','22:55:23'),('2008-05-03','10:19:31'); +select case when d = '2012-12-12' then d else t end as cond, group_concat( d ) from t1 group by cond; +drop table t1; + +--echo End of 5.3 tests + diff --git a/sql/filesort.cc b/sql/filesort.cc index 703264b7ef5..6619989c1ea 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -869,7 +869,10 @@ static void make_sortkey(register SORTPARAM *param, { MYSQL_TIME buf; if (item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES)) - DBUG_ASSERT(maybe_null && item->null_value); + { + DBUG_ASSERT(maybe_null); + DBUG_ASSERT(item->null_value); + } else value= pack_time(&buf); } diff --git a/sql/item.cc b/sql/item.cc index 2e023168f34..cb60d6fb812 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1197,11 +1197,15 @@ bool Item::get_date(MYSQL_TIME *ltime,uint fuzzydate) DBUG_ASSERT(0); } - return 0; + return null_value= 0; err: + /* + if the item was not null and convertion failed, we return a zero date + if allowed, otherwise - null. + */ bzero((char*) ltime,sizeof(*ltime)); - return 1; + return null_value|= (fuzzydate & (TIME_NO_ZERO_DATE|TIME_NO_ZERO_IN_DATE)); } bool Item::get_seconds(ulonglong *sec, ulong *sec_part) |