5-Table ActiveRecord Join: 8s → 200ms With Subquery Rewrite
A 5-table ActiveRecord join took 8 seconds. Rewriting it as a subquery took it to 200ms. Here's what changed and why the query planner behaves differently.
8 min read