views:

185

answers:

2

I have a quite slow data retrieval from a sqlite database on my iPhone and perhaps someone have an alternative idea to explain this. From what I tracked down so far sqlite3_step(statement) is sometimes unusually slow. While retrieving e.g. 50 rows from the database to execute this step takes normally some milliseconds but sometimes it takes several seconds.

My database is not small (80MB) and my theory is that the reason is paging. But can someone else think of an other reason for this?

A: 

Do you have a proper index on that table? Queries can be very slow if a full table scan is required to perform your query. See this page for example for some guidance on how to optimize your SQLite queries.

You may simply need to add an index to your table. Don't forget to reindex your table after you add your index (you'll need a tool, there's a free firefox add-on called "SQLite Manager" that does a pretty decent job for this)

Zoran Simic
The utk page is a good one indeed. But now I'm getting better results (even by sacrificing indexes) by compacting my db although I still have the feeling it page in and out data in the background.
georgij
A: 

This is also an excellent resource for SQLite performance tuning.

Gerard Gualberto