Description:
mysql> SELECT GREATEST(2024, DATE'2024-01-01'); -- 16383-15-31 ← illegal date!
+----------------------------------+
| GREATEST(2024, DATE'2024-01-01') |
+----------------------------------+
| 16383-15-31 |
+----------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> SELECT MONTH(GREATEST(2024, DATE'2024-01-01')); -- NULL (month 15 out of range)
+-----------------------------------------+
| MONTH(GREATEST(2024, DATE'2024-01-01')) |
+-----------------------------------------+
| NULL |
+-----------------------------------------+
1 row in set, 2 warnings (0.04 sec)
Month 00 / month 15 / year 16383 are bit-mixing products of the YEAR numeric value and the DATE packed value; MONTH() returns NULL for all of them. All GREATEST variants return the same garbage 16383-15-31 regardless of arguments.
Column/constant split: GREATEST(YEAR_col, DATE'2024-01-01') returns 2024-01-01 ✓ (correct) — the constant form is wrong, the column form is right.
Impact: a legal GREATEST(YEAR expression, date) query outputs an illegal date — all downstream MONTH()/DAY()/date arithmetic/formatting silently misbehaves, with no warning.
Anchor: adjacent to fix 38469912f01 (LEAST/GREATEST cmp_context fix for ZEROFILL constant substitution — does not cover YEAR×DATE type aggregation).
How to repeat:
SELECT GREATEST(2024, DATE'2024-01-01'); -- 16383-15-31 ← illegal date!
SELECT MONTH(GREATEST(2024, DATE'2024-01-01')); -- NULL (month 15 out of range)