Laravel Mysql Explain

tpetry/laravel-mysql-explain image

Laravel Mysql Explain stats

Downloads
13.8K
Stars
111
Open Issues
0
Forks
4

View on GitHub →

Get MySQL EXPLAIN plans that are understandable for humans

Laravel MySQL Explains For Humans

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 Larvel package collects many query metrics that will be sent to explainmysql.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:

Type Action
explainForHumans returns URL to processed EXPLAIN output
dumpExplainForHumans dumps URL to processed EXPLAIN output and continue normal execution
ddExplainForHumans dumps URL to processed EXPLAIN output and stops execution
// $url will be e.g. https://explainmysql.com/e/C0Omak70mLEXfok1a7Oo1n
$url = Film::where('description', 'like', '%astronaut%')
->explainForHumans();
 
// URL to EXPLAIN will be printed to screen
$users = Film::where('description', 'like', '%astronaut%')
->dumpExplainForHumans()
->get();
 
// URL to EXPLAIN will be printed to screen & execution is stopped
$users = Film::where('description', 'like', '%astronaut%')
->ddExplainForHumans()
->get();

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\MysqlExplain\Facades\MysqlExplain;
 
// $url will be e.g. https://explainmysql.com/e/H1pfKQ7FH3HnH87dS64Wk1
$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.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Tpetry Laravel Mysql Explain Related Articles

MySql Explain with Tobias Petry image

MySql Explain with Tobias Petry

Read article
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud