I have a table created with this command:
CREATE TABLE "A" (`id` INTEGER PRIMARY KEY NOT NULL, `b_id` INTEGER NOT NULL REFERENCES B(id) ON DELETE CASCADE, `c_id` INTEGER NOT NULL REFERENCES C(id) ON DELETE CASCADE, `field1` INTEGER, `field2` TEXT NOT NULL, `field3` INTEGER NOT NULL, `field4` INTEGER NOT NULL, `field5` INTEGER NOT NULL)
When I enable foreign key support (via the PRAGMA command), I have performance issues on this table when doing a "large" number of updates (around 3000). I have no problem on other tables (which also contains foreign keys). For this table, the updates are done in ~90seconds whereas it only takes ~1sec for other tables. If I don't enable foreign keys, the ~3k updates are quickly (a few seconds) done.
Few additional notes:
- I use FMDatabase as wrapper of SQLite.
- I wrap my update statements in a transaction.
- The execution time of the transaction seems to be linear with the number of updates in the transaction. For example, if I do only 100 updates, it will take approximately 3 seconds.
- I tried to VACUUM the database, and I even tried to re-create it from scratch. It didn't change anything.
If anyone has an idea about the origin of this issue, please tell!