tpetry / laravel-mysql-explain
获取 Laravel 的可视化 MySQL EXPLAIN。
1.3.2
2024-09-13 11:00 UTC
Requires
- php: ^8.0
- ext-pdo: *
- guzzlehttp/guzzle: ^6.0|^7.0
- illuminate/contracts: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.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
使用 EXPLAIN 命令进行 MySQL 查询优化是不必要的复杂:输出包含大量难以理解或完全误导的信息。
此 Laravel 包收集了许多查询度量标准,这些度量标准将被发送到 mysqlexplain.com 并转换为更易于理解的形式。
安装
您可以通过 composer 安装此包
composer require tpetry/laravel-mysql-explain
用法
查询构建器
为非常容易提交查询计划,查询构建器已增加了三个新方法
// $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();
原始查询
在某些情况下,您正在执行原始 SQL 查询而不使用查询构建器。您可以使用 MysqlExplain
门面来获取它们的 EXPLAIN URL
use Tpetry\MysqlExplain\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'], );
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
鸣谢
许可
MIT 许可证(MIT)。请参阅 许可文件 了解更多信息。