"Cory Nelson" and the whole list wanted to know...


On Fri, Feb 22, 2013 at 9:56 AM, jose isaias cabrera wrote:

Greetings.

which one is faster...

#1.

SELECT id FROM LSOpenJobs WHERE bdate BETWEEN '2012-01-01' AND '2012-12-31';

or this one...

#2

SELECT id FROM LSOpenJobs WHERE bdate IN ('2012-01-01', ..., '2012-12-31)';

where , ..., would have all the rest of the dates.  Thanks.

josé

This is a great opportunity to learn the Try It And See approach.

Note that:
- The first query will only perform 2 comparisons.
- The second query will perform 31 comparisons.
- Dates are not strongly-typed in SQLite, so this will perform string
comparisons without any special handling.

SELECT id FROM LSOpenJobs WHERE bdate BETWEEN '2012-01-01' AND '2012-12-31';
total records 5976
Total time 344ms

SELECT id FROM LSOpenJobs WHERE bdate IN ('2012-01-01',
'2012-01-02',
'2012-01-03',
'2012-01-04',
...clip...
'2012-12-29',
'2012-12-30',
'2012-12-31');
total records 5976
Total time 375ms

I guess BETWEEN wins vs IN.  Thanks.

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

Reply via email to