MDEV-16958 Assertion `field_length < 5' failed in Field_year::val_str or data corruption upon SELECT with UNION and aggregate functions

This commit is contained in:
Alexander Barkov 2019-03-15 11:36:41 +04:00
parent 3d2d060b62
commit 78c2499282
3 changed files with 24 additions and 1 deletions

View File

@ -444,5 +444,14 @@ Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
DROP TABLE t1;
#
# MDEV-16958 Assertion `field_length < 5' failed in Field_year::val_str or data corruption upon SELECT with UNION and aggregate functions
#
CREATE TABLE t1 (f YEAR);
INSERT IGNORE INTO t1 VALUES (1971),(1972);
SELECT MAX( NULLIF( f, '1900' ) ) AS f FROM t1 UNION SELECT MAX( NULLIF( f, '1900' ) ) AS f FROM t1;
f
1972
DROP TABLE t1;
#
# End of 10.1 tests
#

View File

@ -214,6 +214,17 @@ SELECT * FROM t1 WHERE a=10 AND a>=10;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=10 AND a>=10;
DROP TABLE t1;
--echo #
--echo # MDEV-16958 Assertion `field_length < 5' failed in Field_year::val_str or data corruption upon SELECT with UNION and aggregate functions
--echo #
CREATE TABLE t1 (f YEAR);
INSERT IGNORE INTO t1 VALUES (1971),(1972);
SELECT MAX( NULLIF( f, '1900' ) ) AS f FROM t1 UNION SELECT MAX( NULLIF( f, '1900' ) ) AS f FROM t1;
DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
--echo #

View File

@ -9476,7 +9476,10 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
break;
}
default:
max_length= MY_MAX(max_length, display_length(item));
if (fld_type == MYSQL_TYPE_YEAR)
max_length= MY_MAX(max_length, item->max_length);
else
max_length= MY_MAX(max_length, display_length(item));
};
maybe_null|= item->maybe_null;
get_full_info(item);