Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.1, 11.8.9
-
Linux x86_64, MariaDB 11.8.9 binary distribution
-
Unexpected results
Description
Under SET NAMES binary, combining two identical ADDTIME() expressions with UNION changes the returned value by appending ten zero bytes.
SELECT DISTINCT returns the expected 16-byte value. The equivalent UNION query returns a 26-byte value. The additional bytes are visible through HEX() and OCTET_LENGTH(), and cause comparison with the directly computed value to return false.
Reproducer
SET NAMES binary; |
|
|
SELECT
|
HEX(col1) AS hex_value, |
OCTET_LENGTH(col1) AS byte_length, |
col1 = ADDTIME('-01:01:01.01', '-23:59:59.1') AS equals_direct |
FROM ( |
SELECT DISTINCT |
ADDTIME('-01:01:01.01', '-23:59:59.1') AS col1 |
) AS s; |
|
|
SELECT
|
HEX(col1) AS hex_value, |
OCTET_LENGTH(col1) AS byte_length, |
col1 = ADDTIME('-01:01:01.01', '-23:59:59.1') AS equals_direct |
FROM ( |
SELECT ADDTIME('-01:01:01.01', '-23:59:59.1') AS col1 |
UNION |
SELECT ADDTIME('-01:01:01.01', '-23:59:59.1') AS col1 |
) AS s; |
Actual result
The first query returns:
hex_value: 2D32353A30313A30302E313130303030
|
byte_length: 16
|
equals_direct: 1
|
The second query returns:
hex_value: 2D32353A30313A30302E31313030303000000000000000000000
|
byte_length: 26
|
equals_direct: 0
|
The second result contains ten trailing 0x00 bytes after the expected string '-25:01:00.110000'.
Expected result
Both queries should return:
hex_value: 2D32353A30313A30302E313130303030
|
byte_length: 16
|
equals_direct: 1
|
Both UNION branches evaluate the same ADDTIME() expression. Combining their results should not append bytes or change the value.
Additional observations
- The difference is reproducible through server-side HEX(), OCTET_LENGTH(), and equality comparison.
- The same query pair returns matching results with SET NAMES utf8mb4 or SET NAMES latin1.
Related report
MySQL Bug #40217: UNION ALL query results present faulty internal datetime
MySQL Bug #40217 is closed. The developer comment states that it was fixed in MySQL 5.6.40 and later.
Attachments
Issue Links
- relates to
-
MDEV-41659 UNION loses a stored DATE value with zero components after enabling NO_ZERO_IN_DATE and NO_ZERO_DATE
-
- Open
-