0

I'm having a problem inserting many rows with SQLDelight. I'm not sure if the query is deadlocked, or just taking many minutes. I'm inserting about 10k rows in two different tables.

Both have a .sq file like:

save:
INSERT OR REPLACE INTO TableA VALUES ?;

my insert:

val tableAQueries = database.tableAQueries
withContext(Dispatchers.IO) {
    tableAQueries.transaction {
        rows.forEach { tableAQueries.save(it) }
    }
}
Sean
  • 2,632
  • 2
  • 27
  • 35
  • Try inserting in batches to see how long it will take approximately. – Phil Dukhov Sep 23 '21 at 16:01
  • I gave up after 10 minutes. So it's something longer than that unless i have some deadlock. Doing the same thing with Room took a few seconds. – Sean Sep 23 '21 at 16:35
  • I mean split it in 10 or 100 transactions, to see how long one of them takes. Maybe even start with checking out that a single request finishes fine. – Phil Dukhov Sep 23 '21 at 16:37
  • Well, I feel pretty silly. There's some deadlock, Thanks for the advice. Seems really obvious in hindsight, but my mind was somewhere else. I'll report back when I have some a better idea of how long the insert is actually taking. – Sean Sep 23 '21 at 18:34
  • OK, so that snippet I have posted is actually quite fast. I don't have any hard numbers, but it's comparable to Room. The real problem was some deadlock. Don't run a query on another thread in a mapper. – Sean Sep 23 '21 at 19:22
  • can you please add what you have done after this? so I can understand and solve my problem too – Gulab Sagevadiya Apr 23 '22 at 04:42
  • My problem was that I had another sql query in a mapper. The actual insert as written here worked fine. – Sean May 02 '22 at 09:18

0 Answers0