Are you deleting all data in the table? Use TRUNCATE https://www.sqlite.org/lang_delete.html

Else see what SQLite tells you in its query plan: https://www.sqlite.org/eqp.html

Hard to suggest optimizations without knowing what you are doing

Reply to this note

Please Login to reply.

Discussion

I’m deleting all rows where a specific column contains a specific string (removing events that spam scamming links from the relay db).

You tried setting index on that column?

That could probably make it more efficient but tbh, I don’t want to mess too much with the database itself as I expect the relay software to handle that. Don’t want to mess up an upgrade later on. Thanks for the suggestion though.

Also batching. When you delete too many rows in a single query it’s a transaction that either succeeds or fails as a whole. If you can split deletes into chunks, each chunk only has to worry about those N records.

Might be better to do it in batches but not sure how to write that query though. Do I do subqueries?

I always find it easier to do recursive queries via API calls instead in code - excluding things like tree parent/child select queries.

Often there is a batch or streaming API that can be used. Unsure for SQLITE.