Skip to content

Commit

Permalink
MDEV-16958 Assertion `field_length < 5' failed in Field_year::val_str…
Browse files Browse the repository at this point in the history
… or data corruption upon SELECT with UNION and aggregate functions
  • Loading branch information
abarkov committed Mar 15, 2019
1 parent 3d2d060 commit 78c2499
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mysql-test/r/type_year.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
11 changes: 11 additions & 0 deletions mysql-test/t/type_year.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
5 changes: 4 additions & 1 deletion sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 78c2499

Please sign in to comment.