Commit 78c24992 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-16958 Assertion `field_length < 5' failed in Field_year::val_str or data...

MDEV-16958 Assertion `field_length < 5' failed in Field_year::val_str or data corruption upon SELECT with UNION and aggregate functions
parent 3d2d060b
......@@ -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
#
......@@ -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 #
......@@ -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);
......
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