I have a problem with a fairly standard Rails / mySQL query. I must be
doing something very wrong. I was hoping somebody could shed some
light on this.
First model: article, has_many comments
Second model: comment, belongs_to article
The number of articles and comments can be big (one to two millions).
Every once in a while, I "clean" the DB and remove older articles and
Articles.delete_all(["a_date < ?", xxxx]
Comments.delete_all("comments.article_id not in (select id from
The first query is executed with no problems. But the second one hangs
and completely loads my database server.
- I am not using :dependent => :delete since I was thinking doing a
destroy instead of delete on Articles would be too slow (my
understanding is when you "destroy", Rails loads the object first)
- I have killed all other queries on the DB, just to make sure there
are no locks somewhere.