> My understanding is that any reading from database automatically
> starts read transaction. The question: why does sqlite need to do it on read-only database?
You may open a database as read-only, but another process can open it
as read-write. So SQLite needs to check the lock even when the DB
is opened as read-only.
Now if the database is on a read-only file system, it is possible to
tell SQLite by
opening with file:foo.sqlite?immutable=1 (see https://www.sqlite.org/uri.html)
and that can save some time. But make sure to read the caveats at above URL.
To keep the results of a query consistent one better starts a transaction. A database can be updated by one thread at a time, but read by many.
Suppose you need a list of all employees of a department. If you start to search one at a time a lot of changes can happen. An employee can be moved to another department, fired or a new one entered. Another reason is speed. All (or most if it is a huge department and/or a tiny cache) employees are in cache so you're sure you have the requested list showing the situation on the moment of creation.
Andrii Motsok wrote Thu, 6 Oct 2016 11:43:10:
>My understanding is that any reading from database automatically starts read transaction.
>The question: why does sqlite need to do it on read-only database?