1

I will working sqlite for my project. Maybe db have one table and ~40k rows. I have some question for this.

  • When i was use SQLiteDatabase.openDatabase() then all rows go into the memory? or row adress maybe?(Afraid for large memory problem coz 40k rows)

  • When query methods then this search on memory? or on db file?

  • SQLiteDatabase.openDatabase() reference i use this with static is there a problem?

  • Finally ~40k rows Is this a problem for memory performance etc?

kibar
  • 822
  • 3
  • 17
  • 37

2 Answers2

3

When i was use SQLiteDatabase.openDatabase() then all rows go into the memory?

No, thats the point of databases.

When query methods then this search on memory? or on db file?

A query will only load required data temporarily to apply given filters. Not even the reult is completely loaded in to memory (unless you do so with the returned Cursor).

SQLiteDatabase.openDatabase() reference i use this with static is there a problem?

Probably not, but you should avoid to keep databases open for the entire lifetime of your process.

Finally ~40k rows Is this a problem for memory performance etc?

This is not a big number for a database. It will most certainly be no problem.

F43nd1r
  • 7,690
  • 3
  • 24
  • 62
  • Why would keeping the DB open be a problem? Re-opening it for every query would be horribly inefficient. – CL. May 10 '16 at 08:11
  • @MaximG No. The page cache is part of the connection. – CL. May 10 '16 at 08:28
  • @CL. Keeping an unused connection open might only be problematic if multiple threads want to access the database. This part of my answer comes from server side development, where creating too many connections is problematic. I agree that this is less important in Android development. – F43nd1r May 10 '16 at 14:06
  • @F43nd1r Open but unused connections do not affect other connections; only active transactions do. – CL. May 10 '16 at 14:53
  • @CL. DB stored as file. What's about file descriptors? – Maxim G May 11 '16 at 05:42
  • @MaximG What about them? If you were really running out of FDs, re-opening the DB would fail, too. – CL. May 11 '16 at 06:49
1

SQLite has only five data types and you can calculate approximate size.

By query you get cursor (pattern) with window (buffer), the size may be 1mb.

Version of android matters.

Finally, profiling can show the real picture.

Community
  • 1
  • 1
Maxim G
  • 1,479
  • 1
  • 15
  • 23