On Fri, 26 Apr 2013 11:12:15 +0200
Hick Gunter <h...@scigames.at> wrote:

> It is not unreasonable to assume that in a well designed SQL
> Statement the GROUP BY clause will be backed up by the necessary
> index and an identical ORDER BY clause

That is an entirely unreasonable assumption.  Order may or not matter.
I've often written GROUP BY queries ordered by the aggregate, or to
select the maximum.  

> Any index that covers all the GROUP BY fields is a "good" index
> because it allows aggregates to be computed "on the fly" as opposed
> to in a temporary table.

Agreed.  I hope it's clear now that "covers" is order-independent.  It
so happens, apparently, that the order in which the column names appear
in the GROUP BY determine whether or not the index is used.  Thats
unfortunate, because it makes two equivalent queries perform very
differently.  

--jkl
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to