mysql-problem-solver
Skill10 starsChanged 4 months agoMITView on GitHub
Use when analyze real MySQL query and schema problems using code
- Reads credentials
In this repository62 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- analyze-problemSkill
- api-reviewSkill
- article-writingSkill
- assignment-compliance-checkSkill
- automation-audit-opsSkill
- autonomous-loopsSkill
- benchmark-optimization-loopSkill
- benchmarkSkill
- blueprintSkill
- class-refactoringSkill
- cleanup-local-branchesSkill
- codebase-simplification-auditSkill
- code-review-bugsnagSkill
- code-review-githubSkill
- code-review-jiraSkill
- code-reviewSkill
- composer-updateSkill
- create-issues-from-textSkill
- create-issueSkill
- create-missing-tests-in-prSkill
- create-testSkill
- design-systemSkill
- docker-patternsSkill
- e2e-testingSkill
- frontend-a11ySkill
- frontend-design-directionSkill
- frontend-patternsSkill
- frontend-slidesSkill
- git-workflowSkill
- laravel-authorization-reviewSkill
- laravel-securitySkill
- laravel-telescopeSkill
- latency-critical-systemsSkill
- merge-github-prSkill
- mysql-patternsSkill
- penetration-testerSkill
- postgres-patternsSkill
- prepare-issue-contextSkill
- process-code-reviewSkill
- product-capabilitySkill
- production-auditSkill
- pr-staged-merge-planSkill
- pr-summarySkill
- record-project-memorySkill
- redis-patternsSkill
- refactor-entry-point-to-actionSkill
- refresh-claude-mdSkill
- resolve-issueSkill
- rewrite-tests-pestSkill
- security-bounty-hunterSkill
- security-reviewSkill
- security-threat-analysisSkill
- seoSkill
- skill-creatorSkill
- slack-messagingSkill
- smartest-project-additionSkill
- test-driven-developmentSkill
- tester-cookbookSkill
- test-like-humanSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 10 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
If the current project uses Laravel, also apply @rules/laravel/laravel.mdc, @rules/laravel/architecture.mdc, @rules/laravel/filament.mdc, …
- Distinctive: line 25
Prefer investigation over assumptions
- Distinctive: line 26
Do not invent schema, indexes, or runtime behavior
- Distinctive: line 27
Do not recommend index changes without explaining why they help
- Distinctive: line 29
If DB access is unavailable, continue with static analysis and state the limitation clearly
- Very specific: line 45
If MySQL access is available, run EXPLAIN
- Very specific: line 72
Before recommending any rewrite, capture the baseline of the original query (EXPLAIN / EXPLAIN ANALYZE — type, key, rows, filtered, Extra, …
- Distinctive: line 109
When the input is Laravel code, also inspect:
- Distinctive: line 118
When terminal access is available, inspect DB connection details from:
- Distinctive: line 123
Use MySQL tools when possible for:
- Distinctive: line 128
If access fails, continue statically and say so.
- Very specific: line 132
Use the template defined in templates/analysis-report.md.
- Distinctive: line 138
Prefer evidence from EXPLAIN over assumptions
- Distinctive: line 140
Avoid unnecessary or duplicate indexes
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MySQL Problem Solver
Purpose
Investigate real MySQL performance or query design problems in existing applications.
Focus on:
- the actual query
- real schema and index usage
- EXPLAIN-based diagnosis when possible
- safe, justified optimizations
Constraints
- Apply @rules/sql.mdc
- If the current project uses Laravel, also apply
@rules/laravel/laravel.mdc,@rules/laravel/architecture.mdc,@rules/laravel/filament.mdc, and@rules/laravel/livewire.mdc - Be practical and direct
- Prefer investigation over assumptions
- Do not invent schema, indexes, or runtime behavior
- Do not recommend index changes without explaining why they help
- Apply
@rules/sql/optimalize.mdc"Performance Non-Regression on Query Changes" — every proposed query rewrite must be at least as fast as the original (ideally faster); a proposal that is slower must carry the documented reason and the remaining optimization options - If DB access is unavailable, continue with static analysis and state the limitation clearly
Execution
1. Identify the Query
- Find the actual SQL or reconstruct it from Laravel/Eloquent/query builder code
- Include filters, joins, ordering, grouping, pagination, and subqueries
2. Inspect Schema
- Inspect relevant tables and indexes using:
- schema output
- migrations
- model relationships
- DB tools when available
3. Run EXPLAIN
- If MySQL access is available, run
EXPLAIN - Review:
- table
- type
- possible_keys
- key
- rows
- filtered
- Extra
4. Diagnose the Problem
Look for:
- full scans
- weak join strategy
- existing index bypassed — query could hit a covering index already in the schema but the column order, a wrapping function, or extra projected columns prevent it. Preferred fix is a query rewrite (column re-ordering, SARGable rewrite, covering projection), not a new index (see
@rules/sql/optimalize.mdc"Reuse existing indexes first"). - missing or ineffective indexes
- non-SARGable filters
- poor sort/group plans
- offset pagination on large datasets
- N+1 behavior from application code
- per-row queries inside loops — per-row
update()/create()/delete()or single-row reads driven by aforeach(distinct from N+1 eager-loading: this is application code intentionally writing or reading row-by-row when a single batch query would suffice) - redundant or overlapping indexes
- charset / collation mismatch between compared or joined columns — the implicit conversion makes the converted side non-SARGable (its index is skipped), and an
asciicolumn compared against a non-ASCII value raisesERROR 1267instead of returning no rows - schema-level causes of a slow plan (see
@rules/sql/optimalize.mdc"Schema Design"): an oversized primary key copied into every secondary index, an unjustifiedVARCHAR(255)inflating sort buffers and temporary tables,TIMESTAMPcolumns converting per row by session time zone, orFLOAT/DOUBLEwhereDECIMALbelongs
5. Propose Optimizations
Before recommending any rewrite, capture the baseline of the original query (EXPLAIN / EXPLAIN ANALYZE — type, key, rows, filtered, Extra, measured latency when DB access is available). Every proposal must then be held against that baseline per @rules/sql/optimalize.mdc "Performance Non-Regression on Query Changes":
- The rewritten query must be equal or better on rows examined, access
type, index usage,filesort/temporaryavoidance, and latency. - If a proposal is unavoidably slower than the original (e.g. a correctness fix that widens the row set), do not present it as a clean win — state why it is slower, list the remaining optimization options (or state that none exist and why), and the trade-off that justifies it.
Recommend only justified changes, such as:
- query rewrite to reuse an existing schema index (preferred — verify which indexes already exist via migrations /
SHOW INDEXbefore proposing a new one; reorderWHERE/JOIN/ORDER BYcolumns to match an existing composite index, drop functions wrapping indexed columns, and project only columns the index already covers) - query rewrite (general)
- Eloquent/query builder rewrite
- eager loading change
- pagination change
- batching per-row loops into a single bulk operation — ModelManager batch methods (
batchUpdate,batchInsert),whereIn(...)->delete()for deletes, or one bulk read keyed in memory for lookups (see@rules/sql/optimalize.mdc"Batch over per-row operations") - index addition or replacement (only when the existing schema cannot cover the query and EXPLAIN confirms the gap after the rewrite alternative has been ruled out)
- redundant index removal
- column type / charset / collation alignment when the mismatch is what blocks the index (
@rules/sql/optimalize.mdc"Schema Design") - splitting one query into smaller ones
Explain trade-offs:
- write overhead
- duplicate indexes
- over-indexing
- complexity vs benefit
6. Assess Deployment Safety of Schema Changes
Run this step whenever the input includes DDL — a migration file, Schema::create / Schema::table / Schema::drop* / Schema::rename*, a DB::statement carrying DDL, or raw ALTER TABLE / CREATE INDEX. A statement that is instant on an empty dev database can lock a populated production table, break the release still serving traffic, or fail halfway with no way back, so judge every statement against @rules/sql/optimalize.mdc Deployment Safety of Schema Changes:
- destructive change (column / table drop or rename, narrowed type, tightened
ENUM) shipped in the same release as the code that reads the old surface — propose the expand / contract split - blocking DDL: the change can only run as
ALGORITHM=COPY, or an index build states no algorithm / lock mode — propose the explicitALGORITHM=INSTANT/ALGORITHM=INPLACE, LOCK=NONEstatement, or thept-online-schema-change/gh-ostcommand down()missing, empty, or not restoring the prior structure, and structure changes with noSchema::has*()guard to survive a replay after a failed deploy- a data backfill inside the migration — propose the DDL-only migration plus a chunked, resumable, idempotent command / queued job
- a new
NOT NULL/UNIQUE/CHECK/ foreign key on a populated table with no pre-flight — propose the counting query that finds the violating rows, then remediation, then the constraint - a foreign key or a newly queried column with no backing index shipped in the same release — propose the exact index DDL
Report each one as a finding with its concrete artifact, the same way step 5 reports an optimization.
Laravel-Specific Checks
When the input is Laravel code, also inspect:
with()/ eager loadingwhereHas()/ nested filterswithCount()chunk()vscursor()vs pagination- scopes hiding query complexity
- repeated queries in loops
Terminal Guidance
When terminal access is available, inspect DB connection details from:
.envconfig/database.php- docker/dev setup
Use MySQL tools when possible for:
SHOW CREATE TABLESHOW INDEXEXPLAIN
If access fails, continue statically and say so.
Output Format
Use the template defined in templates/analysis-report.md.
Principles
- Focus on the real bottleneck, not generic SQL advice
- Prefer evidence from EXPLAIN over assumptions
- Validate schema and index usage before proposing changes
- Avoid unnecessary or duplicate indexes
- Explain trade-offs (read vs write cost, complexity vs benefit)
- Be concise, practical, and explicit about limitations
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

