Bug #75828 | Incorrect sorting when using GROUP BY and COUNT | ||
---|---|---|---|
Submitted: | 9 Feb 2015 18:32 | Modified: | 24 Feb 2015 21:17 |
Reporter: | Hans Wurst | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / NET | Severity: | S3 (Non-critical) |
Version: | 6.9.5 | OS: | Windows (Win7, x64) |
Assigned to: | Roberto Ezequiel Garcia Ballesteros | CPU Architecture: | Any |
Tags: | column renaming, connector, GROUP BY, sorting |
[9 Feb 2015 18:32]
Hans Wurst
[10 Feb 2015 8:49]
Chiranjeevi Battula
Hello Hans Wurst, Thank you for the bug report. Verified this behavior on Visual Studio 2013, EntityFramework 6.1.2 with MySQL Connector/Net 6.9.5. Thanks, Chiranjeevi.
[10 Feb 2015 8:50]
Chiranjeevi Battula
SQL query: SELECT `Project1`.`Name`, `Project1`.`Id`, `Project1`.`C2` AS `C1`, `Project1`.`Id1`, `Project1`.`Name1` FROM (SELECT `GroupBy1`.`A1` AS `C1`, `GroupBy1`.`K1` AS `Id`, `GroupBy1`.`K2` AS `Name`, `Extent2`.`Id` AS `Id1`, `Extent2`.`Name` AS `Name1`, CASE WHEN (`Extent2`.`Id` IS NULL) THEN (NULL) ELSE (1) END AS `C2` FROM (SELECT `Extent1`.`Id` AS `K1`, `Extent1`.`Name` AS `K2`, COUNT(1) AS `A1` FROM `project` AS `Extent1` GROUP BY `Extent1`.`Id`, `Extent1`.`Name`) AS `GroupBy1` LEFT OUTER JOIN `project` AS `Extent2` ON `GroupBy1`.`K1` = `Extent2`.`Id`) AS `Project1` ORDER BY `Project1`.`C1` DESC, `Project1`.`Name` ASC, `Project1`.`Id` ASC, `Project1`.`C2` ASC
[23 Feb 2015 22:34]
Roberto Ezequiel Garcia Ballesteros
This is not a bug since the order by is applied to `Project1`.`C1` even if a new alias `C1` is defined. `Project1`.`C1` is the same as `GroupBy1`.`A1` but in the outer select. The query can be tested on any other query tool as console or Workbench.
[24 Feb 2015 21:17]
Hans Wurst
After hours of updating and testing I got the problem. The query can be simplyfied a little bit: SELECT `SubQuery`.`Static` AS `Random`, `SubQuery`.`Name` FROM ( SELECT RAND() AS `Random`, 1 AS `Static`, `Name` FROM `foobar` ) AS `SubQuery` ORDER BY `SubQuery`.`Random`, `SubQuery`.`Name`; With the newest MySQL 5.6.22 the query is executed correctly and sorted at random. The problem is occuring in the newest MariaDB 10.0.16 where the result is sorted incorrectly by name. But definitely no bug in MySQL Connector .NET.