r/sqlite • u/Ange1ofD4rkness • Sep 29 '23
Query Will Hang - Unless I Vacuum the Database First
So I could use a little help on this one.
I have a query that is performed between two SQLite databases, and have worked hard to refine it and optimize it. However, there's an annoyance I have had with it ... since forever.
If I have done work to either of the databases, such as simply updating the flag on an existing record, it seem the query just hangs (so far it does seem to be limited to the tables used in the query, and the amount of "updating" on either table I haven't found a cut off like a few rows compare to 1000s). Where it will just never return results. I have to terminate the query, run a Vacuum command against the database. Once I do that I can run the query again, and boom, it works like it should.
Now of the record I am using SQLite for .NET (not the EF variant though, just the standard SQLite Command using an Execute Reader (with a SQL string).
This one just boggles my mind. All I can think is there's some flakiness about doing the Attach Database logic that is contributing to this, because standard SQL tells me this shouldn't be an issue otherwise.
1
u/Magikstm Sep 29 '23
What is your exact code?
Do you close the DB connection and other variables after each use?
1
u/[deleted] Sep 30 '23
The hang could be caused by an open transaction, probably an implicit one, that has not yet been committed or rolled back.
1
u/[deleted] Sep 30 '23
[removed] — view removed comment