I’m fairly certain this 2.x feature never made it to rails 3. You can view the original ticket and patches here: http://web.archive.org/web/20081005125758/http://dev.rubyonrails.org/ticket/9560
The gist of it is, when you run something like this:
Article.includes(:comments, :author).where(‘authors.id = 1’).limit(10)
You end up with two queries. The first is a “SELECT DISTINCT authors.id…”, and the next will actually load the comments and authors associations. In Rails 2.x, AR was smart enough to only join against the tables that actually limited the resultset (e.g anything in the where or order clauses). Rails 3 will blindly join all the tables, which kills performance when you have several eager loaded associations.
I started working on a patch to apply_join_dependency but ran into a problem with table aliasing. The diff is here:
The approach is basically to scan the order and where clauses for table names. Then scan the included associations for these table names, adding them (and any intermediate joins) to a list, and only joining those associations. The problem is when the arel object is built for clean_relation, it has fewer joins than the original. AR builds a JoinDependency object and JoinDependency#graft’s all my joins to it. That object never actually sees any of the original joins, and so the alias tracker hands out the default table name instead of the aliased table name. I don’t know how to deal with this without hacking up more of the source than I want to - anyone have any ideas about how to deal with this? Or maybe a completely different approach?