Skip to content

Commit 0385d95

Browse files
committed
Bug#35323398: Assertion 'scale >= 0 && precision > 0 and
scale <= precision' failed The problem is with the resolve_type_inner() function for class Item_func_nullif. If the original data type is a temporal type, the type is adjusted to a string type. However, the result type is not adjusted accordingly, which may cause later inconsistencies. Fixed by setting result type to STRING_RESULT. Change-Id: I91b43741ced9c0253b9e337e7170d8c93ac9c8f4
1 parent 4185c0d commit 0385d95

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

mysql-test/r/func_if.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,14 @@ Warning 1292 Incorrect datetime value: '13339'
343343
DO CAST(UNIX_TIMESTAMP(CASE 1 WHEN 1 THEN 42 ELSE 42 END) AS UNSIGNED);
344344
Warnings:
345345
Warning 1292 Incorrect datetime value: '42'
346+
# Bug#35323398: Assertion 'scale >= 0 && precision > 0 and
347+
# scale <= precision' failed
348+
SELECT AVG(NULLIF(YEAR('2001-01-01'),10));
349+
AVG(NULLIF(YEAR('2001-01-01'),10))
350+
2001
351+
CREATE TABLE t1(y YEAR);
352+
INSERT INTO t1 VALUES(2001);
353+
SELECT AVG(NULLIF(y, 10)) FROM t1;
354+
AVG(NULLIF(y, 10))
355+
2001
356+
DROP TABLE t1;

mysql-test/t/func_if.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,15 @@ DROP TABLE t;
299299

300300
DO CAST(UNIX_TIMESTAMP(IF('',3,13339)) AS UNSIGNED);
301301
DO CAST(UNIX_TIMESTAMP(CASE 1 WHEN 1 THEN 42 ELSE 42 END) AS UNSIGNED);
302+
303+
--echo # Bug#35323398: Assertion 'scale >= 0 && precision > 0 and
304+
--echo # scale <= precision' failed
305+
306+
SELECT AVG(NULLIF(YEAR('2001-01-01'),10));
307+
308+
CREATE TABLE t1(y YEAR);
309+
INSERT INTO t1 VALUES(2001);
310+
311+
SELECT AVG(NULLIF(y, 10)) FROM t1;
312+
313+
DROP TABLE t1;

sql/item_cmpfunc.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,6 +3534,7 @@ bool Item_func_nullif::resolve_type_inner(THD *thd) {
35343534
set_data_type_string(args[0]->max_length);
35353535
if (agg_arg_charsets_for_comparison(cmp.cmp_collation, args, arg_count))
35363536
return true;
3537+
cached_result_type = STRING_RESULT;
35373538
}
35383539
return false;
35393540
}

0 commit comments

Comments
 (0)