Performanceprompt onlyIntermediate

Database Latency Reducer

An automated loop designed to systematically identify and resolve database performance bottlenecks to reduce query response times. This agent analyzes execution plans, optimizes slow queries, and applies indexing strategies while maintaining data integrity and safety.

← all loops
performancedatabaseoptimizationsqlquerylatencybenchmarkindexexecution-plan

Goal

Reduce database query response times to meet or exceed performance targets

How to Run

Execute the kickoff prompt in your coding environment to begin the automated database optimization process

  1. 01

    Set Up Environment

    Ensure access to database logs and performance monitoring tools

  2. 02

    Run Kickoff Prompt

    Paste the provided kickoff prompt into Cursor, Claude Code, Codex, OpenCode, or Gemini CLI

  3. 03

    Monitor Iterations

    Review agent suggestions each iteration and approve/deny changes as needed

  4. 04

    Verify Exit Condition

    Confirm latency benchmark meets target upon loop completion

Workflow Steps

  1. 01

    Analyze Current Performance

    Extract slow query logs and execution statistics to identify top latency contributors

  2. 02

    Identify Bottlenecks

    Examine query execution plans, missing indexes, and inefficient joins for each slow query

  3. 03

    Propose Optimizations

    Suggest improvements including index creation, query refactoring, and schema adjustments

  4. 04

    Implement Changes

    Apply non-destructive optimizations first, followed by schema or index modifications with safeguards

  5. 05

    Run Benchmark

    Execute the 'latency benchmark' command to measure improvement against baseline

  6. 06

    Evaluate Results

    Compare current latency against target; continue loop if under threshold or proceed to next iteration if not

Kickoff Prompt

Start the "Database Latency Reducer" loop.

Goal: Reduce database query response times to meet or exceed performance targets
Max iterations: 10
Between iterations run: latency benchmark
Exit when: Average query latency drops below the target threshold


Analyze the current database queries for performance bottlenecks. Execute the 'latency benchmark' command to establish a baseline. For the top 3 slowest queries, generate optimized versions and suggest index additions. Implement one change at a time and re-run benchmarks after each modification until average response time meets the target threshold.

Self-pace this loop. After each iteration, run `latency benchmark` and evaluate the output, and only continue if the exit condition is not met (Average query latency drops below the target threshold). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.

Guardrails

hardcoded
  • ·Always validate query syntax before execution
  • ·Preserve original data structure during optimization experiments
  • ·Test all changes in staging environment before production
  • ·Maintain full backup of database schema before applying indexes
  • ·Avoid destructive operations like DROP without explicit confirmation
  • ·Ensure rollback procedures exist for every proposed change
  • ·Profile queries to prevent resource exhaustion
  • ·Document all modifications with performance impact analysis

Flow Diagram

rendering…

Related loops — Performance