On Sep 14, 12:16 pm, PierreW <[email protected]> wrote:
>
> Articles.delete_all(["a_date < ?", xxxx]
> Comments.delete_all("comments.article_id not in (select id from
> articles)")
>
> The first query is executed with no problems. But the second one hangs
> and completely loads my database server.
>
> Notes:
> - 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.
>
Do you have an index on article_id? Id yo don't this will be super
slow. A subselect that this is probably going to be slow - i'd try a
left join instead, i.e. something like
Comment.joins("left join articles on articles.id =
article_id").where("articles.id is null").delete_all
An index on article id is still advisable
Fred
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.