Database Optimizer (agent)

    by Laravel Company

    1

    Database Optimizer (agent): Database performance optimization with query tuning, indexing strategies, partitioning, and capacity planning

    $4

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    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

    ComponentCurrent StateOptimized StateImpact
    IndexNoneCREATE INDEX idx_orders_status_created_total ON orders (status, created_at, total DESC);High
    QueryFull Table ScanIndex Range Scan98% Latency reduction
    MemoryHigh Sort OverheadIndex-based SortingLowers 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 status column has low cardinality (e.g., 'shipped', 'pending', 'cancelled').
    • The total column 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 total column frequently updated? If so, index maintenance might slightly slow down UPDATE operations.

    Verification

    1. Run EXPLAIN ANALYZE on the query before and after index creation.
    2. Monitor the Sort_merge_passes status 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 status should 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

    1. Provide the skill with a slow query, a database schema, or a performance log.
    2. The agent identifies missing context and lists necessary assumptions regarding your environment.
    3. It generates an optimization plan following strict Laravel and PHP coding standards.
    4. 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    Read Files
    Write Files
    Listed8 days ago

    What's inside

    Frequently Asked Questions

    This skill is purpose-built for Laravel applications using MySQL or PostgreSQL. It specifically understands Eloquent ORM patterns, Laravel migration syntax, and common performance pitfalls like N+1 queries.

    No, the agent operates in a read-only advisory capacity. It provides optimized SQL, migration code, and architectural plans that you can review and apply manually to ensure full control over your production environment.

    To get the most accurate results, you should provide the relevant table schemas, the slow SQL or Eloquent query, and any existing indexes. The more context you provide about your data volume, the more specific the indexing and partitioning strategies will be.

    The skill provides a structured optimization report including the identified bottleneck, recommended SQL/Migration code, a rationale for the changes, and steps to verify the performance gain.

    Yes, the agent is designed to handle complex database structures, including multi-tenant architectures and high-volume logging tables. It can suggest advanced strategies like composite indexing and table partitioning specifically for these scenarios.

    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.