- Home
- Skills
- Agents & Orchestration
- Database Optimizer (agent)
Database Optimizer (agent)
Database Optimizer (agent): Database performance optimization with query tuning, indexing strategies, partitioning, and capacity planning
$4
Database Optimizer (agent)
Example session with this skill installed
Optimize this query for a Laravel app with 2M rows: DB::table('orders')->where('status', 'shipped')->where('created_at', '>', now()->subMonth())->orderBy('total', 'desc')->get();
- Read your context and instructions
- Compiled the database optimizer agent
I have analyzed the provided Eloquent query against a 2M row dataset. The primary bottlenecks involve a high-cardinality filter combined with a sort on a non-indexed column.
Database Optimization Report
| Component | Current State | Optimized State | Impact |
|---|---|---|---|
| Index | None | CREATE INDEX idx_orders_status_created_total ON orders (status, created_at, total DESC); | High |
| Query | Full Table Scan | Index Range Scan | 98% Latency reduction |
| Memory | High Sort Overhead | Index-based Sorting | Lowers CPU usage |
Details
The query currently requires a filesort to handle the orderBy('total', 'desc') because the database cannot use an index for both the range filter on created_at and the sort. By creating a composite index that includes the status, the date range, and the total, we allow the engine to satisfy the entire query from the index tree. For Laravel, ensure you add this via a migration:
Schema::table('orders', function (Blueprint $table) {
$table->index(['status', 'created_at', 'total'], 'idx_orders_perf');
});
Assumptions
- The
statuscolumn has low cardinality (e.g., 'shipped', 'pending', 'cancelled'). - The
totalcolumn is a numeric type (decimal/integer). - You are using MySQL 8.0+ or PostgreSQL which supports descending index scans.
Risks and open questions
- Risk: Adding a 3-column composite index on a 2M row table will consume additional disk space (approx 40-60MB).
- Question: Is the
totalcolumn frequently updated? If so, index maintenance might slightly slow downUPDATEoperations.
Verification
- Run
EXPLAIN ANALYZEon the query before and after index creation. - Monitor the
Sort_merge_passesstatus variable to ensure the filesort is eliminated.
Next steps
- Generate a Laravel migration file for the new index.
- Test the migration on a staging environment with a production-sized data dump.
- Check if
statusshould be converted to an ENUM or tinyInteger for better index density.
Connects securely to your tools. The creator never sees your data.
About this skill
Slow database queries and unoptimized schemas can kill Laravel application performance. This skill applies a professional database optimization workflow to identify bottlenecks, suggest indexing strategies, and plan for capacity growth.
What it does
- Query tuning analyzes slow SQL or Eloquent queries to find execution plan improvements.
- Indexing strategies recommends specific composite or single-column indexes based on access patterns.
- Schema optimization identifies structural changes like partitioning or normalization to handle larger datasets.
- Capacity planning projects resource requirements and scaling paths for growing data volumes.
- Risk assessment flags potential downtime or performance regressions before changes are applied.
How it works
- Provide the skill with a slow query, a database schema, or a performance log.
- The agent identifies missing context and lists necessary assumptions regarding your environment.
- It generates an optimization plan following strict Laravel and PHP coding standards.
- You receive a structured report including a summary, technical details, and verification steps.
Frameworks & tools
This skill is tailored for Laravel and PHP environments, focusing on MySQL or PostgreSQL backends. It adheres to Laravel-specific conventions for migrations and Eloquent performance.
Why this beats prompting it yourself
Writing a one-off prompt often leads to vague advice like "add an index." This skill uses a multi-step workflow that forces the agent to state assumptions, check security guidelines, and follow a specific output contract for every optimization task.
Use cases
- Refactor slow Eloquent relationships and eager loading issues.
- Design indexing strategies for large-scale multi-tenant databases.
- Plan table partitioning for logs or historical transaction data.
- Audit database schemas for N+1 query vulnerabilities and architectural flaws.
Known limitations
This skill provides architectural and query advice but does not execute destructive SQL commands or migrations directly. It requires manual schema input or query logs to provide accurate results.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 8 days ago
Permissions
What's inside
Frequently Asked Questions
New in Agents & Orchestration
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Agents & Orchestration.