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](https://laravelnews.s3.amazonaws.com/images/wZkdPO2ovYhyzAW0mEs5RjTaTApBqId0iLzAoGJW.png)
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 stoppedFilm::where('description', 'like', '%astronaut%') ->ddVisualExplain(); // Submit raw queriesuse 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.