Comments on: The order of columns in GROUP BY statements matters on mysql http://v1.ripper234.com/p/the-order-of-columns-in-group-by-statements-matters/ Stuff Ron Gross Finds Interesting Sun, 02 Aug 2015 11:03:35 +0000 hourly 1 https://wordpress.org/?v=4.5.3 By: ripper234 http://v1.ripper234.com/p/the-order-of-columns-in-group-by-statements-matters/comment-page-1/#comment-2439 Sun, 19 Dec 2010 11:34:15 +0000 http://v1.ripper234.com/?p=1331#comment-2439 No, when used in a where clause, the order of the items does not matter.

Try running EXPLAIN on these queries.

]]>
By: Ofer Egozi http://v1.ripper234.com/p/the-order-of-columns-in-group-by-statements-matters/comment-page-1/#comment-2437 Sun, 19 Dec 2010 09:51:34 +0000 http://v1.ripper234.com/?p=1331#comment-2437 Isn’t it the same as making the same order change for a simple WHERE clause? in your case:
SELECT COUNT(*) AS cnt FROM products WHERE SourceId=1 AND ExternalProductId IS NOT NULL
versus
SELECT COUNT(*) AS cnt FROM products WHERE ExternalProductId IS NOT NULL and SourceId=1
that will also make all of the difference between using the index and not using it, since the index is used in the order it was defined.
http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html

]]>
By: ripper234 http://v1.ripper234.com/p/the-order-of-columns-in-group-by-statements-matters/comment-page-1/#comment-2423 Sat, 18 Dec 2010 17:24:05 +0000 http://v1.ripper234.com/?p=1331#comment-2423 @Ken – tell that to Facebook 🙂

But yeah, this looks like a bug in the query analyzer – Shlomo plans to file it as a bug report.

]]>
By: Ken Egozi http://v1.ripper234.com/p/the-order-of-columns-in-group-by-statements-matters/comment-page-1/#comment-2422 Sat, 18 Dec 2010 17:16:03 +0000 http://v1.ripper234.com/?p=1331#comment-2422 Perhaps it is a matter of the indices defined for that table. MySQL is not known for its Query Analyser. A proper RDBMS will supposedly be smarted about this.

]]>