Hello,

I am using sqlite3 (3.7.15.2 at the moment) in a project.

I discovered that the order of columns in a group by affects the
performance of a query. Is this expected?

For example:

Table:  Column A int, Column B int, Column C int
One Index:  A,B  (combined)

Query 1:  SELECT A,B,count(*) from tableTest group by A,B
Query 2:  SELECT A,B,count(*) from tableTest group by B,A

Query 1 will use the index, while query 2 will not. (which makes Query 1 a
lot faster with bigger tables). Both querys will result with the same data.
I do not really understand why it doesn't use the index for both querys.

I am also using a virtual table (based on a two dimensional array) (very
nice feature btw, sad that it is so unknown). I am seeing the same
behaviour there. It will only use the index if it has the exact same order
as the columns in the group by.

Thanks,

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

Reply via email to