Description:
REPLACE() returns an incorrectly truncated string when the same expression is used in both branches of a UNION.
Evaluating REPLACE('aaaa', 'a', 'bb') directly with SELECT DISTINCT correctly returns 'bbbbbbbb'. However, combining two identical SELECT statements with UNION returns 'bbbb'.
Each of the four occurrences of 'a' should be replaced with 'bb', producing eight characters. UNION should remove the duplicate row without changing its value.
Reproduced on MySQL 9.6.0 and 26.7.0 using the mysql command-line client. No tables or data setup are required.
How to repeat:
-- Correct: returns bbbbbbbb
SELECT DISTINCT REPLACE('aaaa', 'a', 'bb');
-- Incorrect: bbbb
SELECT REPLACE('aaaa', 'a', 'bb') UNION SELECT REPLACE('aaaa', 'a', 'bb');
Expected result:
Both queries should return one row containing 'bbbbbbbb'.
The UNION branches contain identical, deterministic expressions with identical argument types and values. Duplicate elimination should not truncate the resulting string.
Description: REPLACE() returns an incorrectly truncated string when the same expression is used in both branches of a UNION. Evaluating REPLACE('aaaa', 'a', 'bb') directly with SELECT DISTINCT correctly returns 'bbbbbbbb'. However, combining two identical SELECT statements with UNION returns 'bbbb'. Each of the four occurrences of 'a' should be replaced with 'bb', producing eight characters. UNION should remove the duplicate row without changing its value. Reproduced on MySQL 9.6.0 and 26.7.0 using the mysql command-line client. No tables or data setup are required. How to repeat: -- Correct: returns bbbbbbbb SELECT DISTINCT REPLACE('aaaa', 'a', 'bb'); -- Incorrect: bbbb SELECT REPLACE('aaaa', 'a', 'bb') UNION SELECT REPLACE('aaaa', 'a', 'bb'); Expected result: Both queries should return one row containing 'bbbbbbbb'. The UNION branches contain identical, deterministic expressions with identical argument types and values. Duplicate elimination should not truncate the resulting string.