> ## Documentation Index
> Fetch the complete documentation index at: https://codspeed.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Database Instrument Overview

> The database instruments measure the performance of database queries directly in the CI

export const MongoDBIcon = props => <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" viewBox="0 0 31 31" width={31} height={31} fill="none" {...props}>
    <g clipPath="url(#a)">
      <path fill="#599636" d="m15.1.937.778 1.463c.175.27.365.509.589.731a20.436 20.436 0 0 1 1.828 2.067c1.32 1.733 2.21 3.658 2.846 5.74.38 1.271.588 2.575.603 3.894.064 3.944-1.288 7.33-4.013 10.143-.445.446-.921.858-1.432 1.225-.27 0-.398-.207-.51-.398a3.271 3.271 0 0 1-.397-1.145c-.096-.477-.159-.954-.127-1.447v-.222c-.022-.047-.26-21.94-.166-22.051Z" />
      <path fill="#6CAC48" d="M15.1.888c-.033-.064-.065-.015-.096.016.015.319-.096.604-.27.875-.192.27-.446.477-.7.7-1.414 1.224-2.527 2.703-3.418 4.357-1.186 2.225-1.797 4.61-1.97 7.122-.08.905.286 4.102.572 5.024.779 2.448 2.178 4.5 3.99 6.28.445.429.922.826 1.414 1.209.143 0 .159-.128.192-.223.063-.203.11-.41.143-.62l.32-2.385L15.098.888Z" />
      <path fill="#C2BFBF" d="M15.877 27.168c.032-.364.207-.667.398-.97-.192-.079-.334-.236-.445-.412a2.955 2.955 0 0 1-.238-.525c-.222-.668-.27-1.368-.333-2.05v-.414c-.08.064-.096.604-.096.684a15.844 15.844 0 0 1-.287 2.147c-.047.286-.079.572-.255.826 0 .032 0 .064.016.111.286.843.364 1.702.413 2.576v.32c0 .381-.016.3.3.428.129.048.27.064.399.16.095 0 .11-.08.11-.144l-.047-.525v-1.463c-.015-.255.032-.509.064-.748h.001Z" />
    </g>
    <defs>
      <clipPath id="a">
        <rect width={30.271} height={30.271} x={0.054} y={0.316} fill="#fff" rx={3.784} />
      </clipPath>
    </defs>
  </svg>;

The database instruments allow measuring the performance of **database queries**
directly in the CI. For each benchmark, information about the database queries
is displayed in the CodSpeed dashboard. The following performance issues can be
detected:

* **Un-optimized queries**: queries that are not using indexes or are not using
  them efficiently
* **N+1 queries**: queries that are executed multiple times for each item in a
  list instead of using a single query (*coming soon*)

<Frame caption="Example of a benchmark with an un-optimized MongoDB query">
  <img src="https://mintcdn.com/codspeed/_9gjNuBHMdsdxHot/instruments/databases/assets/unoptimized-query.png?fit=max&auto=format&n=_9gjNuBHMdsdxHot&q=85&s=53997d2e05e9a7def5eba52ff6dee1ad" className="rounded-xl w-full max-w-lg mx-auto" alt="Example of a benchmark with an un-optimized MongoDB query" width="1371" height="1152" data-path="instruments/databases/assets/unoptimized-query.png" />
</Frame>

The following benefits can be expected from using the database instruments:

* Full visibility on the performance of your database queries, **directly in the
  CI**
* **Detect and fix problematic queries** before they are deployed to production

## How it works

When enabled, the CodSpeed Action will automatically spawn a proxy server that
will intercept all database queries. Each query will be executed against a real
database and the response sent back to the application.

<img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/instruments/databases/assets/proxy.dark.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=a51f53169d944f725ad1a0dcb171a37f" className="rounded-xl w-full max-w-lg mx-auto" alt="Databases Instruments architecture" width="1759" height="758" data-path="instruments/databases/assets/proxy.dark.png" />

For each query, the CodSpeed proxy will communicate with the real database to
gather the **explain plan** and other metrics about it. When the run is
finished, the data is sent to CodSpeed where it is processed.

## Supported Databases

<Columns cols={2}>
  <Card horizontal title="MongoDB" href="/instruments/databases/mongodb" icon={<MongoDBIcon />} />
</Columns>

<Info>
  If there is another database you would like to see supported, please reach out
  to us via [Discord](https://discord.gg/MxpaCfKSqF) or
  [email out support](mailto:contact@codspeed.io).
</Info>
