Topic: :include slows down large queries?

ok, so when is it better to use :include and better not to?

I have a very complex page that queries many tables.  I tried :include-ing all the data (14 associations), and it generated a 4096 character long query, and the page took 2 full minutes to process at 100%cpu and 600M ram usage! D:  Ok, bad idea.

I've read that it's better to use :include so that rails doesn't have to do so many queries, which supposedly helps a lot with overhead.  Obviously not the case here.  So when is it not better to use :include?

Last edited by nilbus (2008-05-28 22:38:19)

Re: :include slows down large queries?

It is only better to a point. It uses SQL Joins to join the data together, so if you've got 14 associations then that's a lot of joining which will end up taking much more time than a normal query.

I'd only ever use :include for max of 4 or 5 associations.

ThinkRefresh - Free Rails Techniques Screencasts