Comments - GROUP BY trick has been optimized away

11 years, 9 months ago Elena Stepanova

Hi,

You might probably switch to the old behavior for a while by setting optimizer_switch='derived_merge=off' (or optimizer_switch='derived_merge=off,derived_with_keys=off', depending on the structure of your table) in your session or globally in the config file; but really, you are just playing with fire, and most likely it won't be long before you get the problem again, possibly without such luck as noticing it in time.

While MySQL definition might not say anything about Los Angeles being bigger than Adelanto, it is perfectly clear about the type of queries that you use, and says explicitly that behavior here is undefined:

http://dev.mysql.com/doc/refman/5.5/en/group-by-hidden-columns.html

"MySQL extends the use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause. This means that the preceding query is legal in MySQL. You can use this feature to get better performance by avoiding unnecessary column sorting and grouping. However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate. Furthermore, the selection of values from each group cannot be influenced by adding an ORDER BY clause. Sorting of the result set occurs after values have been chosen, and ORDER BY does not affect which values the server chooses."

There is nothing that suggests that your subquery trick should make the difference and assure the deterministic result you are hoping for.

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.