tpetry/laravel-mysql-explain
Adds EXPLAIN support to Laravel's MySQL query builder so you can inspect execution plans, spot missing indexes, and debug slow queries without leaving your app. Works with Eloquent and the query builder, with no extra tooling required.
Architecture fit. tpetry/laravel-mysql-explain is developer tooling, not runtime infrastructure. It wraps MySQL/MariaDB EXPLAIN (JSON/ANALYZE) output and renders it as a human-readable plan tree, exposed through an Artisan entry point and query-builder macros (->explain()). For a Laravel estate on MySQL, that is a natural, low-footprint fit: it is opt-in, changes no schemas, intercepts no production traffic, and lives entirely in the developer’s inner loop. It does not belong in request paths, job pipelines, or anything that runs unattended.
Integration feasibility. High. Composer install as a require-dev dependency, Laravel package auto-discovery, no config publish required, no migrations. It works against the existing Eloquent/Query Builder surface, so engineers can inspect the exact query the ORM emits rather than hand-copying SQL. The only hard prerequisites are a MySQL/MariaDB connection and a DB account permitted to run EXPLAIN (and EXPLAIN ANALYZE where used). It is MySQL/MariaDB only — it provides no value for Postgres/SQLite services.
Technical risk. Low to adopt, moderate to depend on:
EXPLAIN output shape differs across MySQL 5.7 / 8.x and MariaDB; format parsing is inherently version- and vendor-sensitive.EXPLAIN ANALYZE executes the statement (MySQL 8.0.18+). Pointed at a heavy query on a primary, this is a real availability risk, not a curiosity.Key questions.
EXPLAIN ANALYZE be permitted at all, and if so only against read replicas or local copies?require-dev, or are we implicitly relying on it during incident response where a dev dependency may not be installed?composer.json constraints against ours)?Stack fit. Best-in-class fit for Laravel monoliths and APIs backed by MySQL 8.x; acceptable for MariaDB with validation. Zero fit for polyglot estates standardized on Postgres. Install as a dev dependency only; keep it out of production images.
Migration path. There is nothing to migrate — this is additive tooling. Sequence: composer require --dev tpetry/laravel-mysql-explain, rely on auto-discovery, optionally publish config to pin defaults, and validate against a known query before announcing. No data backfill, no cutover, no rollback beyond composer remove.
Compatibility. Confirm three axes before rollout: (a) Laravel/PHP version constraints in the package composer.json; (b) MySQL 5.7 vs 8.x plan format, and MySQL 8.0.18+ for ANALYZE; (c) terminal/CI environment for ANSI rendering. Treat MariaDB as “test before trusting.”
Sequencing.
EXPLAIN FORMAT=JSON to confirm fidelity.EXPLAIN ANALYZE: allowed on local/replica only, never on primaries; document how to capture a safe copy.Maintenance. Near-zero day-to-day: composer updates and version pins. The real maintenance item is upstream risk management — track releases, and be prepared to fork or replace if the package lags a Laravel or MySQL upgrade. Budget a small recurring review, not a support rotation.
Support. Low. Engineers already understand EXPLAIN; the package mainly lowers the reading curve. The support burden is policy, not code: “where am I allowed to run this,” “why does the plan look different on replica vs primary,” “why did ANALYZE take 40 seconds.” A one-page internal guide resolves most of it.
Scaling. The tool itself does not scale — it is per-developer, per-terminal. The scaling concern is blast radius of EXPLAIN ANALYZE: on large tables or busy primaries it can consume real I/O and hold resources for the duration of the query. Governance (replica-only, statement timeouts, review of what gets analyzed) matters far more than the number of adopters. Per-service install overhead across many microservices is trivial but creates version drift; standardize via a shared dev image or template.
Failure modes.
EXPLAIN ANALYZE on production → latency spike or lock contention.Ramp-up. Hours, not days. A Laravel engineer with EXPLAIN familiarity is productive in under an hour; someone new to query plans gets more value from the visual tree than from raw JSON. Plan roughly half a day per squad including the internal guide and the ANALYZE policy briefing. The TPM’s job is to set the guardrails (dev-only, replica-only for ANALYZE, redaction) so the tool stays an accelerator rather than an incident source.
How can I help you explore Laravel packages today?