tpetry / laravel-mysql-explain
Get Visual MySQL EXPLAIN for Laravel.
Installs: 73 031
Dependents: 0
Suggesters: 0
Security: 0
Stars: 242
Watchers: 2
Forks: 7
Open Issues: 0
Requires
- php: ^8.0
- ext-pdo: *
- guzzlehttp/guzzle: ^7.0
- illuminate/contracts: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- tpetry/php-mysql-explain: ^1.0
Requires (Dev)
- mockery/mockery: ^1.6
- nunomaduro/collision: ^3.1|^4.0|^5.0|^6.0|^7.0|^8.0
- nunomaduro/larastan: ^1.0|^2.0
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
MySQL Query optimization with the EXPLAIN
command is unnecessarily complicated: The output contains a lot of cryptic information that is incomprehensible or entirely misleading.
This Laravel package collects many query metrics that will be sent to mysqlexplain.com and transformed to be much easier to understand.
Installation
You can install the package via composer:
composer require tpetry/laravel-mysql-explain
Usage
Query Builder
Three new methods have been added to the query builder for very easy submission of query plans:
// $url will be e.g. https://mysqlexplain.com/explain/01j2gcrbsjet9r8rav114vgfsy $url = Film::where('description', 'like', '%astronaut%') ->visualExplain(); // URL to EXPLAIN will be printed to screen $users = Film::where('description', 'like', '%astronaut%') ->dumpVisualExplain() ->get(); // URL to EXPLAIN will be printed to screen & execution is stopped Film::where('description', 'like', '%astronaut%') ->ddVisualExplain();
Raw Queries
In some cases you are executing raw SQL queries and don't use the query builder. You can use the MysqlExplain
facade to get the EXPLAIN url for them:
use Tpetry\LaravelMysqlExplain\Facades\MysqlExplain; // $url will be e.g. https://mysqlexplain.com/explain/01j2gctgtheyva7a7mhpv8azje $url = MysqlExplain::submitQuery( DB::connection('mysql'), 'SELECT * FROM actor WHERE first_name = ?', ['PENEL\'OPE'], );
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.