Rails joins vs includes — The Difference That Kills Performance
joins filters using SQL JOIN. includes prevents N+1 by eager loading. Using the wrong one creates hidden performance problems. Rails 7/8 with SQL output.
Deep dives into SQL JOIN behavior and how it maps to Rails associations, including LEFT JOIN pitfalls, join conditions, and unexpected query results.
joins filters using SQL JOIN. includes prevents N+1 by eager loading. Using the wrong one creates hidden performance problems. Rails 7/8 with SQL output.
where returns a relation, find_by returns one record or nil. Here's when each is correct, what breaks if you pick wrong, and Rails 7/8 production patterns.
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.
posts.count hit the database on every request and brought down production. Here's how counter cache fixes it, what to watch for, and how to backfill safely.
I had SQL certification on my resume and failed a Rails interview. Knowing databases and knowing ActiveRecord are two different skills. Here's the gap.
I searched for SQL to ActiveRecord conversion so many times I finally built the tool myself. Here's what I learned about the patterns that repeat constantly.
SQL JOINs made sense. ActiveRecord's includes() confused me for weeks. Here's the mental model that finally made it click and when to use each.
The complete ActiveRecord query interface for Rails 7 and 8: where, joins, includes, select, group, order, limit, offset, and the SQL each generates.
Rails has no native FULL OUTER JOIN. Here are three working approaches: Arel, find_by_sql, and union of LEFT + RIGHT joins. With SQL output for each.
Seven ways to do a CROSS JOIN in Rails without blowing up in production. Covers Arel, raw SQL, CTEs, and the row-count pitfalls to know before you deploy.
Adding WHERE after LEFT JOIN in Rails silently converts it to INNER JOIN. Here's why it happens, how to spot it, and the fix with .merge() or subqueries.
Rails doesn't expose CROSS JOIN directly. Here's how to write one with Arel or find_by_sql, when it's the right tool, and when to avoid it in production.
Rails INNER JOIN with multiple ON conditions — without moving predicates into WHERE by accident. .merge(), Arel, and SQL verification. Rails 7/8, 2026.