Bug #121323 UNION truncates the result of REPLACE() when the replacement increases string length

Submitted: 20 Sep 13:59 Modified: 21 Sep 8:39
Reporter: jinxin gui Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.46, 8.4.11, 9.7.2 OS:Linux
Assigned to: CPU Architecture:Any
Tags: REPLACE, truncation, UNION, wrong result

[20 Sep 13:59] jinxin gui
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.
[21 Sep 8:39] Chaithra Marsur Gopala Reddy
Hi jinxin gui,

Thank you for the test case. Verified as described.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.050 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.