What this is?

This is a gem that can be used for comparing reports generated by excellent sql_tracker gem for different branches. It can be useful for detecting SQL queries regressions or optimisation opportunities.

Setup

Simply run the following in terminal while in the repo directory (temporary solution while not in rubygems.org)

gem build sql_reporter.gemspec
gem install sql_reporter

or if you are using Bundler

bundle

Usage

sql_reporter original_branch.json improved_branch.json

The above will generate a comparison.log file with content akin to:

SQL Count Decreases between samples/master.json -> samples/637.json
##########################################################

Queries killed: 0

Duration decrease[ms]: 0.0

SQL Count Increases between samples/master.json -> samples/637.json
##########################################################

Queries killed: 0

Duration decrease[ms]: 0.0

SQL Spawned between samples/master.json -> samples/637.json
##########################################################
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------+-------------------------------------+
|Query                                                                                                                                                                                                                                 |Count difference             |Duration difference [ms]             |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------+-------------------------------------+
|SELECT `apples`.* FROM `apples` WHERE `apples`.`apple_id` = xxx AND `apples`.`locale` = xxx AND `appler`.`apple_type` IN (xxx)             |0 -> 1                       |0.0 -> 1.76                          |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------+-------------------------------------+
Queries spawned: 1

Duration gain[ms]: 1.76

SQL Gone between samples/master.json -> samples/637.json
##########################################################
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------------------+
|Query                                                                                                                                                                                                                                                                   |Count diff