[MDEV-3580] LP:694450 - Wrong result with non-standard GROUP BY + ORDER BY Created: 2010-12-26 Updated: 2012-10-04 Resolved: 2012-10-04 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Philip Stoev (Inactive) | Assignee: | Oleksandr Byelkin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Launchpad | ||
| Attachments: |
|
| Description |
|
The following query: SELECT alias2.f3 AS field1 , alias2.f1 AS field2 FROM t1 AS alias1 JOIN t1 AS alias2 ON alias2.f1 = alias1.f2 AND alias2.f1 != alias1.f4 GROUP BY field1 , field2 ORDER BY alias1.f2 , field2; is non-standard in a sense that the ORDER BY contains a column not specified in the SELECT list or GROUP BY. Yet, ONLY_FULL_GROUP_BY SQL mode does not generate an error, and the query returns a wrong result. It seems that this bug is present in all MariaDB and MySQL version. It would be nice to fix it because it causes various false positives when testing 5.3 optimizations. Test case: SET SESSION SQL_MODE='ONLY_FULL_GROUP_BY';
|
| Comments |
| Comment by Kristian Nielsen [ 2010-12-27 ] | ||||||||||||
|
Re: Wrong result with non-standard GROUP BY + ORDER BY First, from a quick test, it looks to me as if ONLY_FULL_GROUP_BY simply is not taken into account for ORDER BY. Even trivial examples show this. Maybe it makes sense to report this to MySQL. Second, you say that the two queries return different result sets (one row vs. several). This seems to be a regression compared to MariaDB 5.1.51, where I get the same set of rows from both queries: MariaDB [test]> SELECT alias2.f3 AS field1 , alias2.f1 AS field2 FROM t1 AS alias1 JOIN t1 AS alias2 ON alias2.f1 = alias1.f2 AND alias2.f1 != alias1.f4 GROUP BY field1 , field2 ORDER BY alias1.f2 , field2;
--------------------
-------------------- MariaDB [test]> SELECT alias2.f3 AS field1 , alias2.f1 AS field2 FROM t1 AS alias1 JOIN t1 AS alias2 ON alias2.f1 = alias1.f2 AND alias2.f1 != alias1.f4 GROUP BY field1 , field2 ;
--------------------
-------------------- (Since you say "this bug is present in all MariaDB and MySQL versions", I was not sure if you meant just the ignoring of ONLY_FULL_GROUP_BY in ORDER BY, or also the result difference). | ||||||||||||
| Comment by Philip Stoev (Inactive) [ 2010-12-27 ] | ||||||||||||
|
Re: Wrong result with non-standard GROUP BY + ORDER BY A. ONLY_FULL_GROUP_BY does not prevent a query with sub-standard ORDER BY from running. I think this bug has been there since the dawn of time. I will report it to MySQL when I have a chance. B. Wrong result from the query. Here are the results I am getting:
| ||||||||||||
| Comment by Philip Stoev (Inactive) [ 2010-12-27 ] | ||||||||||||
|
Re: Wrong result with non-standard GROUP BY + ORDER BY with order by: id select_type table type possible_keys key key_len ref rows Extra without order by: id select_type table type possible_keys key key_len ref rows Extra | ||||||||||||
| Comment by Kristian Nielsen [ 2010-12-27 ] | ||||||||||||
|
Re: Wrong result with non-standard GROUP BY + ORDER BY | ||||||||||||
| Comment by Oleksandr Byelkin [ 2012-03-14 ] | ||||||||||||
|
Re: Wrong result with non-standard GROUP BY + ORDER BY | ||||||||||||
| Comment by Rasmus Johansson (Inactive) [ 2012-03-14 ] | ||||||||||||
|
Launchpad bug id: 694450 |