---
title: "Apply a fix | Grafana Labs"
description: "Match what you recorded to one of five fixes and apply it on your database. The path does not run SQL."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Apply a fix

To apply the fix that follows the diagnosis, match what you recorded to one of the fixes below.

1. Based on your diagnosis, use the following table to identify the appropriate fix. Each fix is described on [Improve slow queries](https://grafana.com/docs/grafana-cloud/observe-and-act/monitor-infrastructure/database-observability/optimize/improve-slow-queries/).
   
   Expand table
   
   | What you recorded                                                                                                          | Fix                                                                                        |
   |----------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
   | The filtered, joined, or sorted column has no **Indexed** badge, or the index column order doesn’t match                   | Add or modify an index that matches your filters, joins, and sort order                    |
   | The plan shows a table scan although an index exists, or the query wraps a column in a function such as `YEAR(created_at)` | Rewrite the query so the database can use the index, for example as a date range           |
   | **Calls** is high and the samples show many short, near-identical executions                                               | Batch the N+1 pattern into one query with `IN` or a join                                   |
   | The wait events breakdown is dominated by lock waits                                                                       | Reduce lock time: shorter transactions, consistent lock order, appropriate isolation level |
   | The wait events breakdown is dominated by I/O waits                                                                        | Reduce data scanned: add indexes, increase cache memory, review storage throughput         |
   
   Select an AI assistant button (for example, **Explain this query**) on any Query details tab for a suggestion, and validate it against your explain plan and query samples before applying it.
   
   Apply the fix on your database, then continue to compare the result.

You chose the fix that matches your diagnosis and applied it on your database.
