Skip to content

Commit

Permalink
feat: add optimize recommendaion, avoid char (#6531)
Browse files Browse the repository at this point in the history
* feat: add optimize recommendaion, avoid char

* chore: add n

* Update content/700-optimize/400-recommendations/700-avoid-char.mdx

* Update content/700-optimize/400-recommendations/700-avoid-char.mdx

* Apply suggestions from code review

---------

Co-authored-by: Jon Harrell <4829245+jharrell@users.noreply.github.com>
  • Loading branch information
ankur-arch and jharrell authored Jan 2, 2025
1 parent cf2f44e commit 38b134e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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)
- [Using `@db.VarChar(n)`](/optimize/recommendations/avoid-varchar)
- [Using `timestamp(0)` or `timestamptz(0)`](/optimize/recommendations/avoid-timestamp-timestampz-0)

Expand Down
21 changes: 21 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,21 @@
---
title: 'Using @db.Char(n)'
metaTitle: 'Optimize Recommendations: Avoid usage of `@db.Char(n)`'
metaDescription: "Learn about the recommendation provided by Optimize for using `@db.Char(n)` native type."
---

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

In the following example, the `@db.Char(n)` native type has been used within the `Item` model on the `name` field:

```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.

0 comments on commit 38b134e

Please sign in to comment.