DEV Community

loading...
Play Button Pause Button
AppLand

Find the N+1 Query Problem in Rails Apps in Under 5 Mins

appmapruby profile image AppMap Ruby ・1 min read

This video is based on the brilliant Eager Loading and the N+1 Query Problem blog post by Kevin Gilpin.

It is a short demonstration of how to identify the N+1 Query anti-pattern using the AppMap extension for VS Code, jq and the Rails Sample Application Sixth Edition as an example.

The N+1 anti-pattern happens when a query is executed for every result of a previous query. If left unchecked N+1 queries result in a gradual slowdown in the performance of an application.

N+1 Query Problem

Detecting  N+1 queries is tricky, because they are not revealed by any mainstream testing strategy.

To detect the N+1 query problems we need to look at the number of SQL queries that are performed in a realistic situation, such as an integration test, and compare this number with a “reasonable” expectation.

You can find full usage instructions, and all these links, on the AppMap page in the VSCode marketplace.

Thanks for watching!

Discussion (0)

pic
Editor guide