Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optimize recommendaion, avoid char #6531

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions content/700-optimize/300-recordings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ When a recording session ends, Optimize generates recommendations such as:
- [Repeated query](/optimize/recommendations/repeated-query)
- [Overfetching](/optimize/recommendations/select-returning)
- [Using `@db.Money`](/optimize/recommendations/avoid-db-money)
- [Using `@db.Char(n)`](/optimize/recommendations/avoid-char)

:::info
Use [Prisma AI](/optimize/prisma-ai) to ask follow-up questions about a recommendation.
Expand Down
23 changes: 23 additions & 0 deletions content/700-optimize/400-recommendations/700-avoid-char.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: 'Using @db.Char(n)'
metaTitle: 'Optimize Recommendations: Avoid usage of `@db.Char(x)`'
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
metaDescription: "Learn about the recommendation provided by Optimize for using `@db.Char(x)` native type."
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
tocDepth: 3
toc: true
jharrell marked this conversation as resolved.
Show resolved Hide resolved
---

Optimize provides recommendations to help you identify and resolve performance issues caused by the use of `@db.Char(n)` type in PostgreSQL.

The `@db.Char(n)` native type has been used within the `Item` model on the name field:
jharrell marked this conversation as resolved.
Show resolved Hide resolved

```prisma
model Item {
// ...
name String @db.Char(1)
// ...
}
```

### Why this is a problem

The `@db.Char(n)` type enforces a fixed length of `n`, which can cause unexpected issues in production if not properly managed by the application. In PostgreSQL, `char(n)` pads shorter values with spaces, leading to problems during comparisons and other operations. Unlike some databases that optimize `char(n)`, PostgreSQL does not offer such optimizations, making careful handling essential.
Loading