The project is in a healthy, maintained state
A Ruby on Rails gem that analyzes SQL queries and suggests optimizations like missing indexes, inefficient sorts, and risky joins.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.4
~> 3.13

Runtime

>= 6.0, < 8.0
>= 6.0, < 8.0
~> 1.4
~> 0.8.0
>= 6.0, < 8.0
 Project Readme

SqlQueryAnalyzer

Gem Version Code Coverage Branch Coverage

Analyze your ActiveRecord queries easily with EXPLAIN and smart optimization suggestions. 🚀

✅ Supports Rails 6.0+ through Rails 7.1+


Compatibility

Rails Version Ruby Version Status
6.0.x 3.0+ ✅ Fully Supported
6.1.x 3.0+ ✅ Fully Supported
7.0.x 3.0+ ✅ Fully Supported
7.1.x 3.1+ ✅ Fully Supported

Installation

Add this line to your Gemfile:

gem 'sql_query_analyzer'

And then execute:

bundle install

Or install it manually:

gem install sql_query_analyzer

Need to create a new file in the config/initializers/sql_query_analyzer.rb

Usage

In your Rails console or app:

User.where(active: true).explain_with_suggestions

✅ You will get:

  • Full EXPLAIN ANALYZE plan

  • Smart suggestions like:

    • Missing JOIN conditions
    • Sorting without indexes
    • High row scan warnings

Why Use This Gem?

  • Save time analyzing slow queries
  • Instant smart hints
  • Improve database performance faster
  • Beginner-friendly explanations

Example Output

=== EXPLAIN ANALYZE OUTPUT ===
Seq Scan on users ...

=== SUGGESTIONS ===
[CRITICAL] âš¡ Sequential Scan detected. Consider adding indexes.
[WARNING] 🚨 Query uses SELECT *. Select only needed columns.

Example Output using dummy queries

Here is an example of the output response from the Gem:

Query Response

Code Coverage

The project maintains high test coverage to ensure reliability:

  • Line Coverage: 99.4% (167/168 lines)
  • Branch Coverage: 80.7% (46/57 branches)

Coverage is measured using SimpleCov and is checked on every pull request.

Roadmap

For a detailed roadmap, visit our GitHub Pages roadmap.