Detecting forgotten SQLite transaction on Android

2019-03-30 04:44发布

Executing multiple SQL statements without putting them into one transaction is a severe bottleneck (see e.g. http://www.sqlite.org/faq.html#q19). I haven't thoroughly checked how SQLite is configured on Android, but anecdotally I perceived dramatical performance increase within my on app when using transactions in more places.

Is it possible to detect instances where one forgets to use transactions using StrictMode? If not, could that be considered for a future release of StrictMode? It might be somewhat tricky to detect, but two different strategies could be, 1) non-select statements outside transaction, or 2) multiple non-select statements outside transaction executed within a short period of time.

1条回答
该账号已被封号
2楼-- · 2019-03-30 05:22

Yeah, that sounds like a good thing to catch. I could imagine an API like:

StrictMode.catchWritesOutsideTransactionsOn(SQLiteDatabase db);

We've been considering other SQLite hooks into StrictMode (mostly around selects missing indexes and such), but this is a good idea too!

查看更多
登录 后发表回答