Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate interferes with transaction and slows down import. #129

Open
mrschuster opened this issue Apr 4, 2018 · 1 comment
Open

Truncate interferes with transaction and slows down import. #129

mrschuster opened this issue Apr 4, 2018 · 1 comment

Comments

@mrschuster
Copy link

When using MySQL and loading yaml data, the tables are cleared via "TRUNCATE". This is a DDL statement in MySQL and seems to break the surrounding transaction in Rails. In consequence, the INSERT statements get very slow on my system.

Importing about 500.000 records takes two hours. When I replace the TRUNCATE by a DELETE statement, the surrounding transaction works fine and the import is done within minutes. The additional time for the DELETE instead of TRUNCATE is negligible. I thus suggest to either always use a "DELETE" statement or to put the transaction block around the "load_records" call.

I used rails 5.1.5 with mysql2 gem 0.4.10 to produce the issue.

@kwerle
Copy link

kwerle commented Apr 30, 2020

module YamlDbWithoutTruncation
  def truncate_table(table)
    true
  end
end
YamlDb::SerializationHelper::Load.singleton_class.prepend(YamlDbWithoutTruncation) if ENV['WITHOUT_TRUNCATION'] == true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants