The MySQL Visual Explain tool by Tobias Petry helps users analyze slow queries by providing an easy-to-understand visual representation of MySQL’s EXPLAIN output. This tool enables you to decipher MySQL’s default, often cryptic EXPLAIN output, making it accessible even for those without deep database expertise, providing an excellent visualization of query performance:
MySQL Explain example visualization
The MySQL Visual Explain website has an accompanying API and an integration for laravel. The Laravel package adds methods to the query builder with various options such as automatically running a visual explain and providing a link, dumping the visual explain, or outputting the URL and stopping execution:
// $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();
// Submit raw queries
use Tpetry\MysqlExplain\Facades\MysqlExplain;
$url = MysqlExplain::submitQuery(
DB::connection('mysql'),
'SELECT * FROM actor WHERE first_name = ?',
['PENEL\'OPE'],
);
For more information, you can visit MySQL Visual Explain.
The post Visual EXPLAIN for MySQL and Laravel appeared first on Laravel News.
Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.