low_card_tables icon indicating copy to clipboard operation
low_card_tables copied to clipboard

Implicit transaction commits

Open yogin opened this issue 9 years ago • 0 comments

Hey @ageweke , it's been a while, how's it going?

We just started using this gem, because it was so helpful before ;)

However, we just stumbled on an issue with table locks.

We're using the DatabaseCleaner gem with Rspec, to cleanup the database around our specs. It has several strategies, and one of them is transaction, which uses savepoints to rollback queries. https://dev.mysql.com/doc/refman/5.5/en/savepoint.html

It was working great until we added low_card_tables. Since it does a LOCK .. WRITE; ...; UNLOCK TABLES; when adding new rows, UNLOCK creates an implicit transaction COMMIT, so savepoints get released automatically. So the next time the DatabaseCleaner tries to release/rollback to a savepoint it will fail. https://dev.mysql.com/doc/refman/5.5/en/implicit-commit.html

The only solution to this I have found so far, is to change the strategy to truncation. This works, but it's much slower to run.

Wondering if you've encountered this issue before, and if you have other suggestions around this?

This could also have other side effects outside of running specs. Since it will commit any transaction you're in, possibly before you're done with your transaction.

yogin avatar Aug 10 '15 20:08 yogin