[SQLiteJDBC] Why is this query answered instantly by the sqlite3 application, but slowly using sqlitejdbc?

Gary Helmstetter gh at theworld.com
Sun Feb 28 17:20:21 EST 2010


I'm using Mac OS X v10.4.11 with the standard Java (1.5.0_19) and  
sqlite3 (3.1.3) that came it. (Yeah, a little old.)

I have a sqlite3 database with a table with a few hundred thousand  
rows, with "name" and "stored" text columns. Name is one of six (so  
far) short strings; stored is a 19-character standard date-time  
string. Each column has a stand-alone index. (Essentially, the table  
tracks events in the life of 6 entities; its other columns describe  
the individual events.) The following query:

> select distinct name from myTable where stored >= date("now");

lists the relevant names instantly when I perform it through the Mac  
OS X "sqlite3" application. I get the same results, but it takes over  
2 seconds to find each name (total of about 15 seconds), when I do the  
exact same query in the obvious way in my application:

> String         q = "SELECT DISTINCT name FROM myTable " +
>                     "WHERE stored >= DATE('now');" ;
> try {
>     Statement stmt = conn.createStatement();
>     ResultSet rs = stmt.executeQuery(q);
>     while (rs.next()) {
>         final String s = rs.getString("symbol");
>         System.err.println("Got " + s);
>     }
>     rs.close();
> }
I've tried this with both sqlitejdbc-v054 and sqlitejdbc-v055 . No  
perceptible difference.

A wild speculation, based on the way it behaves, is that when the  
sqlite3 application does the query sqlite uses the indexes optimally  
(ie. applying "stored" first), but for some reason this doesn't happen  
when sqlitejdbc does the same query.

Is this a known deficiency? If not, anyone have any suggestions how to  
attack it ?




More information about the SQLiteJDBC mailing list