GitLab Well Architected
Cookbook navigation
Prompts / Optimize Database Queries

Optimize Database Queries

PerformanceDatabaseDeveloperMonitorBeginner

Optimize slow queries with index suggestions and query rewrites. Improve database performance.

For GitLab Duo

prompt

Optimize this slow query:

[PASTE SQL QUERY]

Execution plan:
[PASTE EXPLAIN OUTPUT]

Optimize for:
1. Query speed
2. Index usage
3. Join efficiency
4. Maintainability
5. Provide explain plan

Use the prompt

Share the query plan, table definitions, and database version. Data size and distribution matter when deciding whether an index or rewrite will improve the query.