Bug #111094 Results ordered incorrectly
Submitted: 21 May 2023 2:25 Modified: 22 May 2023 6:54
Reporter: Benno Lang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.33, 8.0.36 OS:Ubuntu (8.0.33-0ubuntu0.20.04.2)
Assigned to: CPU Architecture:x86

[21 May 2023 2:25] Benno Lang
Description:
In certain cases results aren't ordered by what's specified in ORDER BY

How to repeat:
CREATE TABLE order_test (
	id INT UNSIGNED NOT NULL AUTO_INCREMENT,
	val varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs NOT NULL,
	PRIMARY KEY (id),
	KEY val(val)
);

INSERT INTO order_test (val) VALUES ('Wä'), ('E');

-- Incorrect order
SELECT *, val = 'wä', val = 'Wä', val = 'E'
FROM order_test
ORDER BY val = 'wä' DESC, val = 'Wä' DESC, val = 'E' DESC;

+----+-----+-------------+-------------+-----------+
| id | val | val = 'wä'  | val = 'Wä'  | val = 'E' |
+----+-----+-------------+-------------+-----------+
|  2 | E   |           0 |           0 |         1 |
|  1 | Wä  |           0 |           1 |         0 |
+----+-----+-------------+-------------+-----------+
2 rows in set (0.00 sec)

-- Expected order
SELECT *, val = 'ka', val = 'Wä', val = 'E'
FROM order_test
ORDER BY val = 'ka' DESC, val = 'Wä' DESC, val = 'E' DESC;

+----+-----+------------+-------------+-----------+
| id | val | val = 'ka' | val = 'Wä'  | val = 'E' |
+----+-----+------------+-------------+-----------+
|  1 | Wä  |          0 |           1 |         0 |
|  2 | E   |          0 |           0 |         1 |
+----+-----+------------+-------------+-----------+
2 rows in set (0.00 sec)
[22 May 2023 6:54] MySQL Verification Team
Hello Benno Lang,

Thank you for the report and test case.

regards,
Umesh