What are the overheads of using AUTOINCREMENT for SQLite on Android?
My estimate, noting that I'm not a statistician, is that the overhead is something like 8-12% slower.
I obtained the results using 3 structurally similar and simple tables with two TEXT columns, running 10,000 inserts per each table, repeating this 5 times on 4 devices.
Table 1 (Dflt column) was created with just the two TEXT Columns (thus utilising the default ROWID).
Table 2 (AI column) was created using _id INTEGER PRIMARY KEY AUTOINCREMENT
in addition to the two TEXT columns.
Table 3 (No AI column) was created using _id INTEGER PRIMARY KEY
in addition to the two TEXT columns.
So Table 2 uses the slightly different ROWID selection algorithm for inserts.
The four devices used were :-
(1) A Genymotion emulated device (Custom Tablet - 5.1.0 - API 22 - 1536x2048 )
(2) An Onix 10" tablet (AT101-1116 )
(3) An HTC 1 M8 (HTC_0PKV1 )
-
(4) A Lenevo A10-30 tablet (Lenovo TB2-X30F )
The results I obtained were :-
The results are more favourable when everything is run in just 1 transaction (i.e beginTransaction();
before any inserts, with setTransactionSuccessful();
and endTransaction();
after all inserts (for all tables i.e. the entire 150,000 inserts), e.g. :-
Comparison of the two tables, highlights the benefits that using transactions can have upon performance.