---
title: Bits Database Optimization
description: Review and implement database query optimizations identified by Bits AI.
breadcrumbs: Docs > Database Monitoring > Bits Database Optimization
---

# Bits Database Optimization

{% alert level="info" %}
Bits Database Optimization is only available for PostgreSQL. To request support for another database management system, contact your Datadog representative or [Datadog Support](https://docs.datadoghq.com/help/).
{% /alert %}

## Overview{% #overview %}

Bits Database Optimization detects underperforming queries across your database fleet, identifies optimizations validated against a simulated copy of your environment, and delivers the result as a pull request fixing the exact code that triggered the query.

Optimization candidates are selected automatically from Database Monitoring telemetry, with no additional setup required. Candidates are identified by highest potential impact, focusing on query execution times, blocking queries, and regressed queries.

{% alert level="info" %}
Bits Database Optimization does not require write access to your database, and does not export or use actual data from your environment. Optimizations are empirically tested against database simulations populated with synthetic data using statistical properties of your schema.
{% /alert %}

{% image
   source="https://docs.dd-static.net/images/database_monitoring/database_optimization_panel_overview.9c49a37fcb4ccc68c057064e3178685b.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/database_optimization_panel_overview.9c49a37fcb4ccc68c057064e3178685b.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="Am optimized query in the optimization panel, showing a detailed summary of the issue, a diff for the optimized query, and a button to create a PR." /%}

## Prerequisites{% #prerequisites %}

- **Database Monitoring** is configured for the target database instances. See [Database Monitoring Setup](https://docs.datadoghq.com/database_monitoring/architecture.md).
- **Schema collection** is enabled on the target instances.
- For automated PR creation:
  - **APM** must be configured for the services that issue the queries you want to address. See [Correlate Database Monitoring and Traces](https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm.md) for more information.
  - A **GitHub repository** must be linked in your Datadog organization.

## Viewing optimizations{% #viewing-optimizations %}

### Query list{% #query-list %}

On the [Database Monitoring > Queries](https://app.datadoghq.com/databases/queries) screen, queries with optimizations available have an AI icon in the Status column. Hover over an icon to see a summary of the optimization, and click the icon to open the Optimization panel.

To filter the query list by optimization type, select an option from **Optimizations** above the list.

{% image
   source="https://docs.dd-static.net/images/database_monitoring/database_optimization_queries.c7e97464033834004738dfbc89738d25.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/database_optimization_queries.c7e97464033834004738dfbc89738d25.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="The status column on the Queries screen, showing AI icons in query rows where optimizations are available." /%}

### Optimization panel{% #optimization-panel %}

The Optimization panel includes a summary of the query issue, the optimized query used in the simulation, and a visualization of the Simulated Performance Impact.

Explore the Simulated Performance Impact visualization for more details about improvements:

- Hover over the improvement summary (for example, "96.9x faster") to view before-and-after execution times, logical reads, and shared blocks dirtied. The table shows the average, median, P95, and maximum for each metric.
- Hover over each item in the visualization to view more details.

{% image
   source="https://docs.dd-static.net/images/database_monitoring/database_optimization_simulated_performance_impact.1926b0f5066c1cf8a6abd230855d1f05.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/database_optimization_simulated_performance_impact.1926b0f5066c1cf8a6abd230855d1f05.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="An example Simulated Performance Impact visualization, showing a query optimized to 96.9x faster." /%}

Click **Compare Plans** to view side-by-side comparisons of the current and optimized execution plans:

- **List View** shows a hierarchical list of the execution plan's operations, with node cost and row estimates for each step.
- **Map View** shows a visual representation of the execution plan, with the option to compare the plans by different metrics.
- **Raw** shows the raw execution plan output.

{% image
   source="https://docs.dd-static.net/images/database_monitoring/database_optimization_plan_comparison_map_view.be5867052810ad06af6d388d44bed069.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/database_optimization_plan_comparison_map_view.be5867052810ad06af6d388d44bed069.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="The Compare Plans Map View, showing added and removed operations for an optimized query." /%}

### Review the pull request{% #review-the-pull-request %}

To review the PR for the optimization fix to your database, select **Review PR by Bits AI**. The GitHub PR opens with a pre-populated description that includes the simulation results.

{% alert level="info" %}
Automated pull requests require APM to be configured for the service issuing the query, and a GitHub repository linked to your Datadog organization.
{% /alert %}

## Further reading{% #further-reading %}

- [Database Monitoring](https://docs.datadoghq.com/database_monitoring.md)
- [Exploring Query Metrics](https://docs.datadoghq.com/database_monitoring/query_metrics.md)
- [Correlate Database Monitoring and Traces](https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm.md)
