androidsqlitememory-managementaudit-tables

make sure audit table doesn't affect RAM used by application


I tried to simplify my situation as much as possible, so it doesn't look too real, sorry. But it is based on a real concern.

Let's imagine I have a small Android application that is showing user the current temperature. The temperature is changing every second and the application is working all the time.

Also the app has an "audit" DB table:

CREATE TABLE TemperatureAudit (
secondsFrom1970 INTEGER not null,
temperature INTEGER not null);

After a year of this application working the audit table will be quite large. And let's imagine I don't want to truncate it if it's not really necessary.

So the question for those who know how sqlite working on Android: should I worry?

  1. Will sqlite try to load this big table in RAM when I don't use it? For instance when I select from a different table.
  2. Will sqlite load this big table one part after another if I try to "select count from TemperatureAudit where temperature > 0"? Or will it load the whole table in RAM in one piece?
  3. If sqlite is not too stingy with memory allocation what can I do? Will moving this table to another database help with the first problem? Will the table partitioning help with the second?

Solution

  • SQLite loads the metadata of all tables, but it does not load any actual data that is not needed.

    All accesses to the database are done through pages, which have a size of a few KB; any page not currently being used is not required to be in memory. So scanning through a table requires very little memory.