Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lychee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@ jobs:
else
echo "Failing based on first run results"
exit ${{ steps.lychee.outputs.exit_code }}
fi
fi
2 changes: 1 addition & 1 deletion apps/docs/content/docs.v6/accelerate/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ If VS Code does not recognize the `$extends` method, refer to [this section](/v6

Since [extensions are applied one after another](/v6/orm/prisma-client/client-extensions#conflicts-in-combined-extensions), make sure you apply them in the correct order. Extensions cannot share behavior and the last extension applied takes precedence.

If you are using [Prisma Optimize](/v6/optimize) in your application, make sure you apply it _before_ the Accelerate extension. For example:
If you are using [Query Insights](/query-insights) in your application, make sure you apply it _before_ the Accelerate extension. For example:

```ts
const prisma = new PrismaClient({
Expand Down
1 change: 0 additions & 1 deletion apps/docs/content/docs.v6/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"orm",
"postgres",
"accelerate",
"optimize",
"guides",
"platform",
"ai"
Expand Down
9 changes: 0 additions & 9 deletions apps/docs/content/docs.v6/optimize/faq.mdx

This file was deleted.

103 changes: 0 additions & 103 deletions apps/docs/content/docs.v6/optimize/getting-started.mdx

This file was deleted.

33 changes: 0 additions & 33 deletions apps/docs/content/docs.v6/optimize/index.mdx

This file was deleted.

53 changes: 0 additions & 53 deletions apps/docs/content/docs.v6/optimize/known-limitations.mdx

This file was deleted.

14 changes: 0 additions & 14 deletions apps/docs/content/docs.v6/optimize/meta.json

This file was deleted.

11 changes: 0 additions & 11 deletions apps/docs/content/docs.v6/optimize/performance-metrics.mdx

This file was deleted.

9 changes: 0 additions & 9 deletions apps/docs/content/docs.v6/optimize/prisma-ai.mdx

This file was deleted.

26 changes: 0 additions & 26 deletions apps/docs/content/docs.v6/optimize/recommendations.mdx

This file was deleted.

11 changes: 0 additions & 11 deletions apps/docs/content/docs.v6/optimize/recordings.mdx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
---
title: Query optimization using Prisma Optimize
description: How Prisma optimizes queries under the hood
title: Query optimization
description: How to identify and optimize query performance with Prisma
url: /v6/orm/prisma-client/queries/query-optimization-performance
metaTitle: Query optimization using Prisma Optimize
metaDescription: How Prisma optimizes queries under the hood
metaTitle: Query optimization
metaDescription: How to identify and optimize query performance with Prisma
---

This guide shows how to identify and optimize query performance, debug performance issues, and address common challenges.
This guide covers identifying and optimizing query performance with Prisma.

## Query Insights

[Query Insights](/query-insights) is built into Prisma Postgres and shows you which queries are slow, how expensive they are, and what to fix. It works out of the box for raw SQL, but to see Prisma ORM operations (model name, action, query shape) you need one extra step.

### Enabling Prisma ORM attribution

Install `@prisma/sqlcommenter-query-insights`:

```bash
npm install @prisma/sqlcommenter-query-insights
```

Then pass it to the `comments` option in your `PrismaClient` constructor:

```ts
import { prismaQueryInsights } from "@prisma/sqlcommenter-query-insights";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient({
adapter: myAdapter, // driver adapter or Accelerate URL required
comments: [prismaQueryInsights()],
});
```

This adds a SQL comment to every query containing the model, action, and parameterized query shape. Query Insights uses these annotations to trace SQL back to the exact Prisma call that generated it — even when a single Prisma call produces multiple SQL statements.

#### Let your AI agent handle setup

Copy this prompt into your AI coding assistant:

```
Install and configure @prisma/sqlcommenter-query-insights in my project so I can
see Prisma ORM queries in Query Insights. Docs: https://www.prisma.io/docs/query-insights
```

## Debugging performance issues

Expand All @@ -17,26 +52,7 @@ Several common practices can lead to slow queries and performance problems, such
- Not caching repeated queries
- Performing full table scans

:::info

For more potential causes of performance issues, visit [this page](/v6/optimize/recommendations).

:::

[Prisma Optimize](/v6/optimize) offers [recommendations](/v6/optimize/recommendations) to identify and address the inefficiencies listed above and more, helping to improve query performance.

To get started, follow the [integration guide](/v6/optimize/getting-started) and add Prisma Optimize to your project to begin diagnosing slow queries.

<div class="videoWrapper">
<iframe
width="660"
height="315"
src="https://www.youtube.com/embed/gWROOjjEiM0"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</div>
Use [Query Insights](/query-insights) to identify which queries are affected and what to change.

:::tip

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const postsWithAuthorsAndProfiles = await prisma.post.findFirst({

:::note

Be careful when deeply nesting relations because the underlying database query may become slow due it needing to access a lot of different tables. To ensure your queries always have optimal speed, consider adding a caching layer with [Prisma Accelerate](/v6/accelerate) or use [Prisma Optimize](/v6/optimize) to get query insights and recommendations for performance optimizations.
Be careful when deeply nesting relations because the underlying database query may become slow due to it needing to access a lot of different tables. To ensure your queries always have optimal speed, consider adding a caching layer with [Prisma Accelerate](/v6/accelerate) or use [Query Insights](/postgres/database/query-insights) to identify slow queries and optimize performance.

:::

Expand Down
Loading
Loading