0

I have a table called accounts that is extremely large ~600,000+. From this table, I need to delete about 1/3 of the accounts. On the accounts table are many references to different tables. What I want to do is to delete the accounts by batches to speed up the process but it looks like the Rails delete method does not do that.

So that is my question. Does the delete method trigger the DELETE CASCADE command? I tried it out on the rails console and it would seem that it in fact does not trigger a DELETE CASCADE. Is the only purpose of the delete method is to not trigger rails callbacks? Is there a different method that I can look into?

Dan Rubio
  • 4,709
  • 10
  • 49
  • 106
  • Possible duplicate of [Rails: delete cascade vs dependent destroy](http://stackoverflow.com/questions/12556614/rails-delete-cascade-vs-dependent-destroy) – infused Mar 21 '16 at 20:11

1 Answers1

2

There is not actually a Postgres command called DELETE CASCADE. But if you have foreign keys with the option ON DELETE CASCADE, then yes, when you delete a row, the rows that reference it will be deleted too. None of this is really Rails, but just Postgres.

Paul A Jungwirth
  • 23,504
  • 14
  • 74
  • 93