Download the PHP package verbanent/laravel-sql-performance-guard without Composer
On this page you can find all versions of the php package verbanent/laravel-sql-performance-guard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download verbanent/laravel-sql-performance-guard
More information about verbanent/laravel-sql-performance-guard
Files in verbanent/laravel-sql-performance-guard
Package laravel-sql-performance-guard
Short Description Check SQL performance
License MIT
Homepage https://github.com/verbanent/laravel-sql-performance-guard
Informations about the package laravel-sql-performance-guard
Laravel SQL Performance Guard
A service provider to monitor SQL statements, check the performance (EXPLAIN command), view real-time queries, and collect SQL logs to optimise them.
Installation
Please install the package via Composer:
You can publish the config file if you need to change its default values:
Default settings:
Usage
Currently, the library works only in the debug mode. Please run it in your development environment to test SQL queries and make required amends to improve the SQL performance. If you see better results, apply these changes to your Production environment.
Example
Install a package and check your logs:
Change your application mode to DEBUG
by updating your .env
file:
It's just an example. If you configured your logs you might not need to do any changes here.
Open a page or run a CLI command to trigger saving debug logs. You should something like this:
We see the problem is that the query doesn't use any indexes (keys) to filter results. It means it must go through more than 80.000 rows to get the results.
Based on this knowledge let's optimise our table users
by adding an index:
It's better know:
But still not perfect. There's the last warning related to the key length. It means that the column contains longer strings and our index might be huge if we don't limit it. Let's try to fix it based on that information:
The results show all tests passed:
This is a simple tool to help you diagnose the issue with your queries based on the EXPLAIN
command. It should be used during your developing process. We don't recommend running it in your Production environment.