Skip to content

Commit

Permalink
feat: add more sections to optmize docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-arch committed Jul 25, 2024
1 parent 49fd29e commit 0408abe
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 61 deletions.
3 changes: 2 additions & 1 deletion cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"Nikolas",
"Supavisor",
"inshellisense",
"janedoe"
"janedoe",
"unindexed"
],
"patterns": [
{
Expand Down
17 changes: 10 additions & 7 deletions content/700-optimize/100-what-is-optimize.mdx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
title: 'What is Optimize'
metaTitle: 'What is Optimize'
metaDescription: 'Learn about Optimize, a tool that generates insights and recommendations that can be used to make your database queries faster.'
metaDescription: 'Learn about Optimize, a tool that generates insights and recommendations to make your database queries faster.'
tocDepth: 3
toc: true
---

<TopBlock>
[Optimize](https://www.prisma.io/data-platform/optimize) helps you generate insights about your queries and provides recommendations that can be used to make your database queries faster.

Its main features are:
[Optimize](https://www.prisma.io/data-platform/optimize) is a tool designed to generate insights, help you debug database queries, and provide recommendations to make your queries faster.

- Generating insights about your database queries
- Providing recommendations to improve your database queries
Key features include:

The goal of Optimize is to help developers of all skill-levels to be able to write performant database queries so that database load is reduced and apps are more responsive.
</TopBlock>
- Generating insights about your database queries
- Identifying errors to help debug your database queries
- Providing recommendations to improve query performance

Optimize aims to help developers of all skill levels write efficient database queries, reducing database load and making applications more responsive.

</TopBlock>
42 changes: 19 additions & 23 deletions content/700-optimize/300-recording.mdx
Original file line number Diff line number Diff line change
@@ -1,53 +1,49 @@
---
title: 'Recording'
metaTitle: 'Optimize: Recording'
metaDescription: "Learn about everything you need to know to use Optimize's recording."
metaDescription: "Learn about using Optimize's recording feature."
tocDepth: 3
toc: true
---

<TopBlock>

The Recordings feature is designed for developers to debug and isolate different sets of queries into distinct sessions, known as recordings. This allows for targeted performance analysis and optimization, ensuring that queries from different applications or testing rounds do not get mixed, leading to clearer insights and more effective debugging.
The Recordings feature is designed to help developers debug and isolate different sets of queries into distinct sessions, known as recordings. This targeted approach enables precise performance analysis and optimization by preventing the mixing of queries from different applications or test rounds, leading to clearer insights and more effective debugging.

</TopBlock>

## Managing a recording session

You can manually start and stop recording sessions via the [Optimize dashboard](https://optimize.prisma.io), by clicking the **Start recording** and **Stop recording** buttons present in the dashboard.
You can manually start and stop recording sessions via the [Optimize dashboard](https://optimize.prisma.io) by clicking the **Start Recording** and **Stop Recording** buttons.

:::warning

A recording will automatically stop when 10k query limit is reached or if the prisma schema of the app is changed.
A recording will automatically stop if the 10k query limit is reached or if the Prisma schema of the app is changed.

:::

A recording session can be deleted when no longer needed.

## Identification of a recording session
## Identifying a recording session

You can rename and tag your recording session for easy identification and context. You can do this by clicking on the generated default name of the recording session, and then typing the desired name for your recording session.
You can rename and tag your recording sessions for easy identification and context. Click on the generated default name of the recording session and type the desired name.

## Data captured from a recording session
## Data captured in a recording session

Each recording session captures insights about queries executed in your app, they include:
- All executed queries during a recording session.
- **Raw Query**: the raw query that is generated and sent to the database by Prisma ORM.
- **Count**: Number of times the query was executed.
- Performance metrics
- **`AVG`**: The average query latency.
- **`p50`**: The 50th percentile of the query latency.
- **`P99`**: The 99th percentile of the query latency.
- **`MAX`**: The maximum query latency.
- Errors encountered during query execution
Each recording session captures insights about queries executed in your app, including:
- All executed queries during the session.
- **Raw Query**: The raw query generated and sent to the database by Prisma ORM.
- **Count**: The number of times a query pattern was executed.
- [Query performance metrics](/optimize/performance-metrics).
- Errors encountered during query execution.

Each recording can have a maximum of 10K queries, however, there are no limits on storage retention period.
Each recording can have a maximum of 10k queries. There are no limits on the storage retention period.

## Recommendations generated from a recording session
## Recommendations from a recording session

When a recording session ends, Optimize also recommendations such as:
- [Queries on unindexed columns](/optimize/recommendations#queries-on-unindexed-columns)
- [Excessive number of rows returned](/optimize/recommendations#excessive-number-of-rows-returned)
- [Full table scans caused by LIKE operations](/optimize/recommendations#full-table-scans-caused-by-like-operations)
When a recording session ends, Optimize generates recommendations such as:
- [Excessive number of rows returned](/optimize/recommendations#excessive-number-of-rows-returned)
- [Full table scans caused by LIKE operations](/optimize/recommendations#full-table-scans-caused-by-like-operations)
- [Queries on unindexed columns](/optimize/recommendations#queries-on-unindexed-columns)

Learn more about the recommendations generated by Optimize [here](/optimize/recommendations).
46 changes: 44 additions & 2 deletions content/700-optimize/400-recommendations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Optimize provides recommendations focused on performance improvements such as in
</TopBlock>

## Excessive number of rows returned

The following query targeting a `User` model do not provide a [`take` option](/orm/reference/prisma-client-reference#findmany).

```ts
Expand Down Expand Up @@ -103,7 +104,7 @@ To avoid these issues, we recommend creating an index on the columns that are fr

Consider a `user` model with a `name` field that is frequently used in filters. You can add an index to this column as follows:

```prisma
```prisma file=schema.prisma
model User {
id Int @id @default(autoincrement())
name String
Expand All @@ -114,4 +115,45 @@ model User {

The best way to define indexes for your schema depends factors such as the type of the column, and what database you are using. Learn more about indexes in Prisma: [Indexes Documentation](/orm/prisma-schema/data-model/indexes)

## Full table scans caused by LIKE operations
## Full table scans caused by LIKE operations

The following query targeting the user model provides `contains` and `endsWith` as options, which translate to `LIKE` and `ILIKE` SQL operators.

```jsx
user.findMany({ where: { email: { contains: "gmail.com" }, name: { endsWith: "Burk" } } })
```

### Why is this a problem?

`LIKE` and `ILIKE` operators in SQL can lead to full table scans, potentially impacting performance, especially with larger datasets:

#### UX

- **Slower load times**: Full table scans can significantly increase the time it takes to retrieve data, leading to longer wait times for users.

#### Resource utilization

- **Increased resource usage**: Full table scans increase CPU, memory usage, and disk I/O, straining system resources for your database.
- **Increased costs**: In serverless database pricing plans, more intensive resource usage can translate into higher costs.

### Recommendation

To mitigate potential performance issues, consider extracting a separate indexed String field for the substring being filtered on, or a `Boolean` field indicating the presence of a given substring. These approaches are particularly useful if you have a limited, known set of substrings.

For example, if you frequently filter on the file extension of a `filePath` field, you can create an indexed column for the file extension:

```prisma file=schema.prisma
model File {
id Int @id @default(autoincrement())
filePath String
fileExtension String
@@index([fileExtension])
}
```
<br />
:::note

This solution has trade-offs, such as increased storage requirements and potential impacts on write performance due to the additional index. Consider whether this approach is beneficial for your usecase.

:::
15 changes: 0 additions & 15 deletions content/700-optimize/500-faq.mdx

This file was deleted.

33 changes: 33 additions & 0 deletions content/700-optimize/500-performance-metrics.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: 'Performance metrics'
metaTitle: 'Optimize: Query performance metrics'
metaDescription: "Learn about the query performance metrics provided by Optimize."
tocDepth: 3
toc: true
---

<TopBlock>

An Optimize recording session provides you with the query latencies of the executed queries recorded during the session, including average duration, 50th percentile, 99th percentile, and maximal query execution time.

</TopBlock>

## Total query durations

Prisma Optimize provides the total latency for a query pattern so that you can analyze and debug slow queries.

### Average query duration (**`AVG`**)

The average query duration helps you understand the general performance of your queries by providing the mean execution time. This metric is useful for identifying overall trends and spotting inefficiencies that affect the typical user experience.

### 50th percentile (**`P50`**)

The 50th percentile (median) query duration indicates the time it takes for half of the queries to complete. This metric is useful for understanding the typical performance experienced by users, as it is not skewed by outliers.

### 99th percentile (**`P99`**)

The 99th percentile query duration shows the execution time for the slowest 1% of queries. This metric is critical for identifying and addressing performance bottlenecks that affect a small but significant portion of users, ensuring that the worst-case scenarios are optimized.

### Maximal query duration (**`MAX`**)

The maximal query duration provides the execution time of the single slowest query. This metric is useful for pinpointing extreme cases and understanding the worst performance your system can exhibit, helping you to diagnose and fix potential outliers.
15 changes: 15 additions & 0 deletions content/700-optimize/600-faq.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "FAQ"
metaTitle: "Prisma Optimize: FAQ"
metaDescription: "Frequently asked questions about Prisma Optimize."
tocDepth: 3
toc: true
---

## Does Optimize automatically implement optimizations?

Prisma Optimize provides insights and recommendations on how to improve your database queries. It does not alter any existing queries or your Prisma schema.

## How long is a recording session retained in Optimize?

There are no limits on the storage retention period. Optimize will store a recording session until you explicitly delete it.
13 changes: 0 additions & 13 deletions content/700-optimize/600-known-limitations.mdx

This file was deleted.

13 changes: 13 additions & 0 deletions content/700-optimize/700-known-limitations.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: 'Known Limitations'
metaTitle: 'Optimize: Known Limitations'
metaDescription: 'Learn about known limitations of Optimize.'
tocDepth: 3
toc: true
---

Below are the known limitations when using Prisma Optimize. If you are aware of any limitations that are missing, please let us know on the `#help-and-questions` channel in our community [Discord](https://pris.ly/discord).

## Query limit on a recording session

Each [recording session](/optimize/recording) can contain a maximum of 10k queries. Once this limit is reached, the recording session will end.

0 comments on commit 0408abe

Please sign in to comment.