Wrong values of CASE, COALESCE, IFNULL on a combination of different temporal types

Description

Notice, CASE correctly creates a DATETIME(3) column.
However, it returns wrong values from both SELECT queries.
The expected value is:
'0000-00-00 '00:00:00.567'

More examples:

The expected result is '2001-01-01 00:00:00.120' for both queries.

The expected result is '2001-01-01 00:00:00.120'.

The expected result is '2002-01-01 00:00:00'.

The expected result is '0000-00-00 00:00:00.567', without a warning.

A similar problem is observed with COALESCE:

The expected result is '2002-01-01 00:00:00.000' for both queries.

The expected result is '2001-01-01 00:00:00.120' for both queries.

A similar problems is observer with IFNULL:

The expected value is '2001-01-01 00:00:00.120' for both expressions.

The expected value is '2002-01-01 00:00:00.000' for both expressions.

Environment

None

Status

Assignee

Alexander Barkov

Reporter

Alexander Barkov

Labels

None

External issue ID

None

External issue ID

None

Fix versions

Affects versions

Priority

Minor
Configure