Simple But Effective Ways To Improve Active Record Query Performance — Eager Loading With `includes` to Avoid n+1 Queries Use includes to avoid n+1 queries. For example, if there are n rows in the users table, the following ActiveRecord code would generate n+1 queries: However, using includes will only run 2 queries. One to load all the users, and another to load all posts associated with those users.