On 4/13/2012 2:59 PM, Steinar Midtskogen wrote:
I have a table with "unix_time" as primary key and I want to get the
minimum and maximum values of "unix_time".  When I do:

   SELECT min(unix_time), max(unix_time) from table;

it is very slow.  It takes about 250ms, nearly everything in the
step() call.

However, if I do:

   SELECT min(unix_time) FROM table; SELECT max(unix_time) FROM table;

to get the same values, it takes a fraction of the time.  The speedup
is more than 2000x.

If you want to do it with a single query (say, to minimize disturbance to existing code), you could make it

select (SELECT min(unix_time) FROM table), (SELECT max(unix_time) FROM table);

I'm pretty sure this will get executed the fast way.
--
Igor Tandetnik

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

Reply via email to