Does SQLite load whole db file into memory when connected?

前端 未结 2 1518
耶瑟儿~
耶瑟儿~ 2021-02-19 19:18

I want to know is Database more efficient or just a normal json file if it has many items, in android device.

相关标签:
2条回答
  • 2021-02-19 19:40

    No, Sqlite will read data for hard disk by paging. The Sqlite document said: "In order to return data from the database to the user, for example as the results of a SELECT query, SQLite must at some point read data from the database file. Usually, data is read from the database file in aligned blocks of page-size bytes. "

    Link: https://www.sqlite.org/fileio.html

    0 讨论(0)
  • 2021-02-19 19:58

    There is an option when "connecting" to an SQLite database of using memory instead of filesystem as storage.

    But it is used only when creating new databases so the "new" in memory database will be empty. This is useful when you want to take advantage of SQL like indexing and querying on a large set of data.

    Unfortunately copy from filesystem into memory (or vice-versa) is not a feature in SQLite. It's a design choice because the SQLite file must be locked by your (or others) for concurrency control.

    Typically a DSN to connect to an SQLite database would look like this 'sqlite:/path/to/file.sqlite'. And access control to the database is given by access filesystem rights. In the case of in memory databases the DSN will look like this 'sqlite::memory'.

    0 讨论(0)
提交回复
热议问题