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.
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
- 01
Set Up Environment
Ensure access to database logs and performance monitoring tools
- 02
Run Kickoff Prompt
Paste the provided kickoff prompt into Cursor, Claude Code, Codex, OpenCode, or Gemini CLI
- 03
Monitor Iterations
Review agent suggestions each iteration and approve/deny changes as needed
- 04
Verify Exit Condition
Confirm latency benchmark meets target upon loop completion
Workflow Steps
- 01
Analyze Current Performance
Extract slow query logs and execution statistics to identify top latency contributors
- 02
Identify Bottlenecks
Examine query execution plans, missing indexes, and inefficient joins for each slow query
- 03
Propose Optimizations
Suggest improvements including index creation, query refactoring, and schema adjustments
- 04
Implement Changes
Apply non-destructive optimizations first, followed by schema or index modifications with safeguards
- 05
Run Benchmark
Execute the 'latency benchmark' command to measure improvement against baseline
- 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
Related loops — Performance
Performance
Bundle Size Reducer
Iteratively reduces JavaScript bundle size by analyzing dependencies, identifying large modules, and applying targeted optimizations until a specified size target is met.
Performance
Frontend Speed Optimizer
Automatically improves frontend page speed by iteratively analyzing Lighthouse reports and applying targeted optimizations. This loop runs until your target Lighthouse performance score is achieved.
Performance
Slow Endpoint Hunter
This loop identifies and optimizes slow API endpoints by continuously benchmarking, analyzing performance bottlenecks, and applying targeted improvements until response times meet predefined budgets.