bug: derived table contains union all statement, return incorrect result set
davidshiz opened this issue · comments
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Please confirm if bug report does NOT exists already ?
- I confirm there is no existing issue for this
Describe the problem
mysql> SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT a FROM t2) tu ORDER BY a;
+-------+
| a |
+-------+
| 65533 |
| 65533 |
| 0 |
| 0 |
| 1 |
| 1 |
+-------+
6 rows in set (0.00 sec)
Expected behavior
mysql> SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT a FROM t2) tu ORDER BY a;
+-------+
| a |
+-------+
| 0 |
| 0 |
| 1 |
| 1 |
| 253 |
| 65533 |
+-------+
6 rows in set (0.00 sec)
How To Reproduce
CREATE TABLE t1 (a TINYINT UNSIGNED);
INSERT INTO t1 VALUES (0),(1),(0xFF-2);
CREATE TABLE t2 (a SMALLINT UNSIGNED);
INSERT INTO t2 VALUES (0),(1),(0xFFFF-2);
SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT a FROM t2) tu ORDER BY a;
Environment
[root@stonedb-test support-files]# /stonedb57/install/bin/mysqld --version
/stonedb57/install/bin/mysqld Ver 5.7.36-StoneDB-v1.0.1 for Linux on x86_64 (build-)
build information as follow:
Repository address: https://github.com/stoneatom/stonedb.git:stonedb-5.7-dev
Branch name: stonedb-5.7-dev
Last commit ID: 6b369e5
Last commit time: Date: Thu Jun 8 19:16:12 2023 +0800
Build time: Date: Tue Jun 13 06:00:25 UTC 2023
Are you interested in submitting a PR to solve the problem?
- Yes, I will!