I’m sort of lost on this. I have an application that is reading from a static SQLite database that has 439397 records (~32MB).
I am querying the database on a column that is indexed, but the it takes ~8-12 seconds to finish the query. The current query I am using is to do database.query(tableName, columnHeaders, “some_id=” + id) for a list of ids.
I tried doing the “WHERE some_id IN (id1, id2, id3)” approach, but that took over twice as long. I have a feeling that I might be doing it wrong.
The query is done in an AsyncTask, so I am at a lost at what other thing I could do to improve the performance.
- UPDATE:
I resolved the problem by changing the behavior of the application.
You can use
EXPLAIN QUERY PLANto confirm that your index is indeed being properly used.You can try running your query once with a
COUNT(*)instead of the real column list, to see if the issue is the act of actually reading the row data off of flash storage (which is possible if there are lots of matches and lots of big columns).You can try running your query to match on a single ID (rather than N of them), to start to try to get a handle on whether the issue is too many comparisons.
However, please bear in mind that
AsyncTaskdoes not somehow make things magically faster. It makes things magically not run on the main application thread.