On Tue, 13 Jun 2017 11:53:05 +0200
rv.gauth...@free.fr wrote:

> Hi all,
> 
> we are using sqlite3 on an embedded application.
> The database is opened in read only mode and can't be modified by the 
> application.
> 
> I noticed that the first SELECT statement after a BEGIN TRANSACTION 
> takes at least 14 ms.
> All subsequent queries in the same transaction are taking near 0 ms.

The first SELECT says to sqlite to do all the work needed to make your
query ACID constraint (acquires locks, malloc ram, generate structs,
open files, etc...)

> 
> If I omit the BEGIN TRANSACTION, all queries are taking at least 14
> ms.

Because each query automatically is wrapped with BEGIN TRANSACTION /
query / END TRANSACTION and the work to make your query ACID is done on
every query, not on the first one.

> I tried also to do a unique BEGIN TRANSACTION after opening the 
> database. This fixes the timing issue, but my memory increases 
> constantly.

... Do you know what's a transaction? In your case it's a read only db
and don't think the could be a problem, but in normal use cases could
be catastrophic.

> Is there a way (pragma, compile flags, ...) to gain these 14 ms for
> the first query ?

Try openinig with URI, check for 'inmutable' parameter
https://www.sqlite.org/draft/c3ref/open.html , perhaps you can gain
some ms, but it's dangerous, I warn you.

> 
> Thanks.
> 
> 
> Hervé Gauthier.
> 
> 
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


---   ---
Eduardo Morras <emorr...@yahoo.es>
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to