Gregoire de Turckheim <gdt--sql...@taveo.com> wrote: > I'm noticing a strange behaviour with SELECT statements. > > Let's consider this statement : > > SELECT * FROM log > WHERE id_clie...@idclient > ORDER BY utc DESC > LIMIT 1 > > The table has an index on the "utc" and "id_client" fields pair. > > When running this query with an @IdClient value which exists in the > table, the query returns instantly (< 200ms)
Just a lucky choice of the ID. Try one that only appears near the bottom of the list, when sorted by (utc DESC). Your index cannot be used to satisfy the WHERE clause, and is only used for ORDER BY. So SQLite does a full table scan, in order of utc, until it hits the record with the right id_client. Try an index on (id_client, utc) instead, in that order. -- Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users