Bug #119619 Incorrect results for REPLACE function
Submitted: 4 Jan 14:07 Modified: 4 Jan 21:17
Reporter: John Jove Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S1 (Critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[4 Jan 14:07] John Jove
Description:
Run the following statements, which are expected to return 1133133.

How to repeat:
DROP TABLE t1;
CREATE TABLE t1 (c1 TINYINT UNSIGNED);
INSERT INTO t1 VALUES (133);
SELECT (REPLACE((IF(c1, c1, c1)), (BIT_COUNT(c1)), c1)) FROM t1 GROUP BY c1; -- actual: {113313}, expected: {1133133}
[4 Jan 14:09] John Jove
The following case may help to fix the problem.

DROP TABLE t1;
CREATE TABLE t1 (c1 BIGINT UNSIGNED);
INSERT INTO t1 VALUES (133);
SELECT (REPLACE((IF(c1, c1, c1)), (BIT_COUNT(c1)), c1)) FROM t1 GROUP BY c1; -- {1133133}
[4 Jan 21:17] Roy Lyseng
Verified as described.